Comments (11)
Yes this is an oversight pypa/hatch#1347
from hatch-pip-compile.
Can you please confirm that this works on the master branch of Hatch?
from hatch-pip-compile.
Awesome, thank you! Just FYI while I have you here, the next release will begin shipping UV directly as a dependency.
from hatch-pip-compile.
At first glance, adding --unsafe-package mypkg --no-allow-unsafe
to the pip-compile
arguments will do the right thing, based on jazzband/pip-tools#2002 (comment)
from hatch-pip-compile.
This is an interesting one. I didn't know about recursive optional dependencies.
hatch-pip-compile
is an EnvironmentPlugin - so at "pip-compile time" it references an environment property, dependencies, and sends that over to pip-compile
as a temporary requirements.in
file.
So in a perfect world for your example, the dependencies
property should return ['fastapi', 'uvicorn']
- but instead it's returning ['mypkg[api]', 'uvicorn']
.
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 dependencies
/ dependencies_complex
properties. @ofek I'm curious what you're doing to handle this scenario where optional dependency groups refer to other groups. Is it this a reasonable request for hatch to change the behavior of dependencies
/ dependencies_complex
for these cases?
from hatch-pip-compile.
At first glance, adding
--unsafe-package mypkg --no-allow-unsafe
to thepip-compile
arguments will do the right thing, based on jazzband/pip-tools#2002 (comment)
Some further information, this workaround unfortunately doesn't work correctly with hatch-pip-compile
(by adding --unsafe-package
to pip-compile-args
), because (perhaps for the reasons in previous comments) it ends up referring to to the upstream mypkg[api]
rather than the local one. So you still get the wrong transitive dependencies (or lack thereof) even if you don't get the incorrect self-dependency.
I think this is what you're talking about in #78 (comment)?
from hatch-pip-compile.
This example helped to clarify this issue for me since pypackage1234
doesn't exist on PyPI. This works when it uses the default virtualenv
environment type by hatch, but breaks on hatch env create uvicorn
when you un-comment the last line and use the pip-compile
environment type from hatch-pip-compile:
pip._internal.exceptions.DistributionNotFound: No matching distribution found for mypkg1234[api]
[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 dependencies
property returns ['mypkg[api]', 'uvicorn']
, although I believe that ['fastapi', 'uvicorn']
would be more intuitive - since that's the actual intention behind the recursive optional dependencies.
I can try to see how I would handle this in hatch-pip-compile
- but implementing it upstream would work everywhere and benefit other plugins. If this is something I can figure out I can submit a PR upstream too.
In the meantime, until this is resolved if you'd like to use hatch-pip-compile
the best way might be to stay away from recursive dependencies 😞
[project]
name = "mypkg"
version = "1.0.0"
[project.optional-dependencies]
api = [
"fastapi"
]
uvicorn = [
"fastapi",
"uvicorn",
]
[tool.hatch.envs.uvicorn]
features = [ "uvicorn" ]
type = "pip-compile"
from hatch-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 pip-compile
.
from hatch-pip-compile.
Will be resolved upstream by pypa/hatch#1387
from hatch-pip-compile.
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
#
# This file is autogenerated by hatch-pip-compile with Python 3.12
#
# - fastapi
# - uvicorn
#
annotated-types==0.6.0
# via pydantic
anyio==4.3.0
# via starlette
click==8.1.7
# via uvicorn
fastapi==0.110.2
# via hatch.envs.uvicorn
h11==0.14.0
# via uvicorn
idna==3.7
# via anyio
pydantic==2.7.0
# via fastapi
pydantic-core==2.18.1
# via pydantic
sniffio==1.3.1
# via anyio
starlette==0.37.2
# via fastapi
typing-extensions==4.11.0
# via
# fastapi
# pydantic
# pydantic-core
uvicorn==0.29.0
# via hatch.envs.uvicorn
from hatch-pip-compile.
Awesome, thank you! Just FYI while I have you here, the next release will begin shipping UV directly as a dependency.
I saw uv
fly by while I was installing from master, that is awesome!
from hatch-pip-compile.
Related Issues (20)
- matrix environments with parent environment with different python version raise an error HOT 1
- depend on constraint env lockfile only if dependencies are present HOT 1
- Why is pip-tools being installed into the destination virtualenv? HOT 1
- pip complains about installing with `--no-deps`
- lockfile check not running HOT 8
- exhaustively check `dependencies_in_sync` HOT 1
- Specific Version of `pip-tools`
- Installation instructions not working HOT 13
- Regex error when installing pydantic as dependency HOT 5
- Lockfile Out Of Date between Windows vs. Linux HOT 3
- creating constraint environment without installing dependencies leaves it in bad state HOT 3
- "hatch env remove" leaves partial environment in place HOT 5
- "PIP_COMPILE_DISABLE" does not affect exit code HOT 8
- How can I use this plugin using hatch config `dirs.env.virtual`? HOT 2
- Use `uv` as locker / installer? HOT 1
- uv pip sync support
- singular uv install
- How can one update hatch-pip-compile itself ? HOT 5
- Possible issue on windows with wrong environment content
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hatch-pip-compile.