Skip to content

gh-75229: ensurepip does not honour the value of $(prefix) #17634

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-31046: ensurepip does not honour the value of $(prefix)
Co-Authored-By: Xavier de Gaye <xdegaye@gmail.com>
  • Loading branch information
ZackerySpytz and xdegaye committed Dec 17, 2019
commit 5754521af1d51aa8e445cba07a093bbc0c88596d
9 changes: 7 additions & 2 deletions Doc/library/ensurepip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ is at least as recent as the one bundled with ``ensurepip``, pass the
By default, ``pip`` is installed into the current virtual environment
(if one is active) or into the system site packages (if there is no
active virtual environment). The installation location can be controlled
through two additional command line options:
through some additional command line options:

* ``--prefix <dir>``: Installs ``pip`` using the given directory prefix.
* ``--root <dir>``: Installs ``pip`` relative to the given root directory
rather than the root of the currently active virtual environment (if any)
or the default root for the current Python installation.
Expand Down Expand Up @@ -89,7 +90,7 @@ Module API
Returns a string specifying the bundled version of pip that will be
installed when bootstrapping an environment.

.. function:: bootstrap(root=None, upgrade=False, user=False, \
.. function:: bootstrap(root=None, prefix=None, upgrade=False, user=False, \
altinstall=False, default_pip=False, \
verbosity=0)

Expand All @@ -99,6 +100,8 @@ Module API
If *root* is ``None``, then installation uses the default install location
for the current environment.

*prefix* specifies the directory prefix to use when installing.

*upgrade* indicates whether or not to upgrade an existing installation
of an earlier version of ``pip`` to the bundled version.

Expand All @@ -119,6 +122,8 @@ Module API
*verbosity* controls the level of output to :data:`sys.stdout` from the
bootstrapping operation.

.. versionchanged:: 3.9 the *prefix* parameter was added.

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

.. note::
Expand Down
18 changes: 13 additions & 5 deletions Lib/ensurepip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ def _disable_pip_configuration_settings():
os.environ['PIP_CONFIG_FILE'] = os.devnull


def bootstrap(*, root=None, upgrade=False, user=False,
def bootstrap(*, root=None, prefix=None, upgrade=False, user=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add prefix at the end of the args list, as noted above. Also, supplying both root and prefix arguments doesn't really make sense (and may even be rejected by pip at some point in the future, if it isn't already) so it would be better to make these arguments mutually exclusive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, I'm not sure they should be mutual exclusive.

If root equals $(DESTDIR) and prefix equals $(prefix), I would guess we want to install into $(DESTDIR)/$(prefix). I need to look more closely at this later today.

altinstall=False, default_pip=False,
verbosity=0):
"""
Bootstrap pip into the current Python installation (or the given root
directory).
and directory prefix).

Note that calling this function will alter both sys.path and os.environ.
"""
# Discard the return value
_bootstrap(root=root, upgrade=upgrade, user=user,
_bootstrap(root=root, prefix=prefix, upgrade=upgrade, user=user,
altinstall=altinstall, default_pip=default_pip,
verbosity=verbosity)


def _bootstrap(*, root=None, upgrade=False, user=False,
def _bootstrap(*, root=None, prefix=None, upgrade=False, user=False,
altinstall=False, default_pip=False,
verbosity=0):
"""
Bootstrap pip into the current Python installation (or the given root
directory). Returns pip command status code.
and directory prefix). Returns pip command status code.

Note that calling this function will alter both sys.path and os.environ.
"""
Expand Down Expand Up @@ -112,6 +112,8 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
args = ["install", "--no-index", "--find-links", tmpdir]
if root:
args += ["--root", root]
if prefix:
args += ["--prefix", prefix]
if upgrade:
args += ["--upgrade"]
if user:
Expand Down Expand Up @@ -183,6 +185,11 @@ def _main(argv=None):
default=None,
help="Install everything relative to this alternate root directory.",
)
parser.add_argument(
"--prefix",
default=None,
help="Install everything using this prefix.",
)
parser.add_argument(
"--altinstall",
action="store_true",
Expand All @@ -202,6 +209,7 @@ def _main(argv=None):

return _bootstrap(
root=args.root,
prefix=args.prefix,
upgrade=args.upgrade,
user=args.user,
verbosity=args.verbosity,
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_ensurepip.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ def test_bootstrapping_with_root(self):
unittest.mock.ANY,
)

def test_bootstrapping_with_prefix(self):
ensurepip.bootstrap(prefix="/foo/bar/")
self.run_pip.assert_called_once_with(
[
"install", "--no-index", "--find-links",
unittest.mock.ANY, "--prefix", "/foo/bar/",
"setuptools", "pip",
],
unittest.mock.ANY,
)

def test_bootstrapping_with_user(self):
ensurepip.bootstrap(user=True)

Expand Down
4 changes: 2 additions & 2 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ install: @FRAMEWORKINSTALLFIRST@ commoninstall bininstall maninstall @FRAMEWORKI
install|*) ensurepip="" ;; \
esac; \
$(RUNSHARED) $(PYTHON_FOR_BUILD) -m ensurepip \
$$ensurepip --root=$(DESTDIR)/ ; \
$$ensurepip --root=$(DESTDIR)/ --prefix=$(prefix) ; \
fi

altinstall: commoninstall
Expand All @@ -1191,7 +1191,7 @@ altinstall: commoninstall
install|*) ensurepip="--altinstall" ;; \
esac; \
$(RUNSHARED) $(PYTHON_FOR_BUILD) -m ensurepip \
$$ensurepip --root=$(DESTDIR)/ ; \
$$ensurepip --root=$(DESTDIR)/ --prefix=$(prefix) ; \
fi

commoninstall: check-clean-src @FRAMEWORKALTINSTALLFIRST@ \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A directory prefix can now be specified when using :mod:`ensurepip`.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy