-
Notifications
You must be signed in to change notification settings - Fork 104
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
Proposed fix for #474: enables parsing of requirements.txt during locking #476
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for conda-lock ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
from conda_lock.src_parser.pyproject_toml import unpack_git_url | ||
|
||
|
||
def parse_requirements_txt(file_path, category=None) -> Dependency: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the return type annotation, this seems to be Dependency
generator rather than returning a Dependency
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really promising!!! Apologies for taking so long to provide feedback.
I'd recommend putting tests into tests/test_conda_lock.py
.
I'm a bit uncomfortable tapping into pip._internal
since that may be an unstable API. (Perhaps it's worth considering if it's feasible to vendor pip._internal.req.req_file
.)
But overall I think this is a major step in the right direction and a very important feature. Thanks so much for the submission!
requirements.write("\n") # Trailing newline | ||
requirements.file.close() | ||
|
||
dependencies.extend(parse_requirements_txt(requirements.name, category)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering what will happen now with editable requirements.
Description
This addresses #474, which fails to lock if environment.yml has -rrequirements.txt in the pip requirements. The main problem with the existing implementation is that it treats requirements lists as if they were a tool.poetry.dependencies block in a pyproject.toml. Poetry is great, and I see why you would want to vendor such a clean implementation, but poetry doesn't have any specification for external files. Further, any differences between calling
pip install
andpoetry lock
would eventually cause an issue.My fix mimics conda's implementation which writes a temporary requirements.txt and invokes the command-line pip install command. https://github.com/conda/conda/blob/main/conda_env/installers/pip.py. Ideally this means there will be fewer bugs/differences between performing
conda env create
andconda lock
.Since pip doesn't provide an explicit library or API for parsing I do it by invoking pip's own parse_requirements function. I also based the return values strongly on the pyproject_toml.py implementation.
Testing and Feedback
I would love if somebody could suggest the right place to put unit tests.