Skip to content

Commit ee113be

Browse files
committed
Ran nox -s generate
1 parent 26416a4 commit ee113be

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

public/get-pip.py

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

4345

44-
def determine_pip_install_arguments():
45-
implicit_pip = True
46-
implicit_setuptools = True
47-
implicit_wheel = True
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
4854

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-
# 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
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+
65+
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()
71+
72+
args.append("pip")
6073

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
74+
if include_setuptools(pre):
75+
args.append("setuptools")
7576

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"]
77+
if include_wheel(pre):
78+
args.append("wheel")
8379

8480
return ["install", "--upgrade", "--force-reinstall"] + args
8581

0 commit comments

Comments
 (0)