pip icon indicating copy to clipboard operation
pip copied to clipboard

`pip config` should support `add` and `remove` commands

Open stonecharioteer opened this issue 5 years ago • 14 comments

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 avatar May 18 '20 11:05 stonecharioteer

@stonecharioteer Could you fill the issue template, and, potentially clarify how this would differ from pip config set?

pradyunsg avatar May 18 '20 11:05 pradyunsg

Apologies, I hit the enter key way too soon.

stonecharioteer avatar May 18 '20 11:05 stonecharioteer

Updated

stonecharioteer avatar May 18 '20 11:05 stonecharioteer

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)

deveshks avatar May 19 '20 21:05 deveshks

(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". :)

pradyunsg avatar May 21 '20 23:05 pradyunsg

@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

stonecharioteer avatar May 22 '20 14:05 stonecharioteer

@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 avatar May 22 '20 15:05 deveshks

@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.

stonecharioteer avatar May 25 '20 15:05 stonecharioteer

BUMP. My company would also greatly benefit from this feature.

aamailhot avatar Apr 13 '22 22:04 aamailhot

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" ?

potiuk avatar Apr 13 '22 22:04 potiuk

My mistake, i misunderstood how pip is maintianed. Thanks for the information i will take this back to my company and weigh our options.

aamailhot avatar Apr 13 '22 23:04 aamailhot

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?

stonecharioteer avatar Apr 14 '22 06:04 stonecharioteer

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

uranusjr avatar Apr 14 '22 07:04 uranusjr

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"

mattangus avatar Jun 17 '24 17:06 mattangus