|
40 | 40 | import sys
|
41 | 41 | import tarfile
|
42 | 42 | import tempfile
|
43 |
| -import textwrap |
44 | 43 | import time
|
45 | 44 | import zipfile
|
46 | 45 | from io import open # needed for python 2
|
47 | 46 | from urllib.parse import unquote as urlunquote
|
48 | 47 | from urllib.parse import urlparse
|
49 | 48 |
|
50 | 49 | import toml
|
51 |
| -from pep517.envbuild import BuildEnvironment |
52 |
| -from pep517.wrappers import Pep517HookCaller |
| 50 | +import build.util |
53 | 51 |
|
54 | 52 |
|
55 | 53 | def transform_dep_for_pip(dependency):
|
@@ -113,40 +111,7 @@ def extract_metainfo_files_from_package(
|
113 | 111 | )
|
114 | 112 | package = os.path.join(temp_folder, "package")
|
115 | 113 |
|
116 |
| - # Because PEP517 can be noisy and contextlib.redirect_* fails to |
117 |
| - # contain it, we will run the actual analysis in a separate process: |
118 |
| - try: |
119 |
| - subprocess.check_output([ |
120 |
| - sys.executable, |
121 |
| - "-c", |
122 |
| - "import importlib\n" |
123 |
| - "import json\n" |
124 |
| - "import os\n" |
125 |
| - "import sys\n" |
126 |
| - "sys.path = [os.path.dirname(sys.argv[3])] + sys.path\n" |
127 |
| - "m = importlib.import_module(\n" |
128 |
| - " os.path.basename(sys.argv[3]).partition('.')[0]\n" |
129 |
| - ")\n" |
130 |
| - "m._extract_metainfo_files_from_package_unsafe(" |
131 |
| - " sys.argv[1]," |
132 |
| - " sys.argv[2]," |
133 |
| - ")", |
134 |
| - package, output_folder, os.path.abspath(__file__)], |
135 |
| - stderr=subprocess.STDOUT, # make sure stderr is muted. |
136 |
| - cwd=os.path.join(os.path.dirname(__file__), "..") |
137 |
| - ) |
138 |
| - except subprocess.CalledProcessError as e: |
139 |
| - output = e.output.decode("utf-8", "replace") |
140 |
| - if debug: |
141 |
| - print("Got error obtaining meta info.") |
142 |
| - print("Detail output:") |
143 |
| - print(output) |
144 |
| - print("End of Detail output.") |
145 |
| - raise ValueError( |
146 |
| - "failed to obtain meta info - " |
147 |
| - "is '{}' a valid package? " |
148 |
| - "Detailed output:\n{}".format(package, output) |
149 |
| - ) |
| 114 | + _extract_metainfo_files_from_package_unsafe(package, output_folder) |
150 | 115 | finally:
|
151 | 116 | shutil.rmtree(temp_folder)
|
152 | 117 |
|
@@ -461,51 +426,17 @@ def _extract_metainfo_files_from_package_unsafe(
|
461 | 426 | clean_up_path = True
|
462 | 427 |
|
463 | 428 | try:
|
464 |
| - build_requires = [] |
465 | 429 | metadata_path = None
|
466 | 430 |
|
467 | 431 | if path_type != "wheel":
|
468 |
| - # We need to process this first to get the metadata. |
469 |
| - |
470 |
| - # Ensure pyproject.toml is available (pep517 expects it) |
471 |
| - if not os.path.exists(os.path.join(path, "pyproject.toml")): |
472 |
| - with open(os.path.join(path, "pyproject.toml"), "w") as f: |
473 |
| - f.write(textwrap.dedent(u"""\ |
474 |
| - [build-system] |
475 |
| - requires = ["setuptools", "wheel"] |
476 |
| - build-backend = "setuptools.build_meta" |
477 |
| - """)) |
478 |
| - |
479 |
| - # Copy the pyproject.toml: |
480 |
| - shutil.copyfile( |
481 |
| - os.path.join(path, 'pyproject.toml'), |
482 |
| - os.path.join(output_path, 'pyproject.toml') |
483 |
| - ) |
484 |
| - |
485 |
| - # Get build backend and requirements from pyproject.toml: |
486 |
| - with open(os.path.join(path, 'pyproject.toml')) as f: |
487 |
| - build_sys = toml.load(f)['build-system'] |
488 |
| - backend = build_sys["build-backend"] |
489 |
| - build_requires.extend(build_sys["requires"]) |
490 |
| - |
491 |
| - # Get a virtualenv with build requirements and get all metadata: |
492 |
| - env = BuildEnvironment() |
493 |
| - metadata = None |
494 |
| - with env: |
495 |
| - hooks = Pep517HookCaller(path, backend) |
496 |
| - env.pip_install( |
497 |
| - [transform_dep_for_pip(req) for req in build_requires] |
498 |
| - ) |
499 |
| - reqs = hooks.get_requires_for_build_wheel({}) |
500 |
| - env.pip_install([transform_dep_for_pip(req) for req in reqs]) |
501 |
| - try: |
502 |
| - metadata = hooks.prepare_metadata_for_build_wheel(path) |
503 |
| - except Exception: # sadly, pep517 has no good error here |
504 |
| - pass |
505 |
| - if metadata is not None: |
506 |
| - metadata_path = os.path.join( |
507 |
| - path, metadata, "METADATA" |
508 |
| - ) |
| 432 | + # Use a build helper function to fetch the metadata directly |
| 433 | + metadata = build.util.project_wheel_metadata(path) |
| 434 | + # And write it to a file |
| 435 | + metadata_path = os.path.join(output_path, "built_metadata") |
| 436 | + with open(metadata_path, 'w') as f: |
| 437 | + for key in metadata.keys(): |
| 438 | + for value in metadata.get_all(key): |
| 439 | + f.write("{}: {}\n".format(key, value)) |
509 | 440 | else:
|
510 | 441 | # This is a wheel, so metadata should be in *.dist-info folder:
|
511 | 442 | metadata_path = os.path.join(
|
|
0 commit comments