-
Notifications
You must be signed in to change notification settings - Fork 48
Fix Python Problems when using pip --no-build-isolation #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Python Problems when using pip --no-build-isolation #73
Conversation
ee03cc9 to
aa18c32
Compare
setuptools v77 changed the format of the "license" field, without giving it a new name, making it a breaking change. A SPDX string is illegal according to setuptools v76 and lower, while the deprecated table format is illegal according to setuptools v77 and later. This makes it difficult for users to build packages using "--no-build-isolation", since most systems are still shipping earlier setuptools. Define "license" or "license_expression" in setup.py instead, and mark the "license" in pyproject.toml as "dynamic". This is the recommended solution in [1]. [1] pypa/setuptools#4903 Signed-off-by: Yifeng Li <tomli@tomli.me>
If "bootstrap/setuptools_build_meta_custom.py" fails because user has disabled build isolation in preference to a system-package build and the setuptools package is missing, the error message is difficult to understand. Raise our own RuntimeError instead. Signed-off-by: Yifeng Li <tomli@tomli.me>
The original setuptools_scm handling had compatibility problems under "pip --no-build-isolation". Because the "version_file" attribute was unsupported before setuptools_scm v8, pip crashes. In "--no-build-isolation" mode, pip uses existing packages without any check, so "setuptools_scm" cannot be disabled by us by any means (even if we know it's broken). setuptools_scm documentation suggests that new code should obtain package version via "importlib.metadata.version()", the "version_file" field is largely obsolete anyway. Thus, this commit changes the implementation to obtain the "__version__" string via "importlib" instead, the "__version__.py" file is removed. Instead, "__fallback_version__.py" is used if setuptools_scm fails, or if "importlib" is unsupported by the Python version installed. Signed-off-by: Yifeng Li <tomli@tomli.me>
The "Cython" package provided by macOS Homebrew is meant for building other Homebrew packages, so it's not available in the system's search path, making it useless. This commit adds Homebrew's Cython to the search path to simplify "pip --no-build-isolation" installation. Signed-off-by: Yifeng Li <tomli@tomli.me>
50be60f to
438081d
Compare
This commit tests CI/CD with "pip --no-build-isolation" to ensure this use case actually works. On Linux-based systems, we also create a fresh network namespace without any network adapters, to ensure that "--no-build-isolation" fulfils its intended purpose of installing Python pip packages even without network access. Signed-off-by: Yifeng Li <tomli@tomli.me>
438081d to
4ec5f90
Compare
|
Merge ready, together with thliebig/openEMS#200. Hopefully these patchsets will be the last refinement of the Python build process, which finally allows me to unblock openEMS-Projects's new Python workflow. Ignore the "AlmaLinux Latest" test failure for now. It was caused by the broken VTK package in the Fedora EPEL repo. I've already reported the bug to the upstream. |
|
Thanks for all your effort @biergaizi but at the same time the amount of work required to get this pip workflow running seems a bit scary? I really have no idea what all the issues and problems are you are/were fighting... |
|
If one wants to support only the latest systems running cutting-edge pip and Python, 50% of the code in The work's focus was to add additional logic into The GitHub CI script also wants developers to run the same commands on all systems, rather than running a separate workaround for each system. If one has to code the workaround anyway, writing it directly to [1] I wanted to say 80%, but I realized that it would be false. The |
Introduction
The current design of the Python extension allows the use of
--no-build-isolationto bypass Python's own package management for several purposes, for example, it's suggested as the solution if pip cannot find the build-time dependency successfully, or if no network access to PyPI is available.However, after further testing during the development of a new build script for openEMS-Project, it was discovered that
--no-build-isolationdoes not actually work on many systems due to several problems.This Pull Request introduces fixes to these problems.
On Linux-based systems, we also create a fresh network namespace without any network adapters, to create a severe test to ensure
--no-build-isolationfulfills its intended purpose of installing Python pip packages, even without network access to PyPI.Commits
python: define license_expression in setup.py instead.
setuptools v77 changed the format of the "license" field, without giving it a new name, making it a breaking change. A SPDX string is illegal according to setuptools v76 and lower, while the deprecated table format is illegal according to setuptools v77 and later.
This makes it difficult for users to build packages using
--no-build-isolation, since most systems are still shipping earlier setuptools. Definelicenseorlicense_expressionin setup.py instead, and mark thelicensein pyproject.toml asdynamic[1].See:
project.licensedeprecation if v77 unavailable pypa/setuptools#4903python/bootstrap: raise a custom RuntimeError
If
bootstrap/setuptools_build_meta_custom.pyfails because user has disabled build isolation in preference to a system-package build and the setuptools package is missing, the error message is difficult to understand. Raise our own RuntimeError instead.python: improve setuptools_scm handling
The original setuptools_scm handling had compatibility problems under
pip --no-build-isolation. Because theversion_fileattribute was unsupported before setuptools_scm v8, pip crashes. In--no-build-isolationmode, pip uses existing packages without any check, sosetuptools_scmcannot be disabled by us by any means (even if we know it's broken).setuptools_scm documentation suggests that new code should obtain package version via
importlib.metadata.version(), theversion_filefield is largely obsolete anyway. Thus, this commit changes the implementation to obtain the__version__string viaimportlibinstead, the__version__.pyfile is removed. Instead,__fallback_version__.pyis used if setuptools_scm fails, or ifimportlibis unsupported by the Python version installed.python: add Cython to sys search path on macOS
The
Cythonpackage provided by macOS Homebrew is meant for building other Homebrew packages, so it's not available in the system's search path, making it useless. This commit adds Homebrew's Cython to thesearch path to simplify
pip --no-build-isolationinstallation.CI: Test pip --no-build-isolation
This commit tests CI/CD with
pip --no-build-isolationto ensure this use case actually works. On Linux-based systems, we also create a fresh network namespace without any network adapters, to ensure that--no-build-isolationfulfills its intended purpose of installing Python pip packages even without network access.