Skip to content

Commit 292c3ff

Browse files
committed
Allow pip to pick up the config from the sys.base_prefix.
1 parent ffbe932 commit 292c3ff

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

docs/html/user_guide.rst

+6-4
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ pip allows you to set all command line option defaults in a standard ini
358358
style config file.
359359

360360
The names and locations of the configuration files vary slightly across
361-
platforms. You may have per-user, per-virtualenv or global (shared amongst
362-
all users) configuration:
361+
platforms. You may have per-user, per-site (e.g per virtualenv) or global
362+
(shared amongst all users) configuration:
363363

364364
**Per-user**:
365365

@@ -380,11 +380,13 @@ these are located at:
380380
You can set a custom path location for this config file using the environment
381381
variable ``PIP_CONFIG_FILE``.
382382

383-
**Inside a virtualenv**:
383+
**Site (e.g inside a virtualenv)**
384384

385385
* On Unix and macOS the file is :file:`$VIRTUAL_ENV/pip.conf`
386386
* On Windows the file is: :file:`%VIRTUAL_ENV%\\pip.ini`
387387

388+
Additionally ``sys.base_prefix`` is searched for a pip config of the same name.
389+
388390
**Global**:
389391

390392
* On Unix the file may be located in :file:`/etc/pip.conf`. Alternatively
@@ -405,7 +407,7 @@ the following order:
405407

406408
1. The global file is read
407409
2. The per-user file is read
408-
3. The virtualenv-specific file is read
410+
3. The site file is read
409411

410412
Each file read overrides any values read from previous files, so if the
411413
global timeout is specified in both the global file and the per-user file

news/9752.feature.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Virtual environments may now inherit their pip config from the base environment.

src/pip/_internal/configuration.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ def get_configuration_files():
8080
for path in appdirs.site_config_dirs('pip')
8181
]
8282

83-
site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME)
83+
site_config_files = [
84+
os.path.join(sys.prefix, CONFIG_BASENAME)
85+
]
86+
if getattr(sys, 'base_prefix', sys.prefix) != sys.prefix:
87+
site_config_files.append(
88+
os.path.join(sys.base_prefix, CONFIG_BASENAME),
89+
)
90+
8491
legacy_config_file = os.path.join(
8592
expanduser('~'),
8693
'pip' if WINDOWS else '.pip',
@@ -91,7 +98,7 @@ def get_configuration_files():
9198
)
9299
return {
93100
kinds.GLOBAL: global_config_files,
94-
kinds.SITE: [site_config_file],
101+
kinds.SITE: site_config_files,
95102
kinds.USER: [legacy_config_file, new_config_file],
96103
}
97104

0 commit comments

Comments
 (0)