dephell deps convert¶
Convert dependencies between formats. Dephell will automagically lock them if needed and resolve all conflicts.
Dephell uses four pieces of information for conversion:
--from-format
: The format to convert from (e.g.poetry
)--from-path
: The path to the file to read from (e.g.pyproject.toml
)--to-format
: The format to convert to (e.g.setuppy
)--to-path
: The path to the file where the result should be put (e.g.setup.py
). You can provide the special case ‘stdout’ to this option to output to the screen instead of a file.
Dephell can try to guess the formats or paths you want to use given the other piece of information, giving you three different ways to specify what you want:
- Explicitly specify path and format:
--from-format=poetry --from-path=pyproject.toml
and--to-format=setuppy --to-path=setup.py
. - Specify only path:
--from=pyproject.toml
and--to=setup.py
. - Specify only format:
--from=poetry
and--to=setuppy
.
Supported formats¶
- Archives:
- *.egg-info (
egginfo
) - *.tar.gz (
sdist
) - *.whl (
wheel
)
- *.egg-info (
- pip:
- requirements.txt (
pip
) - requirements.lock (
piplock
)
- requirements.txt (
- pipenv:
- Pipfile (
pipfile
) - Pipfile.lock (
pipfilelock
)
- Pipfile (
- poetry:
- pyproject.toml (
poetry
) - poetry.lock (
poetrylock
)
- pyproject.toml (
- Environment:
- Imports in the package (
imports
). Pass path to package or module and dephell will automatically detect required packages. - Installed packages (
installed
). It works like pip freeze. Dephell can only read from this format, of course. If you want to install packages, use install command.
- Imports in the package (
- Other:
- setup.py (
setuppy
) - flit (
flit
) - conda’s environment.yml (
conda
) - pyproject.toml build-system requires (
pyproject
)
- setup.py (
Examples¶
Lock dependencies for Pipfile:
$ dephell deps convert --from=Pipfile --to=Pipfile.lock
Or the same, but more explicit:
$ dephell deps convert \
--from-format=pipfile --from-path=Pipfile \
--to-format=pipfilelock --to-path=Pipfile.lock
Best practice is specify your dependencies file in pyproject.toml
DepHell config:
[tool.dephell.main]
from = {format = "pipfile", path = "Pipfile"}
to = {format = "pipfilelock", path = "Pipfile.lock"}
And after that DepHell will automatically detect your dependencies file:
$ dephell deps convert
You can still override this config for one-off actions:
$ dephell deps convert --to requirements.txt
See configuration documentation for more details.
More examples¶
You can convert anything to anything:
- Lock requirements.txt:
dephell deps convert --from=requirements.in --to=requirements.txt
- Lock Pipfile:
dephell deps convert --from=Pipfile --to=Pipfile.lock
- Lock poetry:
dephell deps convert --from=pyproject.toml --to=poetry.lock
- Migrate from setup.py to poetry:
dephell deps convert --from=setup.py --to=pyproject.toml
- Migrate from pipenv to poetry:
dephell deps convert --from=Pipfile --to=pyproject.toml
- Generate setup.py for poetry (to make project backward compatible with setuptools):
dephell deps convert --from=pyproject.toml --to=setup.py
- Generate requirements.txt from Pipfile to work on a pipenv-based project without pipenv:
dephell deps convert --from=Pipfile --to=requirements.txt
- Generate requirements.txt from poetry to work on a poetry-based project without poetry:
dephell deps convert --from=pyproject.toml --to=requirements.txt
- Pipe poetry requirements into pip for installation in a custom environment:
pip install -r <(dephell deps convert --to-path stdout --to-format pip)
Filter dependencies¶
You can filter dependencies by envs with --envs
flag. All dependencies included in main
or dev
env. Also, some dependencies can be included in extras. There is an example of poetry config with envs in comments:
[tool.poetry.dependencies]
python = ">=3.5"
aiohttp = "*" # main, asyncio
textdistance = "*" # main
[tool.poetry.dev-dependencies]
pytest = "*" # dev, tests
sphinx = "*" # dev
[tool.poetry.extras]
asyncio = ["aiohttp"]
tests = ["pytest"]
Examples, how to filter these deps:
$ dephell deps convert --envs main
# aiohttp, textdistance
$ dephell deps convert --envs asyncio
# aiohttp
$ dephell deps convert --envs main tests
# aiohttp, textdistance, pytest
See also¶
- dephell project build to fast convert dependencies into setup.py, sdist and wheel.
- dephell deps install to install project dependencies.
- dephell deps tree to show dependencies tree for project.