Skip to content
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

Merged
merged 25 commits into from Apr 12, 2015

Conversation

gvalkov
Copy link
Contributor

@gvalkov gvalkov commented Mar 14, 2015

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:

  • The requirements file parser was overhauled and is best reviewed as a new file.
  • I'm not flake8 compliant with regard to max line length. Please consider bringing the recommended maximum up to 100-110.

Comments are welcome.

@pfmoore
Copy link
Member

pfmoore commented Mar 15, 2015

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.

@qwcode
Copy link
Contributor

qwcode commented Mar 16, 2015

I'll try to look too @pfmoore. kudos to @gvalkov for coming back again on this.

@msabramo
Copy link
Contributor

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.

@gvalkov gvalkov force-pushed the reqfileopts branch 2 times, most recently from 898a34e to 7fef584 Compare March 16, 2015 19:18
@gvalkov
Copy link
Contributor Author

gvalkov commented Mar 16, 2015

Thanks everyone - I'm just happy to contribute to pip.

The PR has been rebased and force pushed. However, the req_file.py cleanup from #2497 was incompatible with the new parser and had to be reverted.

@@ -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):
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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?

@qwcode
Copy link
Contributor

qwcode commented Mar 18, 2015

--install-option and --global-option are additive options. that's not working

my requirements.txt

peppercorn --global-option='--author' --global-option='--author-email'

the resulting command

Running command /home/qwcode/.qwdev/pip2/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-hp93Dz/peppercorn/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" --author-email install --record /tmp/pip-Ev5FPG-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/qwcode/.qwdev/pip2/include/site/python2.7

``

if flags:
long_opts += [i.lstrip('-') for i in flags]

opts, _ = getopt.getopt(shlex.split(req_line), '', long_opts)
Copy link
Contributor

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

@gvalkov
Copy link
Contributor Author

gvalkov commented Mar 18, 2015

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.

@gvalkov
Copy link
Contributor Author

gvalkov commented Mar 18, 2015

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 isolated is true, then --no-user-cfg is added to the global options list.

@gvalkov
Copy link
Contributor Author

gvalkov commented Mar 21, 2015

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,
Georgi

@pfmoore
Copy link
Member

pfmoore commented Mar 21, 2015

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.

@pfmoore
Copy link
Member

pfmoore commented Mar 22, 2015

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)
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

@gvalkov
Copy link
Contributor Author

gvalkov commented Apr 12, 2015

Sure, no problem. Merging @qwcode branch would have resulted in some messy history, so I went ahead and rebased with develop and then applied @qwcode's commits on top (sans @qwcode's merge). It looks cleaner when it's linear, imho.

pfmoore added a commit that referenced this pull request Apr 12, 2015
Add --install-options and --global-options to the requirements file parser.
@pfmoore pfmoore merged commit 3b4373c into pypa:develop Apr 12, 2015
@pfmoore
Copy link
Member

pfmoore commented Apr 12, 2015

Looks good - thanks for the contribution!

qwcode added a commit that referenced this pull request Apr 13, 2015
JohannesBertens added a commit to witlox/cumulonimbi that referenced this pull request May 25, 2015
@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants