diff --git a/snapcraft_legacy/plugins/v2/python.py b/snapcraft_legacy/plugins/v2/python.py index 2eb4e21efd..30585d3a67 100644 --- a/snapcraft_legacy/plugins/v2/python.py +++ b/snapcraft_legacy/plugins/v2/python.py @@ -19,7 +19,7 @@ It can be used for python projects where you would want to do: - import python modules with a requirements.txt - - build a python project that has a setup.py + - build a python project that has a setup.py or pyproject.toml file - install packages straight from pip This plugin uses the common plugin keywords as well as those for "sources". @@ -140,7 +140,9 @@ def get_build_commands(self) -> List[str]: requirements_cmd = f"pip install {constraints} -U {requirements}" build_commands.append(requirements_cmd) - build_commands.append(f"[ -f setup.py ] && pip install {constraints} -U .") + build_commands.append( + f"[ -f setup.py -o -f pyproject.toml ] && pip install {constraints} -U ." + ) # Now fix shebangs. # TODO: replace with snapcraftctl once the two scripts are consolidated diff --git a/tests/legacy/unit/plugins/v2/test_python.py b/tests/legacy/unit/plugins/v2/test_python.py index 438c324c91..f14a31d6f4 100644 --- a/tests/legacy/unit/plugins/v2/test_python.py +++ b/tests/legacy/unit/plugins/v2/test_python.py @@ -113,7 +113,7 @@ class Options: == [ '"${SNAPCRAFT_PYTHON_INTERPRETER}" -m venv ${SNAPCRAFT_PYTHON_VENV_ARGS} "${SNAPCRAFT_PART_INSTALL}"', 'SNAPCRAFT_PYTHON_VENV_INTERP_PATH="${SNAPCRAFT_PART_INSTALL}/bin/${SNAPCRAFT_PYTHON_INTERPRETER}"', - "[ -f setup.py ] && pip install -U .", + "[ -f setup.py -o -f pyproject.toml ] && pip install -U .", ] + _FIXUP_BUILD_COMMANDS ) @@ -134,7 +134,7 @@ class Options: 'SNAPCRAFT_PYTHON_VENV_INTERP_PATH="${SNAPCRAFT_PART_INSTALL}/bin/${SNAPCRAFT_PYTHON_INTERPRETER}"', "pip install -c 'constraints.txt' -U pip 'some-pkg; sys_platform != '\"'\"'win32'\"'\"''", "pip install -c 'constraints.txt' -U -r 'requirements.txt'", - "[ -f setup.py ] && pip install -c 'constraints.txt' -U .", + "[ -f setup.py -o -f pyproject.toml ] && pip install -c 'constraints.txt' -U .", ] + _FIXUP_BUILD_COMMANDS ) diff --git a/tests/spread/plugins/v2/build-and-run-hello/task.yaml b/tests/spread/plugins/v2/build-and-run-hello/task.yaml index 083e9315e4..7d43254175 100644 --- a/tests/spread/plugins/v2/build-and-run-hello/task.yaml +++ b/tests/spread/plugins/v2/build-and-run-hello/task.yaml @@ -16,6 +16,7 @@ environment: SNAP/python: python-hello SNAP/python_multiple_parts: python-hello-multiple-parts SNAP/python_multiple_parts_staged: python-hello-multiple-parts-staged + SNAP/python_pyproject: python-hello-pyproject SNAP/python_staged: python-hello-staged-python SNAP/python_with_stage_package_in_base: python-with-stage-package-in-base SNAP/python_with_python_package_dep: python-hello-with-python-package-dep diff --git a/tests/spread/plugins/v2/snaps/python-hello-pyproject/hello b/tests/spread/plugins/v2/snaps/python-hello-pyproject/hello new file mode 100644 index 0000000000..e3095b2229 --- /dev/null +++ b/tests/spread/plugins/v2/snaps/python-hello-pyproject/hello @@ -0,0 +1,2 @@ +def main(): + print("hello world") diff --git a/tests/spread/plugins/v2/snaps/python-hello-pyproject/pyproject.toml b/tests/spread/plugins/v2/snaps/python-hello-pyproject/pyproject.toml new file mode 100644 index 0000000000..6149544990 --- /dev/null +++ b/tests/spread/plugins/v2/snaps/python-hello-pyproject/pyproject.toml @@ -0,0 +1,11 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "python_hello_pyproject" +description = "A simple hello world in python" +version = "0.0.1" + +[project.scripts] +python-hello-pyproject = "pythonhellopyproject:main" diff --git a/tests/spread/plugins/v2/snaps/python-hello-pyproject/snap/snapcraft.yaml b/tests/spread/plugins/v2/snaps/python-hello-pyproject/snap/snapcraft.yaml new file mode 100644 index 0000000000..951d20d932 --- /dev/null +++ b/tests/spread/plugins/v2/snaps/python-hello-pyproject/snap/snapcraft.yaml @@ -0,0 +1,18 @@ +name: python-hello-pyproject +version: "1.0" +summary: hello world +description: A simple hello world in python using a pyproject.toml. +grade: devel +base: core20 +confinement: strict + +apps: + python-hello-pyproject: + command: bin/python-hello-pyproject + +parts: + hello: + source: . + plugin: python + python-packages: + - pip==20.0.2 diff --git a/tests/spread/plugins/v2/snaps/python-hello-pyproject/src/pythonhellopyproject/__init__.py b/tests/spread/plugins/v2/snaps/python-hello-pyproject/src/pythonhellopyproject/__init__.py new file mode 120000 index 0000000000..9ad7f2b392 --- /dev/null +++ b/tests/spread/plugins/v2/snaps/python-hello-pyproject/src/pythonhellopyproject/__init__.py @@ -0,0 +1 @@ +../../hello \ No newline at end of file