(
cls,
interpreter, # type: PythonInterpreter
requires, # type: Iterable[str]
resolved, # type: Iterable[Distribution]
build_backend, # type: str
backend_path, # type: Tuple[str, ...]
extra_requirements=None, # type: Optional[Iterable[str]]
use_system_time=False, # type: bool
**extra_env # type: str
)
| 74 | class BuildSystem(object): |
| 75 | @classmethod |
| 76 | def create( |
| 77 | cls, |
| 78 | interpreter, # type: PythonInterpreter |
| 79 | requires, # type: Iterable[str] |
| 80 | resolved, # type: Iterable[Distribution] |
| 81 | build_backend, # type: str |
| 82 | backend_path, # type: Tuple[str, ...] |
| 83 | extra_requirements=None, # type: Optional[Iterable[str]] |
| 84 | use_system_time=False, # type: bool |
| 85 | **extra_env # type: str |
| 86 | ): |
| 87 | # type: (...) -> Union[BuildSystem, Error] |
| 88 | pex_builder = PEXBuilder(copy_mode=CopyMode.SYMLINK) |
| 89 | pex_builder.info.venv = True |
| 90 | pex_builder.info.venv_site_packages_copies = True |
| 91 | pex_builder.info.venv_bin_path = BinPath.PREPEND |
| 92 | # Allow REPRODUCIBLE_BUILDS_ENV PYTHONHASHSEED env var to take effect. |
| 93 | pex_builder.info.venv_hermetic_scripts = False |
| 94 | for req in requires: |
| 95 | pex_builder.add_requirement(req) |
| 96 | for dist in resolved: |
| 97 | pex_builder.add_distribution(dist) |
| 98 | pex_builder.freeze(bytecode_compile=False) |
| 99 | venv_pex = ensure_venv(PEX(pex_builder.path(), interpreter=interpreter)) |
| 100 | if extra_requirements: |
| 101 | # N.B.: We install extra requirements separately instead of having them resolved and |
| 102 | # handed in with the `resolved` above because there are cases in the wild where the |
| 103 | # build system requires (PEP-518) and the results of PEP-517 `get_requires_for_*` can |
| 104 | # return overlapping requirements. Pip will error for overlaps complaining of duplicate |
| 105 | # requirements if we attempt to resolve all the requirements at once; so we instead |
| 106 | # resolve and install in two phases. This obviously has problems! That said, it is, in |
| 107 | # fact, how Pip's internal PEP-517 build frontend works; so we emulate that. |
| 108 | virtualenv = Virtualenv(venv_pex.venv_dir) |
| 109 | # Python 3.5 comes with Pip 9.0.1 which is pretty broken: it doesn't work with our test |
| 110 | # cases; so we upgrade. |
| 111 | # For Python 2.7 we use virtualenv (there is no -m venv built into Python) and that |
| 112 | # comes with Pip 22.0.2, Python 3.6 comes with Pip 18.1 and Python 3.7 comes with |
| 113 | # Pip 22.04 and the default Pips only get newer with newer version of Pythons. These all |
| 114 | # work well enough for our test cases and, in general, they should work well enough with |
| 115 | # the Python they come paired with. |
| 116 | upgrade_pip = virtualenv.interpreter.version[:2] == (3, 5) |
| 117 | virtualenv.ensure_pip(upgrade=upgrade_pip) |
| 118 | with open(os.devnull, "wb") as dev_null: |
| 119 | _, process = virtualenv.interpreter.open_process( |
| 120 | args=[ |
| 121 | "-m", |
| 122 | "pip", |
| 123 | "install", |
| 124 | "--ignore-installed", |
| 125 | "--no-user", |
| 126 | "--no-warn-script-location", |
| 127 | ] |
| 128 | + list(extra_requirements), |
| 129 | stdout=dev_null, |
| 130 | stderr=subprocess.PIPE, |
| 131 | ) |
| 132 | _, stderr = process.communicate() |
| 133 | if process.returncode != 0: |
no test coverage detected