-
Notifications
You must be signed in to change notification settings - Fork 3k
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 aliases for commonly used commands #8130
Comments
Sounds reasonable. I’d suggest not listing the alias in help to avoid clutter, but having the alias itself is fine. |
How do we add an alias to a command? I am not sure about it. |
IMHO it's as trivial as diff --git a/src/pip/_internal/commands/__init__.py b/src/pip/_internal/commands/__init__.py
index 6825fa6e..defcf967 100644
--- a/src/pip/_internal/commands/__init__.py
+++ b/src/pip/_internal/commands/__init__.py
@@ -44,6 +44,10 @@ commands_dict = OrderedDict([
'pip._internal.commands.uninstall', 'UninstallCommand',
'Uninstall packages.',
)),
+ ('remove', CommandInfo(
+ 'pip._internal.commands.uninstall', 'UninstallCommand',
+ 'Uninstall packages.',
+ )),
('freeze', CommandInfo(
'pip._internal.commands.freeze', 'FreezeCommand',
'Output installed packages in requirements format.', I'm trying to work on this because I thought it's easy but had to come here to ask about testing strategy 😄 |
Thanks, @McSinyx! Please go ahead, no issue :) As for testing, the approach I can think of is to parametrize the tests which involve |
That's brilliant (kudos to |
This might cause
I was thinking along the lines of implementing |
@deveshks, thank you for the heads up, that looks like a much better idea. |
Personally I on board with the alias command or some similar settings. (like what git has) |
I think if we're adding aliases, we definitely want them to be visible to the user via help. That said, we should avoid any amount of clutter that we can. So, I agree that just adding "remove" with the same I'd say, we should aim to have a uniform and proper way to provide aliases to users, allowing for multiple aliases for multiple commands, such that it's not difficult to add another alias for a command (similar to how adding a command is a matter of manipulating a single list). Of course, this means we'd have to get a bit more fancy with how our command parser works, figure out how help should know about the command names and all that... but I much prefer that to something more "bolted on" / invisible to the users. I'd imagine aliases could look like this:
Or... we could do what
Even though I'm using them in the example above... I'm a -1 on adding a "remove" alias for uninstall, without a counterpart "add" alias for install and... I'm a -0 on adding them both together. I don't know how useful this, on it's own, would be to the general audience of pip users. I'm personally a lot more interested in adding shorthands for "most common commands", like I hinted at in the example above, which would be similar to All that said, there's also the risk of "too many ways to do the same thing", which... is really the last thing I'd want to start messing about with pip's CLI today. I think we should wait until we move away from optparse to something else (see #4659), where it's easier to do these things properly without adding significantly more technical debt / complexity to the fairly complex/fragile CLI setup we have today. |
Doubling the number of tests (which doubles test execution times) is not a good idea. I'd much rather have a unit test that mocks out the actual implementation of the commands, and checks that various aliases hit the same That's 1 extra unit test to run after adding an alias, which is significantly better than running 30+ tests w/ subprocesses and virtual environments being created for isolating them. |
I'm also somewhat concerned about the precedent this sets. I'm sure there are plenty of other places where pip's commands don't quite match those of other package managers. Should we add aliases for all of those? Why aren't other package managers adding aliases to match pip's commands? A user-defined alias mechanism like git has might be useful, but explicitly adding code to pip for each alias that someone feels would be useful isn't scalable (or IMO advisable). |
Thank you @pradyunsg and @pfmoore for your thoughtful comments. Given no(t yet any) consensus on the execution, I'll mark my PR as draft until I figured out a clean way to resolve your requests al(most)together, to avoid discussion without concrete code for reference. Edit: to add to the concerns above, personally I'm neither certain about the representation of subcommand docs, e.g. for uninstall should the usage section be docs mockups
or
or
Neither looks visually pleasing to me personally. |
|
@pradyunsg, could you please see if the behavior in GH-8137 fits your vision. I'd be happy with your new suggestion though, just wanna make sure you've seen it. |
Thank you all for your comments and especially @McSinyx for the PR. I like the proposed behavior and it would make my life (and probably others' too) a bit easier by not having to spend brain cycles to figure out whether you need to type |
I just searched for this issue after using remove and add for the umpteenth time :) I'd like to propose making the following changes
Any other commands that people mis-remember and use? |
The search/find which is undergo a UX refactor which group everything together (I think @pradyunsg may explain this better to you, he's been planning it for a while now), but the other two are included in my linked PR (GH-8137). |
OK, I'm on board for adding If someone wants to file a PR implementing this (based of off #8137, ideally), please feel welcome to. That isn't to say the PR would be guaranteed to merge; but it would help move us forward on this front! ^.^ |
in response there is: #12828 (comment) (design) I agree with the confusion about which commands are used by newer developers, but if we take this literally, no functionality would be released as one version would have access to the functionality and another would not. but your comment is really useful and makes me think about the consequences of such a direct and visible implementation (being displayed with the --help command), taking this into account I thought we could implement this subtly in a gradual way and using just simple aliases ( i,u,ls) we would basically implement the aliases without displaying it in --help and after 4/5 years when most developers already have the version with support for aliases then yes we could display this |
following the discussion, I think the most sensible way to go about this issue would be to implement a "remove" command... only to raise a useful error message that the remove command does not exist
I think the issue is very specific to the uninstall command because it's only used once in a while. I myself can never remember if it's pip remove or pip delete, I try both and it's neither :D pip install does not need any assistance IMO |
What's the problem this feature will solve?
As a software developer and package maintainer, I often install and remove software packages with different package managers. With pip I often run into this error:
Describe the solution you'd like
Have a
remove
command that does exactly the same asuninstall
.Alternative Solutions
pip
in general but not forpip remove
.)Additional context
Package managers which use remove and don't know uninstall:
Package managers which have both:
The text was updated successfully, but these errors were encountered: