Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pip/_internal/utils/setuptools_build.py: 22%
40 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 06:33 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 06:33 +0000
1import sys
2import textwrap
3from typing import List, Optional, Sequence
5# Shim to wrap setup.py invocation with setuptools
6# Note that __file__ is handled via two {!r} *and* %r, to ensure that paths on
7# Windows are correctly handled (it should be "C:\\Users" not "C:\Users").
8_SETUPTOOLS_SHIM = textwrap.dedent(
9 """
10 exec(compile('''
11 # This is <pip-setuptools-caller> -- a caller that pip uses to run setup.py
12 #
13 # - It imports setuptools before invoking setup.py, to enable projects that directly
14 # import from `distutils.core` to work with newer packaging standards.
15 # - It provides a clear error message when setuptools is not installed.
16 # - It sets `sys.argv[0]` to the underlying `setup.py`, when invoking `setup.py` so
17 # setuptools doesn't think the script is `-c`. This avoids the following warning:
18 # manifest_maker: standard file '-c' not found".
19 # - It generates a shim setup.py, for handling setup.cfg-only projects.
20 import os, sys, tokenize
22 try:
23 import setuptools
24 except ImportError as error:
25 print(
26 "ERROR: Can not execute `setup.py` since setuptools is not available in "
27 "the build environment.",
28 file=sys.stderr,
29 )
30 sys.exit(1)
32 __file__ = %r
33 sys.argv[0] = __file__
35 if os.path.exists(__file__):
36 filename = __file__
37 with tokenize.open(__file__) as f:
38 setup_py_code = f.read()
39 else:
40 filename = "<auto-generated setuptools caller>"
41 setup_py_code = "from setuptools import setup; setup()"
43 exec(compile(setup_py_code, filename, "exec"))
44 ''' % ({!r},), "<pip-setuptools-caller>", "exec"))
45 """
46).rstrip()
49def make_setuptools_shim_args(
50 setup_py_path: str,
51 global_options: Optional[Sequence[str]] = None,
52 no_user_config: bool = False,
53 unbuffered_output: bool = False,
54) -> List[str]:
55 """
56 Get setuptools command arguments with shim wrapped setup file invocation.
58 :param setup_py_path: The path to setup.py to be wrapped.
59 :param global_options: Additional global options.
60 :param no_user_config: If True, disables personal user configuration.
61 :param unbuffered_output: If True, adds the unbuffered switch to the
62 argument list.
63 """
64 args = [sys.executable]
65 if unbuffered_output:
66 args += ["-u"]
67 args += ["-c", _SETUPTOOLS_SHIM.format(setup_py_path)]
68 if global_options:
69 args += global_options
70 if no_user_config:
71 args += ["--no-user-cfg"]
72 return args
75def make_setuptools_bdist_wheel_args(
76 setup_py_path: str,
77 global_options: Sequence[str],
78 build_options: Sequence[str],
79 destination_dir: str,
80) -> List[str]:
81 # NOTE: Eventually, we'd want to also -S to the flags here, when we're
82 # isolating. Currently, it breaks Python in virtualenvs, because it
83 # relies on site.py to find parts of the standard library outside the
84 # virtualenv.
85 args = make_setuptools_shim_args(
86 setup_py_path, global_options=global_options, unbuffered_output=True
87 )
88 args += ["bdist_wheel", "-d", destination_dir]
89 args += build_options
90 return args
93def make_setuptools_clean_args(
94 setup_py_path: str,
95 global_options: Sequence[str],
96) -> List[str]:
97 args = make_setuptools_shim_args(
98 setup_py_path, global_options=global_options, unbuffered_output=True
99 )
100 args += ["clean", "--all"]
101 return args
104def make_setuptools_develop_args(
105 setup_py_path: str,
106 *,
107 global_options: Sequence[str],
108 no_user_config: bool,
109 prefix: Optional[str],
110 home: Optional[str],
111 use_user_site: bool,
112) -> List[str]:
113 assert not (use_user_site and prefix)
115 args = make_setuptools_shim_args(
116 setup_py_path,
117 global_options=global_options,
118 no_user_config=no_user_config,
119 )
121 args += ["develop", "--no-deps"]
123 if prefix:
124 args += ["--prefix", prefix]
125 if home is not None:
126 args += ["--install-dir", home]
128 if use_user_site:
129 args += ["--user", "--prefix="]
131 return args
134def make_setuptools_egg_info_args(
135 setup_py_path: str,
136 egg_info_dir: Optional[str],
137 no_user_config: bool,
138) -> List[str]:
139 args = make_setuptools_shim_args(setup_py_path, no_user_config=no_user_config)
141 args += ["egg_info"]
143 if egg_info_dir:
144 args += ["--egg-base", egg_info_dir]
146 return args