Proposed fix for #474: enables parsing of requirements.txt during locking#476
Proposed fix for #474: enables parsing of requirements.txt during locking#476stefansjs wants to merge 2 commits intoconda:mainfrom
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.
For the return type annotation, this seems to be Dependency generator rather than returning a Dependency.
maresb
left a comment
There was a problem hiding this comment.
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.
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 installandpoetry lockwould 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 createandconda 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.