|
1 | 1 | import sys
|
| 2 | +import textwrap |
2 | 3 | from typing import List, Optional, Sequence
|
3 | 4 |
|
4 | 5 | # Shim to wrap setup.py invocation with setuptools
|
5 |
| -# |
6 |
| -# We set sys.argv[0] to the path to the underlying setup.py file so |
7 |
| -# setuptools / distutils don't take the path to the setup.py to be "-c" when |
8 |
| -# invoking via the shim. This avoids e.g. the following manifest_maker |
9 |
| -# warning: "warning: manifest_maker: standard file '-c' not found". |
10 |
| -_SETUPTOOLS_SHIM = ( |
11 |
| - "import io, os, sys, setuptools, tokenize; sys.argv[0] = {0!r}; __file__={0!r};" |
12 |
| - "f = getattr(tokenize, 'open', open)(__file__) " |
13 |
| - "if os.path.exists(__file__) " |
14 |
| - "else io.StringIO('from setuptools import setup; setup()');" |
15 |
| - "code = f.read().replace('\\r\\n', '\\n');" |
16 |
| - "f.close();" |
17 |
| - "exec(compile(code, __file__, 'exec'))" |
18 |
| -) |
| 6 | +_SETUPTOOLS_SHIM = textwrap.dedent( |
| 7 | + """ |
| 8 | + exec(compile(''' |
| 9 | + # This is <pip-setuptools-shim> -- a shim that pip uses to run setup.py |
| 10 | + # |
| 11 | + # - It imports setuptools before invoking setup.py, to enable projects that directly |
| 12 | + # import from `distutils.core` to work with newer packaging standards. |
| 13 | + # - Provides a clearer error message when setuptools is not installed. |
| 14 | + # - It sets `sys.argv[0]` to the underlying `setup.py`, when invoking `setup.py` so |
| 15 | + # setuptools doesn't think the script is `-c`. This avoids the following warning: |
| 16 | + # manifest_maker: standard file '-c' not found". |
| 17 | + # - It generates a shim setup.py, for handling setup.cfg-only projects. |
| 18 | + import os, sys, tokenize |
| 19 | +
|
| 20 | + try: |
| 21 | + import setuptools |
| 22 | + except ImportError as error: |
| 23 | + raise RuntimeError( |
| 24 | + "setuptools is not available in the build environment, but is required " |
| 25 | + "to use setup.py-based projects with pip." |
| 26 | + ) from error |
| 27 | +
|
| 28 | + __file__ = {!r} |
| 29 | + sys.argv[0] = __file__ |
| 30 | +
|
| 31 | + if os.path.exists(__file__): |
| 32 | + filename = __file__ |
| 33 | + with tokenize.open(__file__) as f: |
| 34 | + setup_py_code = f.read() |
| 35 | + else: |
| 36 | + filename = "<auto-generated setuptools caller>" |
| 37 | + setup_py_code = "from setuptools import setup; setup()" |
| 38 | +
|
| 39 | + exec(compile(setup_py_code, filename, "exec")) |
| 40 | + ''', "<pip-setuptools-shim>", "exec")) |
| 41 | + """ |
| 42 | +).rstrip() |
19 | 43 |
|
20 | 44 |
|
21 | 45 | def make_setuptools_shim_args(
|
|
0 commit comments