pip
pip copied to clipboard
`pip config` should support `add` and `remove` commands
What's the problem this feature will solve?
I use the pip config command quite a lot, but it does not allow me to add multiple entries to trusted-hosts or to remove a value from the config. This would greatly improve usability for me.
Describe the solution you'd like
Being able to add a value to trusted hosts or index-url with:
pip config add global.trusted-host artifactory.mycompany.com
pip config remove global.trusted-host artifactory.mycompany.com
Alternative Solutions
Currently I just use preexisting configs and keep swapping them out. However, this is an interim solution that is really not helping. Our company has a tight lockdown on the network, and when we switch to external networks, we need to remove the index-urls and add external ones to trusted hosts. We would rather not directly download from pypi or files.pythonhosted.org on company VPN.
Additionally, this is very different from pip config set which sets and unsets absolute values. In this scenario, I could engineer a mix of values from separate configs. This would allow me to swap out registries and add them back without macguyvering solutions like I do today.
Additional context
This is why I had originally created the following issues: #7803 and #7804
@stonecharioteer Could you fill the issue template, and, potentially clarify how this would differ from pip config set?
Apologies, I hit the enter key way too soon.
Updated
If I understand the use-case correctly, You want to be able to set multiple values in pip config for a key, or add to existing values.
With set, you can only provide one value, and that either creates a new value, or replaces the existing one, as seen below.
$ pip config set global.trusted-host artifactory1.mycompany1.com
Writing to /Users/devesh/.config/pip/pip.conf
$ cat /Users/devesh/.config/pip/pip.conf
[global]
trusted-host = artifactory1.mycompany1.com
$ pip config set global.trusted-host artifactory2.mycompany2.com
Writing to /Users/devesh/.config/pip/pip.conf
$ cat /Users/devesh/.config/pip/pip.conf
[global]
trusted-host = artifactory2.mycompany2.com
So in your case, doing pip config add global.trusted-host artifactory1.mycompany1.com and pip config add global.trusted-host artifactory2.mycompany1.com will give you.
$ cat /Users/devesh/.config/pip/pip.conf
[global]
trusted-host = artifactory1.mycompany1.com
artifactory2.mycompany2.com
And with unset, we get rid of the all option presents.
$ pip config get global.trusted-host
artifactory1.mycompany1.com
artifactory2.mycompany2.com
(venv) DeveshSinghMac:~ devesh$ cat /Users/devesh/.config/pip/pip.conf
[global]
trusted-host = artifactory1.mycompany1.com
artifactory2.mycompany2.com
(venv) DeveshSinghMac:~ devesh$ pip config unset global.trusted-host
Writing to /Users/devesh/.config/pip/pip.conf
(venv) DeveshSinghMac:~ devesh$ cat /Users/devesh/.config/pip/pip.conf
(venv) DeveshSinghMac:~ devesh$
But in your case, pip config remove global.trusted-host artifactory1.mycompany1.com and pip config remove global.trusted-host artifactory2.mycompany1.com will get rid of options one by one if present (perhaps if there is only one remaining, we should get rid of [global] section itself)
(perhaps if there is only one remaining, we should get rid of
[global]section itself)
An empty section won't affect what the parsed contents are, so that's more "polish" than "correctness". :)
@deveshks you summarized my thoughts to the point! A command like that would be super useful in a corporate world. @pradyunsg knows where I am coming from :D
@deveshks you summarized my thoughts to the point!
No worries, happy to help
A command like that would be super useful in a corporate world. @pradyunsg knows where I am coming from :D
I am not sure how useful will this option be for the general public. If the pip maintainers are okay with including such a feature, me or you can take a stab at this.
@deveshks I'll give this a go. I would like to expand about this. Regarding the order of the inputs, I would like to preserve the order users put these in. This will definitely help a lot of organizations behind proxies. They don't know that it is possible to add multiple sources, but this will help them understand, I can also go ahead and edit the docs once I am done. I'll raise a PR soon.
@pradyunsg I'll name the commands pip config add and pip config rm. I originally assumed npm had an add command under the config subcommand, but it does not. git has something similar, git config --add is a thing, but there is no git config --rm command.
I will go ahead and send you a PR, we can discuss the nomenclature there, if that is alright. I know pip has an edit command, but that does not solve everything, especially where automation is concerned.
BUMP. My company would also greatly benefit from this feature.
BUMP. My company would also greatly benefit from this feature.
Re your bump: @aamailhot
As a person interested in funding open source (I am not pip maintainer). Since your company would "greatly benefit" I wonder how much your company would like to pay the maintainers for their voluntary work ?
I am currently discussing in the open-source communities ways of funding the OSS efffort and I am interested in hearing what is possible.
Did you consider for example Github Sponsorship? Would that be an option for your company? How much of a regular sponsorship wouldl you see as worth the "great benefit" ?
My mistake, i misunderstood how pip is maintianed. Thanks for the information i will take this back to my company and weigh our options.
Life came in the way and I forgot about this issue. I've since left the company where I could have used this. However, I still think this is a feature that could be useful for pip to support. @pradyunsg do you think I should take a crack at this? Or do you think someone else would benefit from doing this, since this feels like a good first issue?
Please do go ahead and have a crack! We have more easy issues people can choose from instead. One thing to note though is there’s recent effort to allow configs in TOML (https://github.com/pypa/pip/issues/3809#issuecomment-1070666862) and these may need to be coordinated. cc @Shivansh-007
I stumbled upon this issue from google so hopefully this will be helpful for someone else.
I'm not sure if this works in all situations but I was able to replicate an add command for global.extra-index-url taking advantage of subshells:
pip config set global.extra-index-url "$(pip config get global.extra-index-url) https://new-url.com/pip"