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

Raise error if --user and --target arguments are used together #7777

Merged
merged 4 commits into from
Feb 27, 2020

Conversation

sinscary
Copy link
Contributor

closes #7249

This PR adds a validation which runs while parsing the command and throws a CommandError if --user and --target args are used together in same command.

@sinscary
Copy link
Contributor Author

@pradyunsg please suggest a good error message. I am really bad with this.

@sinscary sinscary force-pushed the fix_#7249 branch 2 times, most recently from 4ed5019 to b6d775d Compare February 25, 2020 10:49
@sinscary
Copy link
Contributor Author

@pradyunsg can you review the changes?

cmd_args.remove(cmd_name)

return cmd_name, cmd_args
if set(['--user', '--target']).issubset(set(args_else)):
Copy link
Member

@uranusjr uranusjr Feb 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would handle this in InstallCommand instead, since it is the only context where --user and --target are mutually exclusive.

It is much easier to handle it in run() as well; optparse documentation conveniently provides an example; you can simply write something like

def run(self, options, args):
    if options.use_user_site and options.target_dir is not None:
        raise CommandError('--user and --target cannot be used together.')
    # ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uranusjr My bad. I didn't realise --target was being used with install command only. But don't you think error out early would be better than executing all the code to populate the options, import install module etc. and then error it out. I mean we already know these both args are not allowed together.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean we already know these both args are not allowed together.

Indeed, but you’re already missing -t which is an alias of --target. And what happens if we add more aliases to either argument? Populating the whole options is actually a good thing IMO since it provides both consistency and safety.

Copy link
Contributor Author

@sinscary sinscary Feb 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah that makes sense, Looks like I didn't consider all the cases 😞. Well, will make the changes. Thanks for the review 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are on the topic. Can you suggest a better error message to show?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That I have absolutely no suggestions. I think the current message is good enough, but I’m terrible at this 😆

@sinscary
Copy link
Contributor Author

sinscary commented Feb 27, 2020

@uranusjr @pradyunsg Can you review the changes again?

@@ -0,0 +1 @@
Raise error if --user and --target are used together in command
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe specify in pip install?

@uranusjr
Copy link
Member

One nitpicking, otherwise LGTM 👍

@sinscary
Copy link
Contributor Author

@uranusjr done. But Looks like this test test_distutils_config_file_read is failing for python2 for everyone.

@uranusjr uranusjr closed this Feb 27, 2020
@uranusjr uranusjr reopened this Feb 27, 2020
@sinscary
Copy link
Contributor Author

sinscary commented Feb 27, 2020

@uranusjr @pradyunsg meanwhile tests run, just curious to know why does pip have so many checks 😕 ? 45 checks, I mean that's a lot compared to other pypa projects.

@pradyunsg
Copy link
Member

@sinscary https://pip.pypa.io/en/stable/development/ci/

@pradyunsg pradyunsg merged commit 520e76d into pypa:master Feb 27, 2020
@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Apr 2, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 2, 2020
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.

Should we print an error if --user and --target are used together?
4 participants