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

pip config should support add and remove commands #8259

Open
stonecharioteer opened this issue May 18, 2020 · 14 comments
Open

pip config should support add and remove commands #8259

stonecharioteer opened this issue May 18, 2020 · 14 comments
Labels
S: needs triage Issues/PRs that need to be triaged

Comments

@stonecharioteer
Copy link

stonecharioteer commented May 18, 2020

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

@triage-new-issues triage-new-issues bot added the S: needs triage Issues/PRs that need to be triaged label May 18, 2020
@stonecharioteer stonecharioteer changed the title pip config should have an add commend pip config should have an add commend May 18, 2020
@stonecharioteer stonecharioteer changed the title pip config should have an add commend pip config should support add and remove commands May 18, 2020
@pradyunsg

This comment has been minimized.

@pradyunsg pradyunsg added the S: awaiting response Waiting for a response/more information label May 18, 2020
@triage-new-issues triage-new-issues bot removed the S: needs triage Issues/PRs that need to be triaged label May 18, 2020
@stonecharioteer

This comment has been minimized.

@no-response no-response bot removed the S: awaiting response Waiting for a response/more information label May 18, 2020
@stonecharioteer

This comment has been minimized.

@deveshks
Copy link
Contributor

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)

@pradyunsg
Copy link
Member

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

@stonecharioteer
Copy link
Author

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

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

@stonecharioteer
Copy link
Author

stonecharioteer commented May 25, 2020

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

@pradyunsg pradyunsg added the S: needs triage Issues/PRs that need to be triaged label Aug 30, 2020
@aamailhot
Copy link

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

@potiuk
Copy link
Contributor

potiuk commented Apr 13, 2022

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

@aamailhot
Copy link

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

@stonecharioteer
Copy link
Author

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?

@uranusjr
Copy link
Member

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 (#3809 (comment)) and these may need to be coordinated. cc @Shivansh-007

@mattangus
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: needs triage Issues/PRs that need to be triaged
Projects
None yet
Development

No branches or pull requests

7 participants