From 290941c5f31487c8c4c08c9273770389f92c208e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 6 Oct 2020 00:30:45 +0200 Subject: [PATCH] Support PEP 517 list based backend-path The PEP 517 shows an example backend-path like this: [build-system] # Defined by PEP 518: requires = ["flit"] # Defined by this PEP: build-backend = "local_backend" backend-path = ["backend"] https://www.python.org/dev/peps/pep-0517/#source-trees See that backend-path is a list. Our code previously only supported string path. Obviously a string path is wrong, but we keep it to support projects that have made the mistake, such as flit-core. Add a small integration test for both cases. Note that the new spec files deliberately don't do much, to save CI time. --- pyproject-rpm-macros.spec | 5 +++- pyproject_buildrequires.py | 5 +++- tests/python-flit-core.spec | 43 +++++++++++++++++++++++++++++++++ tests/python-poetry-core.spec | 45 +++++++++++++++++++++++++++++++++++ tests/tests.yml | 6 +++++ 5 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 tests/python-flit-core.spec create mode 100644 tests/python-poetry-core.spec diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index f6617f1..1c9e5fa 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -6,7 +6,7 @@ License: MIT # Keep the version at zero and increment only release Version: 0 -Release: 30%{?dist} +Release: 31%{?dist} # Macro files Source001: macros.pyproject @@ -94,6 +94,9 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856 %license LICENSE %changelog +* Mon Oct 05 2020 Miro Hrončok - 0-31 +- Support PEP 517 list based backend-path + * Tue Sep 29 2020 Lumír Balhar - 0-30 - Process RECORD files in %%pyproject_install and remove them - Support the extras configuration option of tox in %%pyproject_buildrequires -t diff --git a/pyproject_buildrequires.py b/pyproject_buildrequires.py index a34c9e2..4946240 100644 --- a/pyproject_buildrequires.py +++ b/pyproject_buildrequires.py @@ -185,7 +185,10 @@ def get_backend(requirements): backend_path = buildsystem_data.get('backend-path') if backend_path: - sys.path.insert(0, backend_path) + # PEP 517 example shows the path as a list, but some projects don't follow that + if isinstance(backend_path, str): + backend_path = [backend_path] + sys.path = backend_path + sys.path module_name, _, object_name = backend_name.partition(":") backend_module = importlib.import_module(module_name) diff --git a/tests/python-flit-core.spec b/tests/python-flit-core.spec new file mode 100644 index 0000000..45df12b --- /dev/null +++ b/tests/python-flit-core.spec @@ -0,0 +1,43 @@ +Name: python-flit-core +Version: 3.0.0 +Release: 0%{?dist} +Summary: Distribution-building parts of Flit + +License: BSD +URL: https://pypi.org/project/flit-core/ +Source0: %{pypi_source flit_core} + +BuildArch: noarch +BuildRequires: python3-devel +BuildRequires: pyproject-rpm-macros + +%description +Test a build with pyproject.toml backend-path = . +flit-core builds with flit-core. + + +%package -n python3-flit-core +Summary: %{summary} + +%description -n python3-flit-core +... + + +%prep +%autosetup -p1 -n flit_core-%{version} + + +%generate_buildrequires +%pyproject_buildrequires + + +%build +%pyproject_wheel + + +%install +%pyproject_install +%pyproject_save_files flit_core + + +%files -n python3-flit-core -f %{pyproject_files} diff --git a/tests/python-poetry-core.spec b/tests/python-poetry-core.spec new file mode 100644 index 0000000..5a5af4d --- /dev/null +++ b/tests/python-poetry-core.spec @@ -0,0 +1,45 @@ +Name: python-poetry-core +Version: 1.0.0 +Release: 0%{?dist} +Summary: Poetry PEP 517 Build Backend + +License: MIT +URL: https://pypi.org/project/poetry-core/ +Source0: %{pypi_source poetry-core} + +BuildArch: noarch +BuildRequires: python3-devel +BuildRequires: pyproject-rpm-macros + +%description +Test a build with pyproject.toml backend-path = [.] +poetry-core builds with poetry-core. + + +%package -n python3-poetry-core +Summary: %{summary} + +%description -n python3-poetry-core +... + + +%prep +%autosetup -p1 -n poetry-core-%{version} + + +%generate_buildrequires +%pyproject_buildrequires + + +%build +%pyproject_wheel + + +%install +%pyproject_install +%pyproject_save_files poetry + + +%files -n python3-poetry-core -f %{pyproject_files} +%doc README.md +%license LICENSE diff --git a/tests/tests.yml b/tests/tests.yml index 65ed9fc..5441de8 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -67,6 +67,12 @@ - dns_lexicon: dir: . run: ./mocktest.sh python-dns-lexicon + - flit_core: + dir: . + run: ./mocktest.sh python-flit-core + - poetry_core: + dir: . + run: ./mocktest.sh python-poetry-core required_packages: - mock - rpmdevtools