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

Add a mechanism to have a config file that can be overriden by user config #11851

Open
1 task done
dalebrydon opened this issue Mar 9, 2023 · 6 comments
Open
1 task done
Labels
S: awaiting response Waiting for a response/more information type: feature request Request for a new feature

Comments

@dalebrydon
Copy link
Contributor

What's the problem this feature will solve?

Right now the only way to specify a config file that a user can override is to use the global config file which a user needs root to create. This is difficult for shared systems where non-administrators provide Python support.

Describe the solution you'd like

I suggest adding an environment variable along the lines of PIP_DEFAULT_CONFIG_FILE which is loaded first and overriden by all other config files. The major downside to this approach is that it will be a little hard to document/could lead to confusing or messy documentation.

Alternative Solutions

It is pretty standard notion to have configs like global < user < project-level < env vars. pip somewhat breaks this with the way site and base work. The idea of site is that a virtualenv config is basically like the project-level config. Unfortunately, when pip is not being used in a virtual environment, this sort of breaks the above as then we have something that is like a global config overriding user configs. But, this behaviour is probably unchangeable at this point, otherwise a file location somewhere next to the Python install might be ideal. As it is, no other location make sense, which basically only leaves an environment variable.

Additional context

To clarify slightly the situation, we have a group of users who are not admins that manage our python installs where I work. These versions of python are installed in "non-standard" locations and are made available to users via environment modules. Additionally, we have internal PyPI mirrors and other config we'd like to make available to users as a default, but enable them to override. There's not really a mechanism to do this currently.

Note I'm happy to make a PR for this if there's support for adding this feature.

Code of Conduct

@dalebrydon dalebrydon added S: needs triage Issues/PRs that need to be triaged type: feature request Request for a new feature labels Mar 9, 2023
@uranusjr
Copy link
Member

I don’t think this makes much sense, since the user can override that environment variable directly instead. Perhaps it is better to add a mechanism for a config file to “inherit” another config file.

@pradyunsg
Copy link
Member

This is difficult for shared systems where non-administrators provide Python support.

We've added an interepreter level configuration option (#11487) for precisely this usecase.

@pradyunsg
Copy link
Member

I think #9752 covers this.

@pradyunsg pradyunsg added S: awaiting response Waiting for a response/more information and removed S: needs triage Issues/PRs that need to be triaged labels Mar 10, 2023
@dalebrydon
Copy link
Contributor Author

This is difficult for shared systems where non-administrators provide Python support.

We've added an interepreter level configuration option (#11487) for precisely this usecase.

But that mechanism overrides user config.

@dalebrydon
Copy link
Contributor Author

I don’t think this makes much sense, since the user can override that environment variable directly instead. Perhaps it is better to add a mechanism for a config file to “inherit” another config file.

The idea of environment modules is that you do something like module load python3.10; python3 -m pip install blah. It wouldn't be very nice if switching versions of python also messed with pip config. That's an unnecessary intrusion into user space and will lead to confusion for the user (especially since user config isn't loaded at all if a PIP_CONFIG_FILE exists).

@pelson
Copy link
Contributor

pelson commented Mar 27, 2023

But that mechanism overrides user config.

Yes, you are right. The order of user config coming before base and site is unfortunate. At this point, I do not advocate for global or user config at all (the latter because of the precedence, the former because it is a sledgehammer).

The processing order is one of the reasons I wished to be able to control the processing order. I prototyped being able to configure the precedence, e.g.

config-precedence =
    base
    site
    user
    env_var

Which would do a first pass to compute the config-precedence, then a second pass (if necessary) to compute the final config. My implementation wasn't so complex, but it was possibly wrong (I think I found a problem with it at the time) and would introduce a whole new level of complexity to the config & docs... still, it would represent a good way to address this particular issue/need without breaking existing functionality.


As you pointed out in #11815 the PIP_CONFIG_FILE environment variable, despite what is said in the docs, is actually processed last. You could therefore set the environment variable to the user location if it is not set. module unload should do the right thing to restore the state afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: awaiting response Waiting for a response/more information type: feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

4 participants