-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add --install-options and --global-options to the requirements file parser. #2537
Conversation
67fca3f
to
718f12b
Compare
Build failures look mostly like compatibility issues python 2 vs python 3 (or 2.6 vs 2.7). I'll try to get a chance to do a more complete review in the next couple of days. |
Yes, thanks @gvalkov! Not sure if this is Python version specific or just intermittent depending on dict ordering or something; leaning towards latter. Has merge conflicts now too unfortunately, because of lots of activity. |
898a34e
to
7fef584
Compare
Thanks everyone - I'm just happy to contribute to pip. The PR has been rebased and force pushed. However, the |
@@ -48,7 +48,7 @@ class InstallRequirement(object): | |||
|
|||
def __init__(self, req, comes_from, source_dir=None, editable=False, | |||
link=None, as_egg=False, update=True, editable_options=None, | |||
pycompile=True, markers=None, isolated=False): | |||
pycompile=True, markers=None, isolated=False, options=None): |
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.
just set options={}
here and no if/else below
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.
Done. I simply wanted to avoid the discussion about mutable default arguments.
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.
ah... I see. yea, I honestly wasn't thinking about that. ok in this case, but I'm happy either way. I'd almost expect pylint/pep8 to have added a check for mutable kwargs?
my requirements.txt
the resulting command
|
if flags: | ||
long_opts += [i.lstrip('-') for i in flags] | ||
|
||
opts, _ = getopt.getopt(shlex.split(req_line), '', long_opts) |
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.
why not build a mini pip parser?
reuse cmdoptions.install_options
and cmdoptions.global_options
Thank you for the first wave of reviews - I've addressed some of the issues and am looking into the rest. The branch has also been rebased on top of the latest (slightly conflicting) develop. |
Sigh - It was this trailing comma: elif linetype == REQUIREMENT_EDITABLE:
comes_from = '-r %s (line %s)' % (filename, line_number)
isolated = options.isolated_mode if options else False,
default_vcs = options.default_vcs if options else None, False, == (False,)
bool((False,)) is True If |
Hello, @pfmoore, I added the functional test that you requested. At this point all tests pass, with the exception of the flake8 line-length ones. I'm going to make a small stand for 100 char lines. Imho, they improve readability in pip's case. Let me know if you're willing to consider such a change. Also, let me know if you would like to have all commits squashed if you consider this ready for merging. Thanks, |
Regarding the 100-character lines, we have a project policy of following PEP 8, so these would need to be fixed. Otherwise, I'll take a look, probably tomorrow. No problem from me with not squashing the commits. |
This looks OK to me, and I'm happy to merge it. Before I do - @qwcode you mentioned the parsing code in a comment ("why not build a mini pip parser?"). I don't know if you have any concerns in this area - we're adding a big chunk of parsing code here, but I don't really see any real problem with the code here, at the end of the day we need to parse the new syntax. Can you give a +1 if you're OK for this to go, and I'll merge. @gvalkov thanks for all your work on this, it'll be a nice improvement for pip. |
opts, _ = _req_parser.parse_args(args) | ||
|
||
if opts.install_options: | ||
opts.install_options = flat_shlex_split(opts.install_options) |
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 don't see that the extra flatten step is needed.
if args is --global-option='--author' --global-option='--author-email'
, then opts.global_options is ['--author', '--author-email']
.
you'd only need to flatten if people were misusing "--global-option" and adding multiple options into it?
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.
Agreed - supplying --global-option='--author --author-email'
should be an error rather than passing 2 arguments. At least that's how I believe the command line --global-option
works (the docs aren't that clear) and it's what I think makes sense.
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.
Alright - the shlex.split()
and flatten step has been removed. I think the old behavior had a nice DWIM thing going for it, though.
Should --global-option='--author --author-email'
really be handled by pip? The way I see it, the value of a single --global|install-option
should by definition be passes as a single argument to setup.py
.
…onfidence with unit tests that confirm what args are passed
… finder, joining lines,
Add --install-options and --global-options to the requirements file parser.
Looks good - thanks for the contribution! |
… pip yet We have to wait for a new version of PIP: pypa/pip#2537
Hello,
This PR implements the functionality requested in #271 and #571. It is a rebase and cleanup of my previous attempt at implementing this - #790.
Notes:
Comments are welcome.