From 7db47de7733076d1d6111616d0c53a73f9a8fa03 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Thu, 22 Dec 2022 19:08:26 +0000 Subject: [PATCH] Disable native builds within a PEP 517 environment that's building for the target platform (#715) --- .../src/main/python/chaquopy_monkey.py | 87 ++++++++++++++++++ .../main/python/pip/_internal/build_env.py | 16 ++++ .../python/pip/_internal/cli/cmdoptions.py | 2 +- .../pip/_internal/operations/prepare.py | 10 +- .../python/pip/_internal/req/req_install.py | 15 +-- .../pip/_internal/utils/setuptools_build.py | 12 ++- .../src/main/python/pip/_internal/wheel.py | 36 ++++---- .../src/main/python/setuptools/monkey.py | 86 +---------------- .../data/PythonReqs/pep517/app/build.gradle | 2 +- .../PythonReqs/pep517/app/pep517/setup.py | 12 +++ .../pep517/app/sdist_pep517/sdist_pep517.py | 0 .../pep517/app/sdist_pep517/setup.py | 9 -- .../pep517_default_backend/app/build.gradle | 21 ----- .../app/pep517/pyproject.toml | 2 + .../app/sdist_pep517/pyproject.toml | 2 - .../app/sdist_pep517/sdist_pep517.py | 0 .../app/sdist_pep517/setup.py | 9 -- .../app/pep517/pyproject.toml | 3 + .../sdist_native_cc/app/build.gradle | 2 +- .../app/sdist_native}/setup.py | 0 .../app/sdist_native_cc-1.0.tar.gz | Bin 824 -> 0 bytes .../sdist_native_clib/app/build.gradle | 2 +- .../app/sdist_native}/libtest.c | 0 .../app/sdist_native}/setup.py | 0 .../app/sdist_native_clib-1.0.tar.gz | Bin 721 -> 0 bytes .../sdist_native_compiler/app/build.gradle | 2 +- .../app/sdist_native}/setup.py | 0 .../app/sdist_native_compiler-1.0.tar.gz | Bin 784 -> 0 bytes .../sdist_native_ext/app/build.gradle | 2 +- .../app/sdist_native}/ext_module.c | 0 .../app/sdist_native}/setup.py | 0 .../app/sdist_native_ext-1.0.tar.gz | Bin 733 -> 0 bytes .../app/build.gradle | 2 +- .../sdist_native_optional_compiler.py | 0 .../app/sdist_native}/setup.py | 0 .../sdist_native_optional_compiler-1.0.zip | Bin 1033 -> 0 bytes .../app/build.gradle | 2 +- .../app/sdist_native}/ext_module.c | 0 .../sdist_native_optional_ext.py | 0 .../app/sdist_native}/setup.py | 0 .../app/sdist_native_optional_ext-1.0.zip | Bin 1332 -> 0 bytes .../app/sdist_native}/pyproject.toml | 2 +- .../src/test/integration/packages/README.txt | 7 ++ .../test/integration/test_gradle_plugin.py | 65 ++++++++----- 44 files changed, 221 insertions(+), 189 deletions(-) create mode 100644 product/gradle-plugin/src/main/python/chaquopy_monkey.py create mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/pep517/setup.py delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/sdist_pep517/sdist_pep517.py delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/sdist_pep517/setup.py delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/build.gradle create mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/pep517/pyproject.toml delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/pyproject.toml delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/sdist_pep517.py delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/setup.py create mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_explicit_backend/app/pep517/pyproject.toml rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_cc => data/PythonReqs/sdist_native_cc/app/sdist_native}/setup.py (100%) delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_cc/app/sdist_native_cc-1.0.tar.gz rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_clib => data/PythonReqs/sdist_native_clib/app/sdist_native}/libtest.c (100%) rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_clib => data/PythonReqs/sdist_native_clib/app/sdist_native}/setup.py (100%) delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/sdist_native_clib-1.0.tar.gz rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_compiler => data/PythonReqs/sdist_native_compiler/app/sdist_native}/setup.py (100%) delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_compiler/app/sdist_native_compiler-1.0.tar.gz rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_ext => data/PythonReqs/sdist_native_ext/app/sdist_native}/ext_module.c (100%) rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_ext => data/PythonReqs/sdist_native_ext/app/sdist_native}/setup.py (100%) delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/sdist_native_ext-1.0.tar.gz rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_optional_compiler => data/PythonReqs/sdist_native_optional_compiler/app/sdist_native}/sdist_native_optional_compiler.py (100%) rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_optional_compiler => data/PythonReqs/sdist_native_optional_compiler/app/sdist_native}/setup.py (100%) delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_compiler/app/sdist_native_optional_compiler-1.0.zip rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_optional_ext => data/PythonReqs/sdist_native_optional_ext/app/sdist_native}/ext_module.c (100%) rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_optional_ext => data/PythonReqs/sdist_native_optional_ext/app/sdist_native}/sdist_native_optional_ext.py (100%) rename product/gradle-plugin/src/test/integration/{packages/src/sdist_native_optional_ext => data/PythonReqs/sdist_native_optional_ext/app/sdist_native}/setup.py (100%) delete mode 100644 product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/sdist_native_optional_ext-1.0.zip rename product/gradle-plugin/src/test/integration/data/PythonReqs/{pep517/app/sdist_pep517 => sdist_native_pep517/app/sdist_native}/pyproject.toml (56%) diff --git a/product/gradle-plugin/src/main/python/chaquopy_monkey.py b/product/gradle-plugin/src/main/python/chaquopy_monkey.py new file mode 100644 index 00000000000..53e49c21d46 --- /dev/null +++ b/product/gradle-plugin/src/main/python/chaquopy_monkey.py @@ -0,0 +1,87 @@ +# We want to cause a quick and comprehensible failure when a package attempts to build +# native code, while still allowing a pure-Python fallback if available. This is tricky, +# because different packages have different approaches to pure-Python fallbacks: +# +# * Some packages simply catch any distutils exception thrown by setup(), and then run it again +# with the native components removed. +# +# * Some (e.g. sqlalchemy, wrapt) extend the distutils build_ext or build_clib command and +# override its run() method to wrap it with an exception handler. This means we can't simply +# block the commands by name, e.g. by overriding Distribution.run_command. +# +# * Some (e.g. msgpack) go lower-level and catch exceptions in build_ext.build_extension. In +# Python 3, there's an `optional` keyword to Extension which has the same effect (used e.g. +# by websockets). Blocking build_ext.run, or CCompiler.__init__, would cause these builds to +# fail before build_extension is called, and the pure-Python fallback wouldn't happen. +# +# Creating a new compiler class with a new name minimizes the chance of code trying to do +# things which will only work on the standard classses. For example, +# distutils.sysconfig.customize_compiler does things with a "unix" compiler which will crash on +# Windows because get_config_vars won't have certain settings. +# +# This is simpler than determining the regular compiler class and extending it. It avoids +# interference from NumPy's widespread monkey-patching (including new_compiler, CCompiler and +# its subclasses), which takes place after this code is run. It also avoids the default +# behaviour on Windows when no compiler is installed, which is either to give the "Unable to +# find vcvarsall.bat" error, or advice on how to install Visual C++, both of which will waste +# the user's time. +# +# This approach will block builds of packages which require the compiler name to be in a known +# list (e.g. minorminer, lz4), but the error messages from these packages aren't too bad, and +# I've never seen one which has a pure-Python fallback. +def disable_native(): + # Recent versions of setuptools redirect distutils to their own bundled copy, so try + # to import that first. + try: + import setuptools # noqa: F401 + except ImportError: + pass + + from distutils import ccompiler + from distutils.unixccompiler import UnixCCompiler + import os + import sys + import types + + ccompiler.get_default_compiler = lambda *args, **kwargs: "disabled" + ccompiler.compiler_class["disabled"] = ( + "disabledcompiler", "DisabledCompiler", + "Compiler disabled ({})".format(CHAQUOPY_NATIVE_ERROR)) + + class DisabledCompiler(ccompiler.CCompiler): + compiler_type = "disabled" + def preprocess(*args, **kwargs): + chaquopy_block_native("CCompiler.preprocess") + def compile(*args, **kwargs): + chaquopy_block_native("CCompiler.compile") + def create_static_lib(*args, **kwargs): + chaquopy_block_native("CCompiler.create_static_lib") + def link(*args, **kwargs): + chaquopy_block_native("CCompiler.link") + + # To maximize the chance of the build getting as far as actually calling compile(), make + # sure the class has all of the expected attributes. + for name in ["src_extensions", "obj_extension", "static_lib_extension", + "shared_lib_extension", "static_lib_format", "shared_lib_format", + "exe_extension"]: + setattr(DisabledCompiler, name, getattr(UnixCCompiler, name)) + DisabledCompiler.executables = {name: [CHAQUOPY_NATIVE_ERROR.replace(" ", "_")] + for name in UnixCCompiler.executables} + + disabled_mod_name = "distutils.disabledcompiler" + disabled_mod = types.ModuleType(disabled_mod_name) + disabled_mod.DisabledCompiler = DisabledCompiler + sys.modules[disabled_mod_name] = disabled_mod + + # Try to disable native builds for packages which don't use the distutils native build + # system at all (e.g. uwsgi), or only use it to wrap an external build script (e.g. pynacl). + for tool in ["ar", "as", "cc", "cxx", "ld"]: + os.environ[tool.upper()] = CHAQUOPY_NATIVE_ERROR.replace(" ", "_") + + +CHAQUOPY_NATIVE_ERROR = "Chaquopy cannot compile native code" + +def chaquopy_block_native(prefix): + # No need to give any more advice here: that will come from the higher-level code in pip. + from distutils.errors import DistutilsPlatformError + raise DistutilsPlatformError("{}: {}".format(prefix, CHAQUOPY_NATIVE_ERROR)) diff --git a/product/gradle-plugin/src/main/python/pip/_internal/build_env.py b/product/gradle-plugin/src/main/python/pip/_internal/build_env.py index a060ceea2ca..3601642e84f 100644 --- a/product/gradle-plugin/src/main/python/pip/_internal/build_env.py +++ b/product/gradle-plugin/src/main/python/pip/_internal/build_env.py @@ -104,6 +104,22 @@ def __init__(self): ''' ).format(system_sites=system_sites, lib_dirs=self._lib_dirs)) + # Chaquopy + from os.path import dirname, join + import shutil + # Copy chaquopy_monkey unconditionally, so we can import it unconditionally in + # check_chaquopy_exception. + shutil.copy(join(dirname(pip_location), "../chaquopy_monkey.py"), + self._site_dir) + from pip._vendor.packaging import markers + if markers.python_version_info: + fp.write(textwrap.dedent( + ''' + import chaquopy_monkey + chaquopy_monkey.disable_native() + ''' + )) + def __enter__(self): self._save_env = { name: os.environ.get(name, None) diff --git a/product/gradle-plugin/src/main/python/pip/_internal/cli/cmdoptions.py b/product/gradle-plugin/src/main/python/pip/_internal/cli/cmdoptions.py index 244c9f993b2..67995390776 100644 --- a/product/gradle-plugin/src/main/python/pip/_internal/cli/cmdoptions.py +++ b/product/gradle-plugin/src/main/python/pip/_internal/cli/cmdoptions.py @@ -111,7 +111,7 @@ def check_dist_restriction(options, check_target=False): # guaranteed to be locally compatible. # # Chaquopy: added False to disable this restriction. It's safe for us to run source - # distributions, because we monkey-patch setuptools to ensure they fail immediately if they + # distributions, because chaquopy_monkey ensures they fail immediately if they # try to build anything native. if False and dist_restriction_set and sdist_dependencies_allowed: raise CommandError( diff --git a/product/gradle-plugin/src/main/python/pip/_internal/operations/prepare.py b/product/gradle-plugin/src/main/python/pip/_internal/operations/prepare.py index 6cf5f0edd68..216053de4be 100644 --- a/product/gradle-plugin/src/main/python/pip/_internal/operations/prepare.py +++ b/product/gradle-plugin/src/main/python/pip/_internal/operations/prepare.py @@ -211,9 +211,13 @@ def prepare_linked_requirement( ) abstract_dist = make_distribution_for_install_requirement(req) with self.req_tracker.track(req): - abstract_dist.prepare_distribution_metadata( - finder, self.build_isolation, - ) + try: + abstract_dist.prepare_distribution_metadata( + finder, self.build_isolation, + ) + except InstallationError: + abstract_dist.req.chaquopy_setup_py_failed() + if self._download_should_save: # Make a .zip of the source_dir we already created. if not req.link.is_artifact: diff --git a/product/gradle-plugin/src/main/python/pip/_internal/req/req_install.py b/product/gradle-plugin/src/main/python/pip/_internal/req/req_install.py index 9810eb43508..ce5b2c3424b 100644 --- a/product/gradle-plugin/src/main/python/pip/_internal/req/req_install.py +++ b/product/gradle-plugin/src/main/python/pip/_internal/req/req_install.py @@ -623,14 +623,10 @@ def run_egg_info(self): ensure_dir(egg_info_dir) egg_base_option = ['--egg-base', 'pip-egg-info'] with self.build_env: - try: - call_subprocess( - egg_info_cmd + egg_base_option, - cwd=self.setup_py_dir, - command_desc='python setup.py egg_info') - except InstallationError as exc: - self.chaquopy_setup_py_failed(exc) - + call_subprocess( + egg_info_cmd + egg_base_option, + cwd=self.setup_py_dir, + command_desc='python setup.py egg_info') @property def egg_info_path(self): @@ -1006,7 +1002,7 @@ def prepend_root(path): with open(inst_files_path, 'w') as f: f.write('\n'.join(new_lines) + '\n') - def chaquopy_setup_py_failed(self, exc): + def chaquopy_setup_py_failed(self): from pip._internal.exceptions import CommandError # {} may be a long URL, hence the newline. message = ("Failed to install {}.\nFor assistance, please raise an issue " @@ -1019,7 +1015,6 @@ def chaquopy_setup_py_failed(self, exc): if wheel_versions: message += ("\nOr try using one of the following versions, which are available " "as pre-built wheels: {}.".format(wheel_versions)) - logger.critical(str(exc)) raise CommandError(message) def get_install_args( diff --git a/product/gradle-plugin/src/main/python/pip/_internal/utils/setuptools_build.py b/product/gradle-plugin/src/main/python/pip/_internal/utils/setuptools_build.py index 01aa6a57c20..1e002fb797c 100644 --- a/product/gradle-plugin/src/main/python/pip/_internal/utils/setuptools_build.py +++ b/product/gradle-plugin/src/main/python/pip/_internal/utils/setuptools_build.py @@ -13,6 +13,7 @@ # warning: "warning: manifest_maker: standard file '-c' not found". _SETUPTOOLS_SHIM = ( "import sys, setuptools, tokenize; sys.argv[0] = {0!r}; __file__={0!r};" + "{chaquopy_monkey};" "f=getattr(tokenize, 'open', open)(__file__);" "code=f.read().replace('\\r\\n', '\\n');" "f.close();" @@ -36,8 +37,15 @@ def make_setuptools_shim_args(setup_py_path, unbuffered_output=False): # Chaquopy: added '-S' to avoid interference from site-packages. This makes # non-installable packages fail more quickly and consistently. Also, some packages # (e.g. Cython) install distutils hooks which can interfere with our attempts to - # disable compilers in setuptools/monkey.py. + # disable compilers in chaquopy_monkey. args.append('-S') - args.extend(['-c', _SETUPTOOLS_SHIM.format(setup_py_path)]) + from pip._vendor.packaging import markers + chaquopy_monkey = ( + "import chaquopy_monkey; chaquopy_monkey.disable_native()" + if markers.python_version_info + else "pass" + ) + args.extend(['-c', _SETUPTOOLS_SHIM.format(setup_py_path, + chaquopy_monkey=chaquopy_monkey)]) return args diff --git a/product/gradle-plugin/src/main/python/pip/_internal/wheel.py b/product/gradle-plugin/src/main/python/pip/_internal/wheel.py index 5f9401bfd6e..488a907a69c 100644 --- a/product/gradle-plugin/src/main/python/pip/_internal/wheel.py +++ b/product/gradle-plugin/src/main/python/pip/_internal/wheel.py @@ -921,7 +921,9 @@ def _build_one_inside_env(self, req, output_dir, python_tag=None): except Exception: pass # Ignore return, we can't do anything else useful. - self._clean_one(req) + # Chaquopy: backport from https://github.com/pypa/pip/pull/7477 + if not req.use_pep517: + self._clean_one_legacy(req) return None def _base_setup_args(self, req): @@ -963,6 +965,7 @@ def _build_one_pep517(self, req, tempd, python_tag=None): # Reassign to simplify the return at the end of function wheel_name = new_name except Exception: + self.check_chaquopy_exception(req) logger.error('Failed building wheel for %s', req.name) return None return os.path.join(tempd, wheel_name) @@ -988,20 +991,7 @@ def _build_one_legacy(self, req, tempd, python_tag=None): spinner=spinner) except Exception: spinner.finish("error") - - # Chaquopy: if `bdist_wheel` failed because of native code, don't fall back on - # `install` because it'll definitely fail, wasting the user's time and making - # the failure message harder to read. But if `bdist_wheel` failed for some - # other reason, then it's still worth trying `install` (#5630). - # - # The error message may use spaces or underscores (see - # setuptools.monkey.disable_native). - from setuptools.monkey import CHAQUOPY_NATIVE_ERROR - exc = sys.exc_info()[1] - if isinstance(exc, InstallationError) and \ - re.search(CHAQUOPY_NATIVE_ERROR.replace(" ", "."), exc.output): - req.chaquopy_setup_py_failed(exc) - + self.check_chaquopy_exception(req) logger.error('Failed building wheel for %s', req.name) return None names = os.listdir(tempd) @@ -1014,7 +1004,21 @@ def _build_one_legacy(self, req, tempd, python_tag=None): ) return wheel_path - def _clean_one(self, req): + def check_chaquopy_exception(self, req): + # If `bdist_wheel` failed because of native code, don't fall back on `install` + # because it'll definitely fail, wasting the user's time and making the failure + # message harder to read. But if `bdist_wheel` failed for some other reason, then + # it's still worth trying `install` (#5630). + # + # The error message may use spaces or underscores (see + # chaquopy_monkey.disable_native). + from chaquopy_monkey import CHAQUOPY_NATIVE_ERROR + exc = sys.exc_info()[1] + if isinstance(exc, InstallationError) and \ + re.search(CHAQUOPY_NATIVE_ERROR.replace(" ", "."), exc.output): + req.chaquopy_setup_py_failed() + + def _clean_one_legacy(self, req): base_args = self._base_setup_args(req) logger.info('Running setup.py clean for %s', req.name) diff --git a/product/gradle-plugin/src/main/python/setuptools/monkey.py b/product/gradle-plugin/src/main/python/setuptools/monkey.py index f735535d75d..3c77f8cf27f 100644 --- a/product/gradle-plugin/src/main/python/setuptools/monkey.py +++ b/product/gradle-plugin/src/main/python/setuptools/monkey.py @@ -98,91 +98,7 @@ def patch_all(): setuptools.extension.Extension ) - # Chaquopy disabled: importing distutils.msvc9compiler causes exception "not supported by - # this module" on MSYS2 Python, because it isn't built with MSVC. - # patch_for_msvc_specialized_compiler() - - disable_native() - - -# Chaquopy: We want to cause a quick and comprehensible failure when a package attempts to -# build native code, while still allowing a pure-Python fallback if available. This is tricky, -# because different packages have different approaches to pure-Python fallbacks: -# -# * Some packages simply catch any distutils exception thrown by setup(), and then run it again -# with the native components removed. -# -# * Some (e.g. sqlalchemy, wrapt) extend the distutils build_ext or build_clib command and -# override its run() method to wrap it with an exception handler. This means we can't simply -# block the commands by name, e.g. by overriding Distribution.run_command. -# -# * Some (e.g. msgpack) go lower-level and catch exceptions in build_ext.build_extension. In -# Python 3, there's an `optional` keyword to Extension which has the same effect (used e.g. -# by websockets). Blocking build_ext.run, or CCompiler.__init__, would cause these builds to -# fail before build_extension is called, and the pure-Python fallback wouldn't happen. -# -# Creating a new compiler class with a new name minimizes the chance of code trying to do -# things which will only work on the standard classses. For example, -# distutils.sysconfig.customize_compiler does things with a "unix" compiler which will crash on -# Windows because get_config_vars won't have certain settings. -# -# This is simpler than determining the regular compiler class and extending it. It avoids -# interference from NumPy's widespread monkey-patching (including new_compiler, CCompiler and -# its subclasses), which takes place after this code is run. It also avoids the default -# behaviour on Windows when no compiler is installed, which is either to give the "Unable to -# find vcvarsall.bat" error, or advice on how to install Visual C++, both of which will waste -# the user's time. -# -# This approach will block builds of packages which require the compiler name to be in a known -# list (e.g. minorminer, lz4), but the error messages from these packages aren't too bad, and -# I've never seen one which has a pure-Python fallback. -def disable_native(): - from distutils import ccompiler - from distutils.unixccompiler import UnixCCompiler - import os - import types - - ccompiler.get_default_compiler = lambda *args, **kwargs: "disabled" - ccompiler.compiler_class["disabled"] = ( - "disabledcompiler", "DisabledCompiler", - "Compiler disabled ({})".format(CHAQUOPY_NATIVE_ERROR)) - - class DisabledCompiler(ccompiler.CCompiler): - compiler_type = "disabled" - def preprocess(*args, **kwargs): - chaquopy_block_native("CCompiler.preprocess") - def compile(*args, **kwargs): - chaquopy_block_native("CCompiler.compile") - def create_static_lib(*args, **kwargs): - chaquopy_block_native("CCompiler.create_static_lib") - def link(*args, **kwargs): - chaquopy_block_native("CCompiler.link") - - # To maximize the chance of the build getting as far as actually calling compile(), make - # sure the class has all of the expected attributes. - for name in ["src_extensions", "obj_extension", "static_lib_extension", - "shared_lib_extension", "static_lib_format", "shared_lib_format", - "exe_extension"]: - setattr(DisabledCompiler, name, getattr(UnixCCompiler, name)) - DisabledCompiler.executables = {name: [CHAQUOPY_NATIVE_ERROR.replace(" ", "_")] - for name in UnixCCompiler.executables} - - disabled_mod = types.ModuleType("distutils.disabledcompiler") - disabled_mod.DisabledCompiler = DisabledCompiler - sys.modules["distutils.disabledcompiler"] = disabled_mod - - # Try to disable native builds for packages which don't use the distutils native build - # system at all (e.g. uwsgi), or only use it to wrap an external build script (e.g. pynacl). - for tool in ["ar", "as", "cc", "cxx", "ld"]: - os.environ[tool.upper()] = CHAQUOPY_NATIVE_ERROR.replace(" ", "_") - - -CHAQUOPY_NATIVE_ERROR = "Chaquopy cannot compile native code" - -def chaquopy_block_native(prefix): - # No need to give any more advice here: that will come from the higher-level code in pip. - from distutils.errors import DistutilsPlatformError - raise DistutilsPlatformError("{}: {}".format(prefix, CHAQUOPY_NATIVE_ERROR)) + patch_for_msvc_specialized_compiler() def _patch_distribution_metadata(): diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/build.gradle b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/build.gradle index ad0436b8a80..3797573e361 100644 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/build.gradle +++ b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/build.gradle @@ -11,7 +11,7 @@ android { versionName "0.0.1" python { pip { - install "./sdist_pep517" + install "./pep517" } } ndk { diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/pep517/setup.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/pep517/setup.py new file mode 100644 index 00000000000..60e24e50de0 --- /dev/null +++ b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/pep517/setup.py @@ -0,0 +1,12 @@ +import setuptools +from setuptools import setup + +# See https://github.com/googleapis/python-crc32c/blob/main/tests/test___init__.py +import google_crc32c +assert google_crc32c.implementation == "c" +version = google_crc32c.value(b"\x00" * 32) + +setup( + name="pep517", + version=version, +) diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/sdist_pep517/sdist_pep517.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/sdist_pep517/sdist_pep517.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/sdist_pep517/setup.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/sdist_pep517/setup.py deleted file mode 100644 index 805e26e290b..00000000000 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/sdist_pep517/setup.py +++ /dev/null @@ -1,9 +0,0 @@ -import setuptools -from setuptools import setup - - -setup( - name="sdist_pep517", - version=setuptools.__version__, - py_modules=["sdist_pep517"], -) diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/build.gradle b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/build.gradle deleted file mode 100644 index ad0436b8a80..00000000000 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/build.gradle +++ /dev/null @@ -1,21 +0,0 @@ -apply plugin: 'com.android.application' -apply plugin: 'com.chaquo.python' - -android { - compileSdkVersion 23 - defaultConfig { - applicationId "com.chaquo.python.test" - minSdkVersion 21 - targetSdkVersion 23 - versionCode 1 - versionName "0.0.1" - python { - pip { - install "./sdist_pep517" - } - } - ndk { - abiFilters "x86" - } - } -} diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/pep517/pyproject.toml b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/pep517/pyproject.toml new file mode 100644 index 00000000000..f4a025bb27d --- /dev/null +++ b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/pep517/pyproject.toml @@ -0,0 +1,2 @@ +[build-system] +requires = ["setuptools", "wheel", "google-crc32c"] diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/pyproject.toml b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/pyproject.toml deleted file mode 100644 index 77e3cca19ea..00000000000 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/pyproject.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build-system] -requires = ["setuptools==40.8.0", "wheel"] diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/sdist_pep517.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/sdist_pep517.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/setup.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/setup.py deleted file mode 100644 index 805e26e290b..00000000000 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_default_backend/app/sdist_pep517/setup.py +++ /dev/null @@ -1,9 +0,0 @@ -import setuptools -from setuptools import setup - - -setup( - name="sdist_pep517", - version=setuptools.__version__, - py_modules=["sdist_pep517"], -) diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_explicit_backend/app/pep517/pyproject.toml b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_explicit_backend/app/pep517/pyproject.toml new file mode 100644 index 00000000000..7f1bf86d801 --- /dev/null +++ b/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517_explicit_backend/app/pep517/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "wheel", "google-crc32c"] +build-backend = "setuptools.build_meta" diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_cc/app/build.gradle b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_cc/app/build.gradle index a28cc6a57dc..7d570f71a7e 100644 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_cc/app/build.gradle +++ b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_cc/app/build.gradle @@ -11,7 +11,7 @@ android { versionName "0.0.1" python { pip { - install "sdist_native_cc-1.0.tar.gz" + install "./sdist_native" } } ndk { diff --git a/product/gradle-plugin/src/test/integration/packages/src/sdist_native_cc/setup.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_cc/app/sdist_native/setup.py similarity index 100% rename from product/gradle-plugin/src/test/integration/packages/src/sdist_native_cc/setup.py rename to product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_cc/app/sdist_native/setup.py diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_cc/app/sdist_native_cc-1.0.tar.gz b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_cc/app/sdist_native_cc-1.0.tar.gz deleted file mode 100644 index aabf0ca0496724b917d01b866815c92fb7390bb5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 824 zcmV-81IPRyiwFpwe<51}|72-%bT4ycX>)X6Zeet3c4c28Y%$M%3wWn4G4NbJaQ3iTlBjVHiH>e?M6EzaJ?PINJZujxR)_5t7LI zPDD;QYlDh_rqM$wX~R-*G>!X8gCb3lDBEz_JMQ&=^qR&;o)RlVF*)Od;`~1%8DS&Ba5+pUyUcBQEjN(=9ml=zf6otsQ0M<`Kqp3>|5xV! z6AQz&>p#y49bfbRWz>IG9SD}L|6V=+2mRBp-NV6(*Z#`<_gbwb{;Lwk^E!vEQwfXDHM z=6IC{m_e1^v&sH!NJcXIVCFe;FG|jk>wWMjxTV-Bl06GS97B40+E`hSD!$u;W zwwneh?7)DgMN%aV1R27YC?;?APNR@LICqLqX`i(qJm(Vl>2Z+<%Aa! zVoq7Clmsv0$=q@^Zy~8#B9efT#I8GTR><>v&AhnC1ji)55#LVMQJOYkQz|&KVMx|{oT=d}K=(=iqOE7_h-_Zk`+8X6k^F@6HwRy1$`C;$L* C-Ipc+ diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/build.gradle b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/build.gradle index 3aa7a96b1a3..7d570f71a7e 100644 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/build.gradle +++ b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/build.gradle @@ -11,7 +11,7 @@ android { versionName "0.0.1" python { pip { - install "sdist_native_clib-1.0.tar.gz" + install "./sdist_native" } } ndk { diff --git a/product/gradle-plugin/src/test/integration/packages/src/sdist_native_clib/libtest.c b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/sdist_native/libtest.c similarity index 100% rename from product/gradle-plugin/src/test/integration/packages/src/sdist_native_clib/libtest.c rename to product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/sdist_native/libtest.c diff --git a/product/gradle-plugin/src/test/integration/packages/src/sdist_native_clib/setup.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/sdist_native/setup.py similarity index 100% rename from product/gradle-plugin/src/test/integration/packages/src/sdist_native_clib/setup.py rename to product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/sdist_native/setup.py diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/sdist_native_clib-1.0.tar.gz b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_clib/app/sdist_native_clib-1.0.tar.gz deleted file mode 100644 index 5f0e5820979546496626dcc2bde91a5fa57a49da..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 721 zcmV;?0xta@iwFoT;|p5?|72-%bT4ycX>)X6Zeet3c4c2N>Z0Cw__&4+s=P(S6LT8&C~)1C3(@AvQI-;ews{Kre;JwK)a7I=pLzm8rH zMiK;K1`}BU6LUzV&?xi(^d$lp^nUUj%1WlF6sSvC=b3n-0cR*+iW-=L3B5vUDr6ZK zQyR#r#&hg;Y|G&B>HqlfmHTG&^2lmM|6v^5^8YAELZkmS@D4T0m}c%rtQ41G0K|XC z9Y`xPd;q7T!_m>FQOABQ3v^31#YXK}tuJM@R&cRkJa3fW@)U(? zj(ma;CiReR;cT;Th8qb z%-`N@g4kQ;$X{KrWjW4qhWR!#&tT{JzXuQ7=l{@4jQ&mjH~3fjUw#YH$#f_8_^tle z_J3o~kBt7?z!@3)cwy}49b2>M_@d@{218h#(aHengp$6=&;OtP%emEx{weKW{r@H5 zCyW0-iD&fR3MQ2-U`e-@GFQNhQdW9ZS*U(_@U&wCL9hac&f1J|_E+7r)z-k!p&4{l zqwb1T9M$mbsk2yUIQ#I`QL?U5RL%g-oa+UMbN+3QOlZ$Ije&uIK^yoEsZg$j04M+e D=XQUy diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_compiler/app/build.gradle b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_compiler/app/build.gradle index 500995e2414..7d570f71a7e 100644 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_compiler/app/build.gradle +++ b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_compiler/app/build.gradle @@ -11,7 +11,7 @@ android { versionName "0.0.1" python { pip { - install "sdist_native_compiler-1.0.tar.gz" + install "./sdist_native" } } ndk { diff --git a/product/gradle-plugin/src/test/integration/packages/src/sdist_native_compiler/setup.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_compiler/app/sdist_native/setup.py similarity index 100% rename from product/gradle-plugin/src/test/integration/packages/src/sdist_native_compiler/setup.py rename to product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_compiler/app/sdist_native/setup.py diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_compiler/app/sdist_native_compiler-1.0.tar.gz b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_compiler/app/sdist_native_compiler-1.0.tar.gz deleted file mode 100644 index 4b227c88e05de68e93084321bee51af2487e8432..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 784 zcmV+r1MmDFiwFoLS1wxu|72-%bT4ycX>)X6Zeet3c4c2*oY$Q%X0e z3hOkVm&Df}v3>73xpCx(NgQ&5Y)XfrNKzKl%ycaKp!RIA6*`?xc~w}wmiJD(?X*3= z?Rj3!c09Wi)WEOp0l7qy0X)khtBdG22iQ~&+R^Y}jqf=B(|_JbAw`;H11 zu(khpjxQ9+h#)b)(@ZkKyP$kuH~J)@U053&b>n{1L7pTen|0x=f80O$(XSgHMMBM# zM6_aio8v@e4-6(v2#YJ`&n%=|R(l>%8D=a+^+fYfaHJf~Z?p7~CKc;xOmHl+q++UR zY|Q_)H5QE`lku@Q*peDs>A&kbzSjSj?f(%?DIZZD&W17LSJJ{8e4_r_wzJ~@z;!*X z|NDTJM6Lf%;{O)u;nw+|+jf1O|Gkj>&zy&Vsq;V0{|f&HCud&|-wl5A+TWP}ZpT~U zzh`^C=Ko&&PccuebY^TQ_r~U7VLTy&{8Jwk=`f~K8gCMJ8aw3w7M|EX|MvoY{-g7M zjlatO^34#Aqn)4s+P=Gb{@Zc%_y1mSt^|Ep2>M0cKoSiva~6-F2lJBpGN7uUvV5I8 z|DXI%XSJR4zvKJ2{8wN81^)v_=l^@bI1>pJF_0sRr6p%F6nxAgU`Z-6gi!5|NZ8Nn z|DUo?86GG^ESF77OWjzOX0lKXHikwSV-4T}f$^fkB3U%;)(ud21p}7kaUnDWQW9Q~ zh{E-Rg%iMxQ3)s@%Q@hL!g305&2S=egh((Rsj5um(PTMZDPco;gCMd+A&l9jHLqVx z?{3NA-NK6c+h_FFwXrz8zTJstYtiMw9yOOYt^0#oi<{!`C;$MMRf+Nd diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/build.gradle b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/build.gradle index 3a553417d83..7d570f71a7e 100644 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/build.gradle +++ b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/build.gradle @@ -11,7 +11,7 @@ android { versionName "0.0.1" python { pip { - install "sdist_native_ext-1.0.tar.gz" + install "./sdist_native" } } ndk { diff --git a/product/gradle-plugin/src/test/integration/packages/src/sdist_native_ext/ext_module.c b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/sdist_native/ext_module.c similarity index 100% rename from product/gradle-plugin/src/test/integration/packages/src/sdist_native_ext/ext_module.c rename to product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/sdist_native/ext_module.c diff --git a/product/gradle-plugin/src/test/integration/packages/src/sdist_native_ext/setup.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/sdist_native/setup.py similarity index 100% rename from product/gradle-plugin/src/test/integration/packages/src/sdist_native_ext/setup.py rename to product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/sdist_native/setup.py diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/sdist_native_ext-1.0.tar.gz b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_ext/app/sdist_native_ext-1.0.tar.gz deleted file mode 100644 index 4800d06d7e570b28f8c965fd472e11bf62f7e386..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 733 zcmV<30wVn%iwFqx)(cw#|72-%bT4ycX>)X6Zeet3c4c2>cyui>E-)^1VR8WNnO#rY zFcgM+9jX7}C^rMCY4aVaQZFXPKEzhg7~2Ixk(ZnXi^Ps%x1#@kZmU5E16r0vp!vOV za_T5b&Us!Rry`|7#*9e1z!({>-bla&GRRN@5inD)Pz@E5 zl(I}+NL7rg^648rtyjnY$nudMx|Z%C5GKj$=0VFH^owKG6v6Am&;x^{JV`E{}RXfQEVZT*hj?mNWf{N`?Z=55>@z`0r9o|qT=%B1$S6KQE_ PX|N!I$CPRVNhjtUJpD+pLUgi{QnkDL@dw7CuslsHP zlWQKl61^>s}frCowlu*_2bVWuC+-mHDzk9j)qK5nF%d z`WYKvnQolE|MTIi*;{pc%9^apw#|DQ_)0z^Wxiqq6YLd3Er*~=8 z+hjN6)z>DqxmkW&!xrwfiNmWuMN(#y{O2`)Z#G_=RJt;K_NV;j2h-Nn^*-ILXm07b zEHrl3shUpu#|*sfwc?6YWY%)HiU?$&M&R*9qlH8HQm-H*NJIa=_4Sht0L3kQ>% zqPXK zd(oQN)*p^f+jjZU zNnO{SEURM=zSuG4Xq{|m9_QT3lnYIkR+o||q%0P&X;)WOt(a!?8kqC!o^q79R_MnVyQOz5uFjH@f3vRa|G_t(b#8oM z4e(}U5@EodpuwpDNNj5avGB(?O7ccF7+dN>7<`5}gYnx9Od!ZMVoPfX8x4Rd5WjI? XufS4XfHx}}NHa4KssOc~2j>z1C)0r~ diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/build.gradle b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/build.gradle index 5b74019e7b0..7d570f71a7e 100644 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/build.gradle +++ b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/build.gradle @@ -11,7 +11,7 @@ android { versionName "0.0.1" python { pip { - install "sdist_native_optional_ext-1.0.zip" + install "./sdist_native" } } ndk { diff --git a/product/gradle-plugin/src/test/integration/packages/src/sdist_native_optional_ext/ext_module.c b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/sdist_native/ext_module.c similarity index 100% rename from product/gradle-plugin/src/test/integration/packages/src/sdist_native_optional_ext/ext_module.c rename to product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/sdist_native/ext_module.c diff --git a/product/gradle-plugin/src/test/integration/packages/src/sdist_native_optional_ext/sdist_native_optional_ext.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/sdist_native/sdist_native_optional_ext.py similarity index 100% rename from product/gradle-plugin/src/test/integration/packages/src/sdist_native_optional_ext/sdist_native_optional_ext.py rename to product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/sdist_native/sdist_native_optional_ext.py diff --git a/product/gradle-plugin/src/test/integration/packages/src/sdist_native_optional_ext/setup.py b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/sdist_native/setup.py similarity index 100% rename from product/gradle-plugin/src/test/integration/packages/src/sdist_native_optional_ext/setup.py rename to product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/sdist_native/setup.py diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/sdist_native_optional_ext-1.0.zip b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_optional_ext/app/sdist_native_optional_ext-1.0.zip deleted file mode 100644 index a94dd4fbb82d5c16197ef6cad2e05f558c02ca54..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1332 zcmWIWW@Zs#U|`^2I32miCn_b6FBHg21Y#{9E>6iTE{V@eEXgcOjn6MA$;{77%!yB} zDA6_4GtdXp@wxdar8%j3$)cwXxf%=vTrS3a;JbV?^S$Dp!%4?f1j%V--s-M!Y)3+AN zwTlP99e1wsx{vazIr|!cjyey-Y6Kk@;O(yK>F4I3dTt{Zlc5011-l9LC-_~q_?9Oq zt_T#^%5(beD(;(4JihV$tv;%i^gE3$t)GdR;|BLMFH6hKQ94^c9eCj*yTZ#u!6f;_ z;+mok#`%k`=KnP@bgr~4{uW)oqiU_$%!_>m$B*sul-v2I(Uq->_x+0FA-A7OWyim$ zUT`s)W#`jFyn7iDo;U;a1kl|KOdtXXtbiDQ2;-F1E2v~ev%&x!>k4+^egoamhk#qG^(fwc*nL zdly&iy?6dq%Gu+yzu!B-8_a&}*cJ8HNozX=bHqD@@5BoI$~c*?ko3wq(nP;|;!KNk zPwzkfu{U_7;=6Z6yL9et$$Vw?)VKDe-Xh6WI(7&3T|P_+ zQ2X5(sZ{jQ+x=flvg|Rby6s_`1cSOCyy!8!Yaw&tr0Z&xNe`YsXIv_2J12T|bbzF# zMs1LLi}7lKhdGmv*gkMg-eI=Y>9*qYok!g4gd7v3);I`&A#D=KqMx~MR~wceu#FX87Beq4cbU;gg~>O{I^i)zxqQUyp3vReOBr{(fG|YZG6}9(#NEvizo1(<-($wx?f@3g7+p-A3yk@6Yud z?@u}L{9+IAW@Hj!z@2Zw$qPtq1LYS2X$(0RBb$pY%OT92OVC_c21GU!TMj^&nFLI| tI8!{h#K9>GOv%XhV9O5(d-f2v2bwzqyjj^m`dEN41E^~oFmEw1006gm1r-1Q diff --git a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/sdist_pep517/pyproject.toml b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_pep517/app/sdist_native/pyproject.toml similarity index 56% rename from product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/sdist_pep517/pyproject.toml rename to product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_pep517/app/sdist_native/pyproject.toml index 746c0a69ff0..9787c3bdf00 100644 --- a/product/gradle-plugin/src/test/integration/data/PythonReqs/pep517/app/sdist_pep517/pyproject.toml +++ b/product/gradle-plugin/src/test/integration/data/PythonReqs/sdist_native_pep517/app/sdist_native/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools==40.8.0", "wheel"] +requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" diff --git a/product/gradle-plugin/src/test/integration/packages/README.txt b/product/gradle-plugin/src/test/integration/packages/README.txt index 1043c449a7f..972526779c4 100644 --- a/product/gradle-plugin/src/test/integration/packages/README.txt +++ b/product/gradle-plugin/src/test/integration/packages/README.txt @@ -7,3 +7,10 @@ commands in the src/ subdirectories: Some of the scripts require extra arguments: see comments. Some of the packages were then renamed to meet the needs of the tests. + +However, unless a test actually requires a package file, it's better to put the Python +source tree inside the test's own data directory, and install it like this: + + pip { + install "./dir_name" + } diff --git a/product/gradle-plugin/src/test/integration/test_gradle_plugin.py b/product/gradle-plugin/src/test/integration/test_gradle_plugin.py index e75effb1c1a..2cef960e02b 100644 --- a/product/gradle-plugin/src/test/integration/test_gradle_plugin.py +++ b/product/gradle-plugin/src/test/integration/test_gradle_plugin.py @@ -888,16 +888,16 @@ def test_wheel_data(self): def test_sdist_file(self): self.RunGradle("base", "PythonReqs/sdist_file", requirements=["alpha_dep/__init__.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. + # These tests install a package with a native build requirement in its pyproject.toml, + # which is used to generate the package's version number. This verifies that the build + # environment is installed for the build platform, not the target platform. def test_pep517_default_backend(self): - self.RunGradle("base", "PythonReqs/pep517", requirements=["sdist_pep517.py"], - dist_versions=[("sdist_pep517", "40.8.0")]) + self.RunGradle("base", "PythonReqs/pep517", "PythonReqs/pep517_default_backend", + dist_versions=[("pep517", "2324772522")]) + + def test_pep517_explicit_backend(self): + self.RunGradle("base", "PythonReqs/pep517", "PythonReqs/pep517_explicit_backend", + dist_versions=[("pep517", "2324772522")]) # Make sure we're not affected by a setup.cfg file containing a `prefix` line. def test_cfg_wheel(self): @@ -915,13 +915,25 @@ def test_cfg_sdist(self): # can use the absence of the string in other tests to prove that no fallback occurred. RUNNING_INSTALL = "Running setup.py install" - def test_sdist_native(self): - run = self.RunGradle("base", run=False) - for name in ["sdist_native_ext", "sdist_native_clib", "sdist_native_compiler", - "sdist_native_cc"]: - with self.subTest(name=name): - run.apply_layers(f"PythonReqs/{name}") - run.rerun(succeed=False) + def test_sdist_native_ext(self): + self.sdist_native("sdist_native_ext") + + def test_sdist_native_clib(self): + self.sdist_native("sdist_native_clib") + + def test_sdist_native_compiler(self): + self.sdist_native("sdist_native_compiler") + + def test_sdist_native_cc(self): + self.sdist_native("sdist_native_cc") + + def sdist_native(self, name): + for pep517 in [True, False]: + with self.subTest(pep517=pep517): + layers = ["base", f"PythonReqs/{name}"] + if pep517: + layers.append("PythonReqs/sdist_native_pep517") + run = self.RunGradle(*layers, succeed=False) if name == "sdist_native_cc": setup_error = "Failed to run Chaquopy_cannot_compile_native_code" @@ -933,7 +945,7 @@ def test_sdist_native(self): # setup.py install. self.assertNotInLong(self.RUNNING_INSTALL, run.stdout) - url = fr"file:.*app/{name}-1.0.tar.gz" + url = r"file:.*app/sdist_native" if name in ["sdist_native_compiler", "sdist_native_cc"]: # These tests fail at the egg_info stage, so the name and version are # unavailable. @@ -945,12 +957,19 @@ def test_sdist_native(self): self.assertInLong(fr"Failed to install {req_str}." + self.tracker_advice() + r"$", run.stderr, re=True) - def test_sdist_native_optional(self): - run = self.RunGradle("base", run=False) - for name in ["sdist_native_optional_ext", "sdist_native_optional_compiler"]: - with self.subTest(name=name): - run.apply_layers(f"PythonReqs/{name}") - run.rerun(requirements=[f"{name}.py"]) + def test_sdist_native_optional_ext(self): + self.sdist_native_optional("sdist_native_optional_ext") + + def test_sdist_native_optional_compiler(self): + self.sdist_native_optional("sdist_native_optional_compiler") + + def sdist_native_optional(self, name): + for pep517 in [True, False]: + with self.subTest(pep517=pep517): + layers = ["base", f"PythonReqs/{name}"] + if pep517: + layers.append("PythonReqs/sdist_native_pep517") + self.RunGradle(*layers, requirements=[f"{name}.py"]) # If bdist_wheel fails without a "native code" message, we should fall back on setup.py # install. For example, see acoustics==0.2.4 (#5630).