From daafb8979cdd1be30f1f4682bdcd2ab80f4e4ff1 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Thu, 10 Oct 2024 18:42:23 +0200 Subject: [PATCH] Clarify PEP621 (#113) * Clarify PEP621 * Add extra test to validate pip-dist works with pyproject.toml * Use a newer python version on test * Add new test folder * Update pyproject * Update pyproject * Update pyproject.toml * Update pyproject.toml * Update pyproject.toml --------- Co-authored-by: marboledacci --- .circleci/test-deploy.yml | 9 +++++++++ sample_pip_pyproject/pyproject.toml | 14 ++++++++++++++ sample_pip_pyproject/requirements.txt | 1 + sample_pip_pyproject/src/example.py | 5 +++++ sample_pip_pyproject/tests/__init__.py | 0 sample_pip_pyproject/tests/test_ex.py | 11 +++++++++++ sample_pip_pyproject/tests/test_job.py | 7 +++++++ src/commands/install-packages.yml | 6 +++--- 8 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 sample_pip_pyproject/pyproject.toml create mode 100644 sample_pip_pyproject/requirements.txt create mode 100644 sample_pip_pyproject/src/example.py create mode 100644 sample_pip_pyproject/tests/__init__.py create mode 100644 sample_pip_pyproject/tests/test_ex.py create mode 100644 sample_pip_pyproject/tests/test_job.py diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 1c9ca0d..8acba88 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -252,6 +252,13 @@ workflows: name: If another python version is loaded - its broken - this verifies that it's broken when: on_fail command: python --version + - python/test: + filters: *filters + version: 3.11.4 + name: job-test-pip-dist-pyproject + pkg-manager: pip-dist + cache-version: pip-dist-pyproject-<< pipeline.parameters.cache-version >> + app-dir: ~/project/sample_pip_pyproject - orb-tools/pack: filters: *filters - orb-tools/publish: @@ -270,6 +277,8 @@ workflows: - job-test-poetry - job-test-pipenv - job-test-pip + - job-test-pip-dist + - job-test-pip-dist-pyproject - job-auto-test-poetry - job-auto-test-pipenv - job-auto-test-pip diff --git a/sample_pip_pyproject/pyproject.toml b/sample_pip_pyproject/pyproject.toml new file mode 100644 index 0000000..49a695c --- /dev/null +++ b/sample_pip_pyproject/pyproject.toml @@ -0,0 +1,14 @@ +# Example toml for integration testing - this is not used by the orb in anyway +[project] +authors=[ + {name="TEST", email="test@test.com"} +] +name="test" +description="none" +version = "0.0.1" +requires-python=">3.11" +dependencies=["pytest"] + +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" diff --git a/sample_pip_pyproject/requirements.txt b/sample_pip_pyproject/requirements.txt new file mode 100644 index 0000000..e079f8a --- /dev/null +++ b/sample_pip_pyproject/requirements.txt @@ -0,0 +1 @@ +pytest diff --git a/sample_pip_pyproject/src/example.py b/sample_pip_pyproject/src/example.py new file mode 100644 index 0000000..3cefd93 --- /dev/null +++ b/sample_pip_pyproject/src/example.py @@ -0,0 +1,5 @@ + + +def add_func(x,y): + z = x+y + return z \ No newline at end of file diff --git a/sample_pip_pyproject/tests/__init__.py b/sample_pip_pyproject/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sample_pip_pyproject/tests/test_ex.py b/sample_pip_pyproject/tests/test_ex.py new file mode 100644 index 0000000..32c194d --- /dev/null +++ b/sample_pip_pyproject/tests/test_ex.py @@ -0,0 +1,11 @@ +from src import example + +import unittest + +class TestCase(unittest.TestCase): + + def test_add1(self): + assert example.add_func(5,5) == 10 + + def test_add2(self): + assert example.add_func(5,10) == 15 diff --git a/sample_pip_pyproject/tests/test_job.py b/sample_pip_pyproject/tests/test_job.py new file mode 100644 index 0000000..9969986 --- /dev/null +++ b/sample_pip_pyproject/tests/test_job.py @@ -0,0 +1,7 @@ + +import unittest + +class TestCase(unittest.TestCase): + + def test_true(self): + assert True diff --git a/src/commands/install-packages.yml b/src/commands/install-packages.yml index 53372d2..5638137 100755 --- a/src/commands/install-packages.yml +++ b/src/commands/install-packages.yml @@ -9,7 +9,7 @@ parameters: type: enum enum: [auto, poetry, pipenv, pip, pip-dist] default: auto - description: Which package management tool to use, pipenv, pip or poetry with dependency file. Use `pip-dist` to install with project setup.py. + description: Which package management tool to use, pipenv, pip or poetry with dependency file. Use `pip-dist` to install with project setup.py or PEP621 (pyproject.toml). path-args: type: string default: "." @@ -27,7 +27,7 @@ parameters: default: requirements.txt description: | Name of the requirements file that needs to be installed with pip. Prepended with `app-dir`. If using pipenv or poetry, this is ignored. - If using `pip-dist`, use this to use the cache checksum against the `setup.py` if desired. + If using `pip-dist`, use this to use the cache checksum against the `setup.py` or `pyproject.toml` if desired. If `pip-dependency-file` is set to an empty string, no dependency file is used in the `pip install` command. app-dir: type: string @@ -164,7 +164,7 @@ steps: equal: [pip-dist, << parameters.pkg-manager >>] steps: - run: - name: "Install dependencies with pip using project setup.py" + name: "Install dependencies with pip using project setup.py or pyproject.toml" no_output_timeout: << parameters.no_output_timeout >> working_directory: <> command: |