Skip to content

Commit

Permalink
Enable PEP 517 (closes #715)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Dec 20, 2022
1 parent 40e7421 commit 3a8528f
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,32 +264,23 @@ class PythonPlugin implements Plugin<Project> {
}

Task createBuildPackagesTask() {
// pip by default finds the cacert file using a path relative to __file__, which won't work
// when __file__ is something like path/to/a.zip/path/to/module.py. It's easier to run
// directly from the ZIP and extract the cacert file, than it is to extract the entire ZIP
// and then deal with auto-generated pyc files complicating the up-to-date checks.
return project.task("extractPythonBuildPackages") {
// With Python 2.7 on Windows, zipimport has a maximum path length of about 256
// characters, including the path of the ZIP file itself. The longest path within
// the ZIP is currently 66 characters, which means the maximum ZIP file path length
// is about 190. The integration tests with the longest names get quite close to that,
// so make the filename as short as possible.
def zipName = "bp.zip"
ext.buildPackagesZip = "$genDir/$zipName"
def cacertRelPath = "pip/_vendor/certifi/cacert.pem"
ext.cacertPem = "$genDir/$cacertRelPath"
outputs.files(buildPackagesZip, cacertPem)
// To avoid the the Windows 260-character limit, make the path as short as
// possible.
ext.pythonPath = "$genDir/bp"
outputs.files(project.fileTree(pythonPath) {
exclude "**/__pycache__"
})
doLast {
extractResource("gradle/build-packages.zip", genDir, zipName)

// Remove existing directory, otherwise failure to extract will go unnoticed if a
// previous file still exists.
project.delete("$genDir/${cacertRelPath.split("/")[0]}")
project.delete(pythonPath)
project.mkdir(pythonPath)
def zipPath = extractResource("gradle/build-packages.zip", genDir)
project.copy {
from project.zipTree(buildPackagesZip)
include cacertRelPath
into genDir
from project.zipTree(zipPath)
into pythonPath
}
project.delete(zipPath)
project.delete("$genDir/bp.zip") // From Chaquopy 13.0 and older.
}
}
}
Expand Down Expand Up @@ -337,10 +328,7 @@ class PythonPlugin implements Plugin<Project> {
args("--android-abis", *abis)
args reqsArgs
args "--"
args "--chaquopy", PLUGIN_VERSION
args "--no-build-isolation", "--no-use-pep517" // TODO #5711
args "--disable-pip-version-check"
args "--cert", buildPackagesTask.cacertPem
if (!("--index-url" in python.pip.options ||
"-i" in python.pip.options)) {
// If the user passes --index-url, disable our repository as well
Expand Down Expand Up @@ -510,7 +498,7 @@ class PythonPlugin implements Plugin<Project> {
ExecResult execResult = null
try {
execResult = project.exec {
environment "PYTHONPATH", buildPackagesTask.buildPackagesZip
environment "PYTHONPATH", buildPackagesTask.pythonPath
commandLine python.buildPython
args "-S" // Avoid interference from site-packages. This is not inherited by
// subprocesses, so it's used again in pip_install.py.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def parse_args(self, args):
def main(self, args):
# type: (List[str]) -> int
options, args = self.parse_args(args)
assert options.chaquopy, "Chaquopy pip called without --chaquopy"

# Set verbosity so that it can be used elsewhere.
self.verbosity = options.verbose - options.quiet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,6 @@ def check_dist_restriction(options, check_target=False):
# options #
###########

# Adding this option ensures that if we run the system copy of pip by mistake, we fail
# immediately and with a distinctive error message.
chaquopy = partial(
Option,
'--chaquopy',
help="Chaquopy version number")

help_ = partial(
Option,
'-h', '--help',
Expand Down Expand Up @@ -912,7 +905,6 @@ def check_list_path_option(options):
general_group = {
'name': 'General Options',
'options': [
chaquopy,
help_,
isolated_mode,
require_virtualenv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ def load_pyproject_toml(
"project does not have a setup.py"
)
use_pep517 = True

# Chaquopy: added False so we always fall back on setup.py if available, as previous pip
# versions did.
elif False and build_system and "build-backend" in build_system:
elif build_system and "build-backend" in build_system:
if use_pep517 is not None and not use_pep517:
raise InstallationError(
"Disabling PEP 517 processing is invalid: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def format_full_version(info):
version += kind[0] + str(info.serial)
return version

# Chaquopy: this variable is set in cli/cmdoptions.py.
# Chaquopy: when installing for the target platform, this variable is set in
# cli/cmdoptions.py.
python_version_info = None

def default_environment():
Expand All @@ -251,20 +252,36 @@ def default_environment():
iver = "0"
implementation_name = ""

# Chaquopy: changed to use markers of the target platform rather than the build platform.
return {
"implementation_name": "cpython",
"implementation_version": ".".join(str(x) for x in python_version_info),
"os_name": "posix",
"platform_machine": "", # Not needed yet.
"platform_release": "",
"platform_system": "Linux",
"platform_version": "",
"python_full_version": ".".join(str(x) for x in python_version_info),
"platform_python_implementation": "CPython",
"python_version": ".".join(str(x) for x in python_version_info[:2]),
"sys_platform": "linux",
}
if python_version_info:
# Chaquopy: use markers of the target platform.
return {
"implementation_name": "cpython",
"implementation_version": ".".join(str(x) for x in python_version_info),
"os_name": "posix",
"platform_machine": "", # Not needed yet.
"platform_release": "",
"platform_system": "Linux",
"platform_version": "",
"python_full_version": ".".join(str(x) for x in python_version_info),
"platform_python_implementation": "CPython",
"python_version": ".".join(str(x) for x in python_version_info[:2]),
"sys_platform": "linux",
}
else:
# Chaquopy: use markers of the build platform.
return {
"implementation_name": implementation_name,
"implementation_version": iver,
"os_name": os.name,
"platform_machine": platform.machine(),
"platform_release": platform.release(),
"platform_system": platform.system(),
"platform_version": platform.version(),
"python_full_version": platform.python_version(),
"platform_python_implementation": platform.python_implementation(),
"python_version": platform.python_version()[:3],
"sys_platform": sys.platform,
}


class Marker(object):
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools>=40.8.0", "wheel"]
requires = ["setuptools==40.8.0", "wheel"]
build-backend = "setuptools.build_meta"
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import setuptools
from setuptools import setup


setup(
name="sdist_pep517",
version="1.0",
version=setuptools.__version__,
py_modules=["sdist_pep517"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ android {
versionCode 1
versionName "0.0.1"
python {
version "3.6.5"
pip {
install "./sdist_pep517"
}
}
ndk {
abiFilters "arm64-v8a"
abiFilters "x86"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build-system]
requires = ["setuptools==40.8.0", "wheel"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import setuptools
from setuptools import setup


setup(
name="sdist_pep517",
version=setuptools.__version__,
py_modules=["sdist_pep517"],
)
30 changes: 10 additions & 20 deletions product/gradle-plugin/src/test/integration/test_gradle_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,6 @@ def test_apply(self):
def test_apply_buildscript(self):
self.RunGradle("base", "ChaquopyPlugin/apply_buildscript")

# Since this version, the extracted copy of build-packages.zip has been renamed to bp.zip.
# We distinguish the old version by it not supporting arm64-v8a.
def test_upgrade_3_0_0(self):
run = self.RunGradle("base", "ChaquopyPlugin/upgrade_3_0_0", succeed=False)
self.assertInLong("Chaquopy does not support the ABI 'arm64-v8a'", run.stderr)
run.apply_layers("base", "ChaquopyPlugin/upgrade_current")
run.rerun(abis=["arm64-v8a"])

# Since this version, there has been no change in the build-packages.zip filename. We
# distinguish the old version by it not supporting arm64-v8a.
def test_upgrade_4_0_0(self):
run = self.RunGradle("base", "ChaquopyPlugin/upgrade_4_0_0", succeed=False)
self.assertInLong("Chaquopy does not support the ABI 'arm64-v8a'", run.stderr)
run.apply_layers("base", "ChaquopyPlugin/upgrade_current")
run.rerun(abis=["arm64-v8a"])


class AndroidPlugin(GradleTestCase):
ADVICE = ("please edit the version of com.android.application, com.android.library or "
Expand Down Expand Up @@ -904,10 +888,16 @@ def test_wheel_data(self):
def test_sdist_file(self):
self.RunGradle("base", "PythonReqs/sdist_file", requirements=["alpha_dep/__init__.py"])

# We currently disable PEP 517, and patch pip to fall back on setup.py, as it did in
# previous versions.
def test_sdist_pep517(self):
self.RunGradle("base", "PythonReqs/sdist_pep517", requirements=["sdist_pep517.py"])
# This project uses pyproject.toml to require a specific version of setuptools, then
# gives itself the same version number.
def test_pep517(self):
self.RunGradle("base", "PythonReqs/pep517", requirements=["sdist_pep517.py"],
dist_versions=[("sdist_pep517", "40.8.0")])

# Same as test_pep517, but pyproject.toml does not contain a `build-backend` setting.
def test_pep517_default_backend(self):
self.RunGradle("base", "PythonReqs/pep517", requirements=["sdist_pep517.py"],
dist_versions=[("sdist_pep517", "40.8.0")])

# Make sure we're not affected by a setup.cfg file containing a `prefix` line.
def test_cfg_wheel(self):
Expand Down

0 comments on commit 3a8528f

Please sign in to comment.