-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recursive optional dependencies lead to incorrect requirements files #78
Comments
At first glance, adding |
This is an interesting one. I didn't know about recursive optional dependencies.
So in a perfect world for your example, the I can try to add some logic here that detects recursive optional dependencies, gathers all of the ultimate dependencies, and injects them into pip-compile - but IMO an ideal fix would be upstream on the |
Yes this is an oversight pypa/hatch#1347 |
Some further information, this workaround unfortunately doesn't work correctly with I think this is what you're talking about in #78 (comment)? |
This example helped to clarify this issue for me since
[project]
name = "mypkg1234"
version = "1.0.0"
[project.optional-dependencies]
api = [
"fastapi"
]
uvicorn = [
"mypkg1234[api]",
"uvicorn",
]
[tool.hatch.envs.uvicorn]
features = [ "uvicorn" ]
# type = "pip-compile" Inside of the environment plugin, the I can try to see how I would handle this in In the meantime, until this is resolved if you'd like to use [project]
name = "mypkg"
version = "1.0.0"
[project.optional-dependencies]
api = [
"fastapi"
]
uvicorn = [
"fastapi",
"uvicorn",
]
[tool.hatch.envs.uvicorn]
features = [ "uvicorn" ]
type = "pip-compile" |
Thanks for looking into this and all the examples and explanation! For the moment we can just workaround by not using recursive dependencies for the particular environment that uses |
Will be resolved upstream by pypa/hatch#1387 |
Can you please confirm that this works on the master branch of Hatch? |
Yep, confirmed working. Really nice work @ofek 🙇 pyproject.toml
[project]
name = "mypkg1234"
version = "1.0.0"
[project.optional-dependencies]
api = [
"fastapi"
]
uvicorn = [
"mypkg1234[api]",
"uvicorn",
]
[tool.hatch.envs.uvicorn]
features = [ "uvicorn" ]
type = "pip-compile" requirements/requirements-uvicorn.txt
|
Awesome, thank you! Just FYI while I have you here, the next release will begin shipping UV directly as a dependency. |
I saw |
A not entirely documented (pypa/pip#11296) but extremely useful feature of
pip
since version 21.2 is thatoptional-dependencies
groups can depend on each other: https://hynek.me/articles/python-recursive-optional-dependencies/For example if your package is
mypkg
and it has an optional REST API which you could run withuvicorn
or some other server, which you run from theuvicorn
environment in hatch, and for which you'd like to lock dependencies, you could do this:Unfortunately this doesn't really work with
pip-compile
orhatch-pip-compile
, because you will end up with this inrequirements/requirements-uvicorn.txt
:Oh noes! It went off to PyPI and found that yes, indeed, there is a package there already called
mypkg
and proceeded to add it as a dependency to the requirements file. That's definitely not what you want!Note that if you run
pip-compile --extra uvicorn
in the environment you'll get this instead:Which is not what you want either, but definitely better than pulling in some possibly unrelated or out-of-date package from PyPI. In this case it would be easy to post-process the output of
pip-compile
to remove editable installs of recursive optional dependencies, for instance.Responsibility for fixing this might be partly in
pip-tools
if there isn't a way forhatch-pip-compile
to get it to do the right thing...The text was updated successfully, but these errors were encountered: