From 5087670ee642a2c35e5195db61ac994cc6620ac7 Mon Sep 17 00:00:00 2001 From: s-heppner Date: Fri, 11 Oct 2024 15:17:48 +0200 Subject: [PATCH] Refactor dependency management to pyproject.toml Previously, our dependency management was a bit of a mess. We had both a `requirements.txt` and a `pyproject.toml` and some dependencies were only defined in one but not the other. This aims to fix this mess and refactor towards only using `pyproject.toml` to define the dependencies. At the same time, we also clean up the install process, which now works by simply calling `pip install .` or `pip install -e .[dev]` for the developer envrionment. Furthermore, we configure the already introduced `setuptools_scm` to automatically infer a version based on the most recent git tag. --- .github/workflows/ci.yml | 30 ++++++++++++++++-------------- .github/workflows/release.yml | 6 +++--- .gitignore | 3 +++ CONTRIBUTING.md | 2 +- pyproject.toml | 30 ++++++++++++++++++++++++++---- requirements.txt | 10 ---------- 6 files changed, 49 insertions(+), 32 deletions(-) delete mode 100644 requirements.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e65ca3b7..3a977b1ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,13 +7,19 @@ env: jobs: test: + # This job runs the unittests on the python versions specified down at the matrix runs-on: ubuntu-latest strategy: matrix: python-version: ["3.8", "3.10", "3.12"] env: COUCHDB_ADMIN_PASSWORD: "yo0Quai3" - AAS_SPECS_RELEASE_TAG: "V3.0.7" + # (2024-10-11, s-heppner) + # Specify the tag of the released schema files from https://github.com/admin-shell-io/aas-specs/releases + # that you want to use to test the serialization adapter against. + # Currently, we need to update this manually, however I'm afraid this is not possible to automatically infer, + # since it's heavily dependant of the version of the AAS specification we support. + AAS_SPECS_RELEASE_TAG: "IDTA-01001-3-0-1_schemasV3.0.8" services: couchdb: image: couchdb:3 @@ -22,7 +28,6 @@ jobs: env: COUCHDB_USER: "admin" COUCHDB_PASSWORD: ${{ env.COUCHDB_ADMIN_PASSWORD }} - steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} @@ -37,8 +42,7 @@ jobs: - name: Install Python dependencies run: | python -m pip install --upgrade pip - pip install coverage - pip install -r requirements.txt + pip install .[dev] - name: Setup test config and CouchDB database server run: | python test/_helper/setup_testdb.py -u "admin" -p "$COUCHDB_ADMIN_PASSWORD" @@ -51,8 +55,8 @@ jobs: coverage report -m static-analysis: + # This job runs static code analysis, namely pycodestyle and mypy runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 - name: Set up Python ${{ env.X_PYTHON_VERSION }} @@ -62,8 +66,7 @@ jobs: - name: Install Python dependencies run: | python -m pip install --upgrade pip - pip install pycodestyle mypy - pip install -r requirements.txt + pip install .[dev] - name: Check typing with MyPy run: | mypy basyx test @@ -72,8 +75,8 @@ jobs: pycodestyle --count --max-line-length 120 basyx test readme-codeblocks: + # This job runs the same static code analysis (mypy and pycodestyle) on the codeblocks in our docstrings. runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 - name: Set up Python ${{ env.X_PYTHON_VERSION }} @@ -83,8 +86,7 @@ jobs: - name: Install Python dependencies run: | python -m pip install --upgrade pip - pip install pycodestyle mypy codeblocks - pip install -r requirements.txt + pip install .[dev] - name: Check typing with MyPy run: | mypy <(codeblocks python README.md) @@ -96,8 +98,8 @@ jobs: codeblocks python README.md | python docs: + # This job checks, if the automatically generated documentation using sphinx can be compiled runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 - name: Set up Python ${{ env.X_PYTHON_VERSION }} @@ -107,15 +109,15 @@ jobs: - name: Install Python dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt + pip install . pip install -r docs/add-requirements.txt - name: Check documentation for errors run: | SPHINXOPTS="-a -E -n -W --keep-going" make -C docs html package: + # This job checks if we can build our SDK package runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 - name: Set up Python ${{ env.X_PYTHON_VERSION }} @@ -125,7 +127,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel build + pip install . - name: Create source and wheel dist run: | python -m build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0edc20093..912e7da42 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,8 +6,8 @@ on: jobs: publish: + # This job publishes the package to PyPI runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 - name: Set up Python 3.10 @@ -17,10 +17,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel + pip install build - name: Create source and wheel dist run: | - python setup.py sdist bdist_wheel + python -m build - name: Publish distribution to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: diff --git a/.gitignore b/.gitignore index 587fc5b12..eb5b0c468 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ /test/test_config.ini # Schema files needed for testing /test/adapter/schemas + +# Ignore dynamically generated version file +basyx/version.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 339e42442..90e2d8fdc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -127,7 +127,7 @@ Additionally, we use [PEP 484 -- Type Hints](https://www.python.org/dev/peps/pep Before submitting any changes, make sure to let `mypy` and `pycodestyle` check your code and run the unit tests with Python's builtin `unittest`. To install the required tools, use: ```bash -pip install mypy pycodestyle +pip install .[dev] ``` Running all checks: diff --git a/pyproject.toml b/pyproject.toml index b8e44a8f9..ee08429c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,26 @@ [build-system] -requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"] +requires = [ + "setuptools>=45", + "wheel", + "setuptools_scm[toml]>=6.2" +] build-backend = "setuptools.build_meta" +[tool.setuptools_scm] +# Configure setuptools_scm for version management: +# - Automatically infers the version number from the most recent git tag +# - Generates a version.py file in the package directory +# - Allows for automatic versioning between releases (e.g., 1.0.1.dev4+g12345) +# If you want to use the version anywhere in the code, use +# ``` +# from basyx.version import version +# print(f"Project version: {version}") +# ``` +write_to = "basyx/version.py" + [project] name = "basyx-python-sdk" -version = "1.0.0" +dynamic = ["version"] description = "The Eclipse BaSyx Python SDK, an implementation of the Asset Administration Shell for Industry 4.0 systems" authors = [ { name = "The Eclipse BaSyx Authors", email = "admins@iat.rwth-aachen.de" } @@ -19,10 +35,16 @@ classifiers = [ ] requires-python = ">=3.8" dependencies = [ - "python-dateutil>=2.8,<3", + "jsonschema~=4.7", "lxml>=4.2,<5", + "python-dateutil>=2.8,<3", + "types-python-dateutil", + "pyecma376-2>=0.2.4", "urllib3>=1.26,<3", - "pyecma376-2>=0.2.4" + "Werkzeug>=3.0.3,<4", + "schemathesis~=3.7", + "hypothesis~=6.13", + "lxml-stubs~=0.5.1", ] [project.optional-dependencies] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 08aa2a071..000000000 --- a/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -jsonschema~=4.7 -lxml>=4.2,<5 -python-dateutil>=2.8,<3.0 -types-python-dateutil -pyecma376-2>=0.2.4 -urllib3>=1.26,<3 -Werkzeug>=3.0.3,<4 -schemathesis~=3.7 -hypothesis~=6.13 -lxml-stubs~=0.5.1