diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0143def4d..1bf2d2d33 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -135,3 +135,32 @@ jobs: with: name: Wasm path: pkg + + pypi-publish: + name: Upload release to PyPI + runs-on: ubuntu-22.04 + needs: [build-python] + if: ${{ github.repository_owner == 'SleipnirGroup' && github.ref == 'refs/heads/main' }} + environment: + name: pypi + url: https://pypi.org/p/sleipnirgroup-jormungandr + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v3 + with: + name: Windows - python + path: dist + - uses: actions/download-artifact@v3 + with: + name: Linux - python + path: dist + - uses: actions/download-artifact@v3 + with: + name: macOS - python + path: dist + - name: Diagnostics + run: ls -R + + #- name: Publish package distributions to PyPI + # uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/jormungandr/__init__.py b/jormungandr/__init__.py index a261d520c..4ac8b98c7 100644 --- a/jormungandr/__init__.py +++ b/jormungandr/__init__.py @@ -3,4 +3,8 @@ that uses the interior-point method. """ -from ._jormungandr import * +try: + from ._jormungandr import * +except: + print("Warning: No module named 'jormungandr._jormungandr'") + pass diff --git a/jormungandr/version.py b/jormungandr/version.py new file mode 100644 index 000000000..d9bdb26ee --- /dev/null +++ b/jormungandr/version.py @@ -0,0 +1,30 @@ +import re +import subprocess + + +def get_version(): + proc = subprocess.run( + [ + "git", + "describe", + ], + check=True, + encoding="utf-8", + stdout=subprocess.PIPE, + ) + if proc.returncode: + raise RuntimeError("Couldn't find tag for version number") + + m = re.search( + r"^v ([0-9]+\.[0-9]+\.[0-9]+) (- ([0-9]+) )?", + proc.stdout.rstrip(), + re.X, + ) + + # Version number: .dev<# commits since tag> + version = m.group(1) + try: + version += f".dev{m.group(2)}" + except: + pass + return version diff --git a/pyproject.toml b/pyproject.toml index 859179a48..0b1e27cb9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "sleipnirgroup-jormungandr" description = "A linearity-exploiting sparse nonlinear constrained optimization problem solver that uses the interior-point method." -version = "0.0.1" +dynamic = [ "version" ] readme = "README.md" requires-python = ">=3.7" dependencies = [ "numpy" ] @@ -13,7 +13,12 @@ dependencies = [ "numpy" ] Documentation = "https://sleipnirgroup.github.io/Sleipnir/" [build-system] -requires = [ "py-build-cmake~=0.1.8", "pybind11", "pybind11-stubgen" ] +requires = [ + "py-build-cmake~=0.1.8", + "pybind11", + "pybind11-stubgen", + "setuptools-git-versioning" +] build-backend = "py_build_cmake.build" [tool.py-build-cmake.module] @@ -43,6 +48,10 @@ install_args = [ "--strip" ] BUILD_TESTING = "OFF" BUILD_PYTHON = "ON" +[tool.setuptools-git-versioning] +enabled = true +version_callback = "jormungandr.version:get_version" + [tool.pytest.ini_options] minversion = "6.0" testpaths = [ "jormungandr/test" ]