Skip to content

Commit 6afa367

Browse files
committed
Allow pip to pick up the config from the sys.base_prefix.
1 parent ade7220 commit 6afa367

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
@@ -499,8 +499,8 @@ pip allows you to set all command line option defaults in a standard ini
499499
style config file.
500500

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

505505
**Per-user**:
506506

@@ -521,11 +521,13 @@ To find its location:
521521
You can set a custom path location for this config file using the environment
522522
variable ``PIP_CONFIG_FILE``.
523523

524-
**Inside a virtualenv**:
524+
**Site (e.g inside a virtualenv)**
525525

526526
* On Unix and macOS the file is :file:`$VIRTUAL_ENV/pip.conf`
527527
* On Windows the file is: :file:`%VIRTUAL_ENV%\\pip.ini`
528528

529+
Additionally ``sys.base_prefix`` is searched for a pip config of the same name.
530+
529531
**Global**:
530532

531533
* On Unix the file may be located in :file:`/etc/pip.conf`. Alternatively
@@ -546,7 +548,7 @@ the following order:
546548

547549
1. The global file is read
548550
2. The per-user file is read
549-
3. The virtualenv-specific file is read
551+
3. The site file is read
550552

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

news/9752.feature.rst

+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
@@ -75,7 +75,14 @@ def get_configuration_files():
7575
for path in appdirs.site_config_dirs('pip')
7676
]
7777

78-
site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME)
78+
site_config_files = [
79+
os.path.join(sys.prefix, CONFIG_BASENAME)
80+
]
81+
if getattr(sys, 'base_prefix', sys.prefix) != sys.prefix:
82+
site_config_files.append(
83+
os.path.join(sys.base_prefix, CONFIG_BASENAME),
84+
)
85+
7986
legacy_config_file = os.path.join(
8087
os.path.expanduser('~'),
8188
'pip' if WINDOWS else '.pip',
@@ -86,7 +93,7 @@ def get_configuration_files():
8693
)
8794
return {
8895
kinds.GLOBAL: global_config_files,
89-
kinds.SITE: [site_config_file],
96+
kinds.SITE: site_config_files,
9097
kinds.USER: [legacy_config_file, new_config_file],
9198
}
9299

0 commit comments

Comments
 (0)