-
Notifications
You must be signed in to change notification settings - Fork 15
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
Leverage existing requirements.txt parsing logic to close #225 #227
Conversation
d4096c5
to
dad9423
Compare
dad9423
to
3d3ce17
Compare
Hmm. I took a closer look at Still, what I don't like about this integration here is having to write out a temporary file to parse some requirements text, when this text (with the sole exception of parsing However, fixing this requires firrst some moderate refactoring in our Coincidentally, this also frees up our parser to decide for themselves exactly how to read the given file (i.e. they may choose something more appropriate than After this refactoring Then there is the special case of I started looking at this refactoring, and I'd rather you rebuild this PR on top of that, instead of having to write temporary files for every single |
Take a single Path argument instead of separate contents + source. This allows the parser function itself to choose how to open the file and pass it to the underlying parser. This is also necessary for the upcoming rewrite of our requirements.txt parser (#227).
|
#227 (#229) * test_extract_declared_dependencies_succes: Harmless test refactoring Move the dependency_factory() call into the test case instead of in the parametrized test data. Also remove unnecessary "__" prefix from test ids. * extract_declared_dependencies: Refactor API of parser functions Take a single Path argument instead of separate contents + source. This allows the parser function itself to choose how to open the file and pass it to the underlying parser. This is also necessary for the upcoming rewrite of our requirements.txt parser (#227). * test_extract_declared_dependencies_pyproject_toml: Remove unnecessary dedent() * extract_declared_dependencies: Rename parser functions The rename reflects that these now parse file paths, and not extracted file contents. --------- Co-authored-by: Vince Reuter <vince.reuter@gmail.com>
3d3ce17
to
33aa6a1
Compare
33aa6a1
to
014533a
Compare
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.
Looks great! Two things missing:
- An added test (demonstrating Line continuations aren't fully supported for per-requirement options in requirements.txt #225) that is fixed by this PR.
- A comment/consideration on how to possibly make the
setup.cfg
situation better.
For the second one, I've been looking at pip-requirements-parser to see if there is anything in there we could benefit from1.
AFAICS, we have to dig all the way in to RequirementsFileParser._parse_file()
before we've actually opened and read the file. so a cleaner implementation of RequirementsFile.from_string()
would have to copy all but the first line of ._parse_file()
...
Footnotes
-
Even if we were to call into its internal functions, this could still be considered acceptable as we can pin our use of pip-requirements-parser (and control when we upgrade it) as opposed to
pip
itself where we are only given whatever is available on the user's machine. ↩
Once aboutcode-org/pip-requirements-parser#17 is merged, we could more directly use
pip-requirements-parser
(namely, theRequirementsParser.from_string
method). Until then, this works around aNameError
that comes up when using the less commonfrom_string
method in theRequirementsFile
class in that project.