Skip to content

Commit 70debe5

Browse files
Use build rather than pep517 for building (kivy#2784)
pep517 has been renamed to pyproject-hooks, and as a consequence all of the deprecated functionality has been removed. build now provides the functionality required, and since we are only interested in the metadata, we can leverage a helper function for that. I've also removed all of the subprocess machinery for calling the wrapping function, since it appears to not be as noisy as pep517.
1 parent 5ff00ab commit 70debe5

File tree

4 files changed

+18
-90
lines changed

4 files changed

+18
-90
lines changed

pythonforandroid/pythonpackage.py

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,14 @@
4040
import sys
4141
import tarfile
4242
import tempfile
43-
import textwrap
4443
import time
4544
import zipfile
4645
from io import open # needed for python 2
4746
from urllib.parse import unquote as urlunquote
4847
from urllib.parse import urlparse
4948

5049
import toml
51-
from pep517.envbuild import BuildEnvironment
52-
from pep517.wrappers import Pep517HookCaller
50+
import build.util
5351

5452

5553
def transform_dep_for_pip(dependency):
@@ -113,40 +111,7 @@ def extract_metainfo_files_from_package(
113111
)
114112
package = os.path.join(temp_folder, "package")
115113

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)
150115
finally:
151116
shutil.rmtree(temp_folder)
152117

@@ -461,51 +426,17 @@ def _extract_metainfo_files_from_package_unsafe(
461426
clean_up_path = True
462427

463428
try:
464-
build_requires = []
465429
metadata_path = None
466430

467431
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))
509440
else:
510441
# This is a wheel, so metadata should be in *.dist-info folder:
511442
metadata_path = os.path.join(

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
install_reqs = [
2323
'appdirs', 'colorama>=0.3.3', 'jinja2',
2424
'sh>=1.10, <2.0; sys_platform!="nt"',
25-
'pep517', 'toml', 'packaging',
25+
'build', 'toml', 'packaging',
2626
]
27-
# (pep517 and toml are used by pythonpackage.py)
27+
# (build and toml are used by pythonpackage.py)
2828

2929

3030
# By specifying every file manually, package_data will be able to

tests/test_pythonpackage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_get_package_dependencies():
4242
if "MarkupSafe" in dep
4343
]
4444
# Check setuptools not being in non-recursive deps:
45-
# (It will be in recursive ones due to p4a's pep517 dependency)
45+
# (It will be in recursive ones due to p4a's build dependency)
4646
assert "setuptools" not in deps_nonrecursive
4747
# Check setuptools is present in non-recursive deps,
4848
# if we also add build requirements:

tests/test_pythonpackage_basic.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def run__get_system_python_executable(self, pybin):
236236
pybin,
237237
"-c",
238238
"import importlib\n"
239-
"import json\n"
239+
"import build.util\n"
240240
"import os\n"
241241
"import sys\n"
242242
"sys.path = [os.path.dirname(sys.argv[1])] + sys.path\n"
@@ -273,8 +273,8 @@ def test_systemwide_python(self):
273273
# Some deps may not be installed, so we just avoid to raise
274274
# an exception here, as a missing dep should not make the test
275275
# fail.
276-
if "pep517" in str(e.args):
277-
# System python probably doesn't have pep517 available!
276+
if "build" in str(e.args):
277+
# System python probably doesn't have build available!
278278
pass
279279
elif "toml" in str(e.args):
280280
# System python probably doesn't have toml available!
@@ -304,11 +304,8 @@ def test_venv(self):
304304
])
305305
subprocess.check_output([
306306
os.path.join(test_dir, "venv", "bin", "pip"),
307-
"install", "-U", "pep517"
308-
])
309-
subprocess.check_output([
310-
os.path.join(test_dir, "venv", "bin", "pip"),
311-
"install", "-U", "toml"
307+
"install", "-U", "build", "toml", "sh<2.0", "colorama",
308+
"appdirs", "jinja2", "packaging"
312309
])
313310
sys_python_path = self.run__get_system_python_executable(
314311
os.path.join(test_dir, "venv", "bin", "python")

0 commit comments

Comments
 (0)