Skip to content

Commit 232a579

Browse files
committed
Ran nox -s generate
1 parent 787e713 commit 232a579

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

public/get-pip.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,40 +38,48 @@
3838
import pkgutil
3939
import shutil
4040
import tempfile
41-
import argparse
42-
import importlib
4341
from base64 import b85decode
4442

4543

46-
def include_setuptools(args):
47-
"""
48-
Install setuptools only if absent and not excluded.
49-
"""
50-
cli = not args.no_setuptools
51-
env = not os.environ.get("PIP_NO_SETUPTOOLS")
52-
absent = not importlib.util.find_spec("setuptools")
53-
return cli and env and absent
44+
def determine_pip_install_arguments():
45+
implicit_pip = True
46+
implicit_setuptools = True
47+
implicit_wheel = True
5448

49+
# Check if the user has requested us not to install setuptools
50+
if "--no-setuptools" in sys.argv or os.environ.get("PIP_NO_SETUPTOOLS"):
51+
args = [x for x in sys.argv[1:] if x != "--no-setuptools"]
52+
implicit_setuptools = False
53+
else:
54+
args = sys.argv[1:]
5555

56-
def include_wheel(args):
57-
"""
58-
Install wheel only if absent and not excluded.
59-
"""
60-
cli = not args.no_wheel
61-
env = not os.environ.get("PIP_NO_WHEEL")
62-
absent = not importlib.util.find_spec("wheel")
63-
return cli and env and absent
64-
56+
# Check if the user has requested us not to install wheel
57+
if "--no-wheel" in args or os.environ.get("PIP_NO_WHEEL"):
58+
args = [x for x in args if x != "--no-wheel"]
59+
implicit_wheel = False
6560

66-
def determine_pip_install_arguments():
67-
pre_parser = argparse.ArgumentParser()
68-
pre_parser.add_argument("--no-setuptools", action="store_true")
69-
pre_parser.add_argument("--no-wheel", action="store_true")
70-
pre, args = pre_parser.parse_known_args()
61+
# We only want to implicitly install setuptools and wheel if they don't
62+
# already exist on the target platform.
63+
if implicit_setuptools:
64+
try:
65+
import setuptools # noqa
66+
implicit_setuptools = False
67+
except ImportError:
68+
pass
69+
if implicit_wheel:
70+
try:
71+
import wheel # noqa
72+
implicit_wheel = False
73+
except ImportError:
74+
pass
7175

72-
args += ["pip"]
73-
args += ["setuptools"] * include_setuptools(pre)
74-
args += ["wheel"] * include_wheel(pre)
76+
# Add any implicit installations to the end of our args
77+
if implicit_pip:
78+
args += ["pip"]
79+
if implicit_setuptools:
80+
args += ["setuptools"]
81+
if implicit_wheel:
82+
args += ["wheel"]
7583

7684
return ["install", "--upgrade", "--force-reinstall"] + args
7785

0 commit comments

Comments
 (0)