|
8 | 8 | import shutil
|
9 | 9 | import stat
|
10 | 10 | import subprocess
|
| 11 | +import sys |
11 | 12 | import tempfile
|
12 | 13 | import zipfile
|
13 | 14 |
|
|
17 | 18 | from typing import TYPE_CHECKING
|
18 | 19 | from typing import TextIO
|
19 | 20 |
|
20 |
| -from packaging.tags import sys_tags |
| 21 | +import packaging.tags |
21 | 22 |
|
22 | 23 | from poetry.core import __version__
|
23 | 24 | from poetry.core.constraints.version import parse_constraint
|
|
26 | 27 | from poetry.core.masonry.utils.helpers import distribution_name
|
27 | 28 | from poetry.core.masonry.utils.helpers import normalize_file_permissions
|
28 | 29 | from poetry.core.masonry.utils.package_include import PackageInclude
|
| 30 | +from poetry.core.utils.helpers import decode |
29 | 31 | from poetry.core.utils.helpers import temporary_directory
|
30 | 32 |
|
31 | 33 |
|
@@ -327,16 +329,59 @@ def dist_info_name(self, name: NormalizedName, version: str) -> str:
|
327 | 329 | escaped_name = distribution_name(name)
|
328 | 330 | return f"{escaped_name}-{version}.dist-info"
|
329 | 331 |
|
| 332 | + def _get_sys_tags(self) -> list[str]: |
| 333 | + """Get sys_tags via subprocess. |
| 334 | + Required if poetry-core is not run inside the build environment. |
| 335 | + """ |
| 336 | + try: |
| 337 | + output = subprocess.check_output( |
| 338 | + [ |
| 339 | + self.executable.as_posix(), |
| 340 | + "-c", |
| 341 | + f""" |
| 342 | +import importlib.util |
| 343 | +import sys |
| 344 | +
|
| 345 | +from pathlib import Path |
| 346 | +
|
| 347 | +spec = importlib.util.spec_from_file_location( |
| 348 | + "packaging", Path(r"{packaging.__file__}") |
| 349 | +) |
| 350 | +
|
| 351 | +packaging = importlib.util.module_from_spec(spec) |
| 352 | +sys.modules[spec.name] = packaging |
| 353 | +
|
| 354 | +spec = importlib.util.spec_from_file_location( |
| 355 | + "packaging.tags", Path(r"{packaging.tags.__file__}") |
| 356 | +) |
| 357 | +packaging_tags = importlib.util.module_from_spec(spec) |
| 358 | +spec.loader.exec_module(packaging_tags) |
| 359 | +for t in packaging_tags.sys_tags(): |
| 360 | + print(t.interpreter, t.abi, t.platform, sep="-") |
| 361 | +""", |
| 362 | + ], |
| 363 | + stderr=subprocess.STDOUT, |
| 364 | + ) |
| 365 | + except subprocess.CalledProcessError as e: |
| 366 | + raise RuntimeError( |
| 367 | + "Failed to get sys_tags for python interpreter" |
| 368 | + f" '{self.executable.as_posix()}':\n{decode(e.output)}" |
| 369 | + ) |
| 370 | + return decode(output).strip().splitlines() |
| 371 | + |
330 | 372 | @property
|
331 | 373 | def tag(self) -> str:
|
332 | 374 | if self._package.build_script:
|
333 |
| - sys_tag = next(sys_tags()) |
| 375 | + if self.executable != Path(sys.executable): |
| 376 | + # poetry-core is not run in the build environment |
| 377 | + # -> this is probably not a PEP 517 build but a poetry build |
| 378 | + return self._get_sys_tags()[0] |
| 379 | + sys_tag = next(packaging.tags.sys_tags()) |
334 | 380 | tag = (sys_tag.interpreter, sys_tag.abi, sys_tag.platform)
|
335 | 381 | else:
|
336 | 382 | platform = "any"
|
337 | 383 | impl = "py2.py3" if self.supports_python2() else "py3"
|
338 | 384 | tag = (impl, "none", platform)
|
339 |
| - |
340 | 385 | return "-".join(tag)
|
341 | 386 |
|
342 | 387 | def _add_file(
|
|
0 commit comments