Skip to content

Commit

Permalink
feat(plugins): add core20 support for pyproject.toml projects (#4087)
Browse files Browse the repository at this point in the history
LP: #2008237

Signed-off-by: 林博仁(Buo-ren Lin) <[email protected]>
Signed-off-by: Callahan Kovacs <[email protected]>
Co-authored-by: Callahan Kovacs <[email protected]>
  • Loading branch information
brlin-tw and mr-cal authored Oct 19, 2023
1 parent bf37fd4 commit 2d59662
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
6 changes: 4 additions & 2 deletions snapcraft_legacy/plugins/v2/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy/unit/plugins/v2/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
)
1 change: 1 addition & 0 deletions tests/spread/plugins/v2/build-and-run-hello/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/spread/plugins/v2/snaps/python-hello-pyproject/hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main():
print("hello world")
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2d59662

Please sign in to comment.