diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml deleted file mode 100644 index 71c4570..0000000 --- a/.github/workflows/main.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: build - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - timeout-minutes: 10 - concurrency: - group: ci-${{ github.ref }} - cancel-in-progress: true - - defaults: - run: - shell: bash -l {0} - - steps: - - uses: actions/checkout@v3 - - uses: conda-incubator/setup-miniconda@v2 - with: - miniconda-version: "latest" - mamba-version: "1.*" - environment-file: conda/dev.yaml - channels: conda-forge,nodefaults - channel-priority: true - activate-environment: comodi - use-mamba: true - miniforge-variant: Mambaforge - - - name: Install dependencies - run: poetry install - - - name: Run tests - run: make test - - - name: Run style checks - run: | - pre-commit install - make lint diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 74b26cd..76d9d52 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,61 +1,17 @@ -name: Release - +name: Publish to PyPI.org on: - workflow_dispatch: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: release: - name: Release + types: [published] +jobs: + pypi: runs-on: ubuntu-latest - timeout-minutes: 10 - - defaults: - run: - shell: bash -l {0} - steps: - - uses: actions/checkout@v3 - - - uses: conda-incubator/setup-miniconda@v2 + - name: Checkout + uses: actions/checkout@v3 with: - miniconda-version: "latest" - mamba-version: "1.*" - environment-file: conda/dev.yaml - channels: conda-forge,nodefaults - channel-priority: true - activate-environment: comodi - use-mamba: true - miniforge-variant: Mambaforge - - - name: Install deps - run: poetry install - - - name: Run semantic release (for tests) - if: ${{ github.event_name != 'workflow_dispatch' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: make release-dry - - - name: Release command - if: ${{ github.event_name == 'workflow_dispatch' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} - run: | - poetry config pypi-token.pypi ${PYPI_TOKEN} - make release-ci - - - name: Generate documentation with changes from semantic-release - if: ${{ github.event_name == 'workflow_dispatch' }} - run: make docs-build - - - name: GitHub Pages action - if: ${{ github.event_name == 'workflow_dispatch' }} - uses: peaceiris/actions-gh-pages@v3.5.9 + fetch-depth: 0 + - run: python3 -m pip install --upgrade build && python3 -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./docs/_build/html + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/comodi/__init__.py b/comodi/__init__.py index f28e27a..442d4dd 100644 --- a/comodi/__init__.py +++ b/comodi/__init__.py @@ -19,16 +19,13 @@ from .tools import hierarchical_priors -def _get_version() -> str: - """Return the program version.""" - try: - return importlib_metadata.version(__name__) - except importlib_metadata.PackageNotFoundError: # pragma: no cover - return "0.1.0" # Default version - - -version: str = _get_version() - __author__ = "Jonas Dehning" __email__ = "jonas.dehning@ds.mpg.de" -__version__: str = version + +from importlib.metadata import version, PackageNotFoundError + +try: + __version__ = version("package-name") +except PackageNotFoundError: + # package is not installed + pass diff --git a/docs/conf.py b/docs/conf.py index cc09ab4..a74fc31 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -81,10 +81,12 @@ # for |version| and |release|, also used in various other places throughout # the built documents. # -# The short X.Y version. -version = "0.1.0" -# The full version, including alpha/beta/rc tags. -release = "0.1.0" + +from importlib.metadata import version +release = version('myproject') +# for example take major/minor +version = '.'.join(release.split('.')[:2]) + # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pyproject.toml b/pyproject.toml index ac9272c..00880b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools"] +requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] build-backend = "setuptools.build_meta" @@ -21,8 +21,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", ] -#dynamic = ["version"] -version = "0.1.0" +dynamic = ["version"] requires-python = '>=3.8.1' dependencies = [ "numpy", @@ -103,4 +102,7 @@ no_strict_optional = false [tool.setuptools] packages = ["comodi"] +[tool.setuptools_scm] +write_to = "comodi/_version.py" +