Skip to content

Commit a75d2c7

Browse files
erlend-aaslandmcepl
authored andcommitted
Address Paul's review
1 parent 63b8db1 commit a75d2c7

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

Doc/library/ensurepip.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,16 @@ Module API
106106
Returns a string specifying the available version of pip that will be
107107
installed when bootstrapping an environment.
108108

109-
.. function:: bootstrap(root=None, prefix=None, upgrade=False, user=False, \
109+
.. function:: bootstrap(root=None, upgrade=False, user=False, \
110110
altinstall=False, default_pip=False, \
111-
verbosity=0)
111+
verbosity=0, prefix=None)
112112

113113
Bootstraps ``pip`` into the current or designated environment.
114114

115115
*root* specifies an alternative root directory to install relative to.
116116
If *root* is ``None``, then installation uses the default install location
117117
for the current environment.
118118

119-
*prefix* specifies the directory prefix to use when installing.
120-
121119
*upgrade* indicates whether or not to upgrade an existing installation
122120
of an earlier version of ``pip`` to the available version.
123121

@@ -138,9 +136,11 @@ Module API
138136
*verbosity* controls the level of output to :data:`sys.stdout` from the
139137
bootstrapping operation.
140138

139+
*prefix* specifies the directory prefix to use when installing.
140+
141141
.. versionchanged:: 3.13
142142

143-
The *prefix* parameter was added.
143+
The *prefix* parameter.
144144

145145
.. audit-event:: ensurepip.bootstrap root ensurepip.bootstrap
146146

Lib/ensurepip/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,30 +106,32 @@ def _disable_pip_configuration_settings():
106106
os.environ['PIP_CONFIG_FILE'] = os.devnull
107107

108108

109-
def bootstrap(*, root=None, prefix=None, upgrade=False, user=False,
109+
def bootstrap(*, root=None, upgrade=False, user=False,
110110
altinstall=False, default_pip=False,
111-
verbosity=0):
111+
verbosity=0, prefix=None):
112112
"""
113113
Bootstrap pip into the current Python installation (or the given root
114114
and directory prefix).
115115
116116
Note that calling this function will alter both sys.path and os.environ.
117117
"""
118118
# Discard the return value
119-
_bootstrap(root=root, prefix=prefix, upgrade=upgrade, user=user,
119+
_bootstrap(root=root, upgrade=upgrade, user=user,
120120
altinstall=altinstall, default_pip=default_pip,
121-
verbosity=verbosity)
121+
verbosity=verbosity, prefix=prefix)
122122

123123

124-
def _bootstrap(*, root=None, prefix=None, upgrade=False, user=False,
124+
def _bootstrap(*, root=None, upgrade=False, user=False,
125125
altinstall=False, default_pip=False,
126-
verbosity=0):
126+
verbosity=0, prefix=None):
127127
"""
128128
Bootstrap pip into the current Python installation (or the given root
129129
and directory prefix). Returns pip command status code.
130130
131131
Note that calling this function will alter both sys.path and os.environ.
132132
"""
133+
if root is not None and prefix is not None:
134+
raise ValueError("Cannot use 'root' and 'prefix' together")
133135
if altinstall and default_pip:
134136
raise ValueError("Cannot use altinstall and default_pip together")
135137

Lib/test/test_ensurepip.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ def test_bootstrapping_with_prefix(self):
110110
unittest.mock.ANY,
111111
)
112112

113+
def test_root_and_prefix_mutual_exclusive(self):
114+
with self.assertRaises(ValueError):
115+
ensurepip.bootstrap(root="", prefix="")
116+
self.assertFalse(self.run_pip.called)
117+
113118
def test_bootstrapping_with_user(self):
114119
ensurepip.bootstrap(user=True)
115120

Makefile.pre.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ install: @FRAMEWORKINSTALLFIRST@ @INSTALLTARGETS@ @FRAMEWORKINSTALLLAST@
23362336
install|*) ensurepip="" ;; \
23372337
esac; \
23382338
$(RUNSHARED) $(PYTHON_FOR_BUILD) -m ensurepip \
2339-
$$ensurepip --root=$(DESTDIR)/ --prefix=$(prefix) ; \
2339+
$$ensurepip --prefix=$(prefix) ; \
23402340
fi
23412341

23422342
.PHONY: altinstall
@@ -2347,7 +2347,7 @@ altinstall: commoninstall
23472347
install|*) ensurepip="--altinstall" ;; \
23482348
esac; \
23492349
$(RUNSHARED) $(PYTHON_FOR_BUILD) -m ensurepip \
2350-
$$ensurepip --root=$(DESTDIR)/ --prefix=$(prefix) ; \
2350+
$$ensurepip --prefix=$(prefix) ; \
23512351
fi
23522352

23532353
.PHONY: commoninstall

0 commit comments

Comments
 (0)