Repository: mmcdermott/nested_ragged_tensors (language: python)

Issue:
Build setup should be finalized with more recent improvements.
  - [ ] Add dynamic versioning
  - [ ] Add python build workflow


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/code-quality-main.yaml b/.github/workflows/code-quality-main.yaml
index d336969..7539856 100644
--- a/.github/workflows/code-quality-main.yaml
+++ b/.github/workflows/code-quality-main.yaml
@@ -13,10 +13,10 @@ jobs:
 
     steps:
       - name: Checkout
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
 
       - name: Set up Python
-        uses: actions/setup-python@v3
+        uses: actions/setup-python@v5
 
       - name: Run pre-commits
-        uses: pre-commit/action@v3.0.0
+        uses: pre-commit/action@v3.0.1
diff --git a/.github/workflows/code-quality-pr.yaml b/.github/workflows/code-quality-pr.yaml
index 7ca7753..152e022 100644
--- a/.github/workflows/code-quality-pr.yaml
+++ b/.github/workflows/code-quality-pr.yaml
@@ -16,10 +16,10 @@ jobs:
 
     steps:
       - name: Checkout
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
 
       - name: Set up Python
-        uses: actions/setup-python@v3
+        uses: actions/setup-python@v5
 
       - name: Find modified files
         id: file_changes
@@ -31,6 +31,6 @@ jobs:
         run: echo '${{ steps.file_changes.outputs.files}}'
 
       - name: Run pre-commits
-        uses: pre-commit/action@v3.0.0
+        uses: pre-commit/action@v3.0.1
         with:
           extra_args: --files ${{ steps.file_changes.outputs.files}}
diff --git a/.github/workflows/python-build.yaml b/.github/workflows/python-build.yaml
new file mode 100644
index 0000000..d8639e8
--- /dev/null
+++ b/.github/workflows/python-build.yaml
@@ -0,0 +1,99 @@
+name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
+
+on: push
+
+jobs:
+  build:
+    name: Build distribution 📦
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        python-version: ["3.11"]
+
+    steps:
+      - uses: actions/checkout@v4
+      - name: Set up Python ${{ matrix.python-version }}
+        uses: actions/setup-python@v5
+        with:
+          python-version: ${{ matrix.python-version }}
+      - name: Install pypa/build
+        run: >-
+          python3 -m
+          pip install
+          build
+          --user
+      - name: Build a binary wheel and a source tarball
+        run: python3 -m build
+      - name: Store the distribution packages
+        uses: actions/upload-artifact@v4
+        with:
+          name: python-package-distributions
+          path: dist/
+
+  publish-to-pypi:
+    name: >-
+      Publish Python 🐍 distribution 📦 to PyPI
+    if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
+    needs:
+      - build
+    runs-on: ubuntu-latest
+    environment:
+      name: pypi
+      url: https://pypi.org/p/nested-ragged-tensors # Replace <package-name> with your PyPI project name
+    permissions:
+      id-token: write # IMPORTANT: mandatory for trusted publishing
+
+    steps:
+      - name: Download all the dists
+        uses: actions/download-artifact@v4
+        with:
+          name: python-package-distributions
+          path: dist/
+
+      - name: Publish distribution 📦 to PyPI
+        uses: pypa/gh-action-pypi-publish@release/v1
+
+  github-release:
+    name: >-
+      Sign the Python 🐍 distribution 📦 with Sigstore
+      and upload them to GitHub Release
+    needs:
+      - publish-to-pypi
+    runs-on: ubuntu-latest
+
+    permissions:
+      contents: write # IMPORTANT: mandatory for making GitHub Releases
+      id-token: write # IMPORTANT: mandatory for sigstore
+
+    steps:
+      - name: Download all the dists
+        uses: actions/download-artifact@v4
+        with:
+          name: python-package-distributions
+          path: dist/
+
+      - name: Sign the dists with Sigstore
+        uses: sigstore/gh-action-sigstore-python@v2.1.1
+        with:
+          inputs: >-
+            ./dist/*.tar.gz
+            ./dist/*.whl
+      - name: Create GitHub Release
+        env:
+          GITHUB_TOKEN: ${{ github.token }}
+        run: >-
+          gh release create
+          '${{ github.ref_name }}'
+          --repo '${{ github.repository }}'
+          --notes ""
+      - name: Upload artifact signatures to GitHub Release
+        env:
+          GITHUB_TOKEN: ${{ github.token }}
+        # Upload to GitHub Release using the `gh` CLI.
+        # `dist/` contains the built packages, and the
+        # sigstore-produced signatures and certificates.
+        run: >-
+          gh release upload
+          '${{ github.ref_name }}' dist/**
+          --repo '${{ github.repository }}'
diff --git a/pyproject.toml b/pyproject.toml
index 6a27ba8..daad9fd 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,10 +1,10 @@
 [build-system]
-requires = ["setuptools>=61.0"]
+requires = ["setuptools>=64", "setuptools-scm>=8.0", "wheel"]
 build-backend = "setuptools.build_meta"
 
 [project]
 name = "nested_ragged_tensors"
-version = "0.0.6"
+dynamic = ["version"]
 authors = [
   { name="Matthew McDermott", email="mattmcdermott8@gmail.com" },
 ]
@@ -18,9 +18,12 @@ classifiers = [
 ]
 dependencies = ["safetensors", "numpy"]
 
+[tool.setuptools_scm]
+
 [project.optional-dependencies]
 dev = ["pre-commit"]
-tests = ["pytest", "ml-mixins", "loguru", "torch", "rootutils", "hydra-core", "humanize", "pytest-cov"]
+tests = ["pytest", "pytest-cov"]
+performance_testing = ["ml-mixins", "loguru", "torch", "rootutils", "hydra-core", "humanize"]
 
 [project.urls]
 Homepage = "https://github.com/mmcdermott/nested_ragged_tensors"
diff --git a/src/nested_ragged_tensors/__init__.py b/src/nested_ragged_tensors/__init__.py
index e69de29..3a2c46a 100644
--- a/src/nested_ragged_tensors/__init__.py
+++ b/src/nested_ragged_tensors/__init__.py
@@ -0,0 +1,7 @@
+from importlib.metadata import PackageNotFoundError, version
+
+__package_name__ = "nested_ragged_tensors"
+try:
+    __version__ = version(__package_name__)
+except PackageNotFoundError:  # pragma: no cover
+    __version__ = "unknown"


Test patch:
diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml
index b8a3e1a..ff16584 100644
--- a/.github/workflows/tests.yaml
+++ b/.github/workflows/tests.yaml
@@ -11,34 +11,38 @@ jobs:
     runs-on: ubuntu-latest
 
     strategy:
+      matrix:
+        python-version: ["3.10", "3.11", "3.12"]
       fail-fast: false
 
     timeout-minutes: 30
-
     steps:
       - name: Checkout
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
 
-      - name: Set up Python 3.11
-        uses: actions/setup-python@v3
+      - name: Set up Python ${{ matrix.python-version }}
+        uses: actions/setup-python@v5
         with:
-          python-version: "3.11"
+          python-version: ${{ matrix.python-version }}
 
       - name: Install packages
         run: |
-          pip install -e .
-          pip install pytest
-          pip install pytest-cov[toml]
-          pip install rootutils
+          pip install -e .[tests]
 
       #----------------------------------------------
       #              run test suite
       #----------------------------------------------
       - name: Run tests
         run: |
-          pytest -v --doctest-modules --cov --ignore=performance_tests
+          pytest -v --doctest-modules --cov=src --junitxml=junit.xml -s --ignore=performance_tests
 
       - name: Upload coverage to Codecov
         uses: codecov/codecov-action@v4.0.1
         with:
           token: ${{ secrets.CODECOV_TOKEN }}
+
+      - name: Upload test results to Codecov
+        if: ${{ !cancelled() }}
+        uses: codecov/test-results-action@v1
+        with:
+          token: ${{ secrets.CODECOV_TOKEN }}