diff --git a/.github/workflows/CI_build.yml b/.github/workflows/CI_build.yml index 697cbb5..fbddd5f 100644 --- a/.github/workflows/CI_build.yml +++ b/.github/workflows/CI_build.yml @@ -4,6 +4,12 @@ on: push: pull_request: types: [opened, reopened] + workflow_dispatch: + inputs: + tag: + description: Tag for manually running CI Build workflow + required: False + default: '' jobs: @@ -38,12 +44,12 @@ jobs: - name: Check whether import statements are used consistently shell: bash -l {0} run: poetry run isort --check-only --diff --conda-env spec2vec-dev . - - name: SonarQube Scan - if: github.repository == 'iomega/spec2vec' - uses: SonarSource/sonarqube-scan-action@v6 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} +# - name: SonarQube Scan +# if: github.repository == 'iomega/spec2vec' +# uses: SonarSource/sonarqube-scan-action@v6 +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} build_pypi: name: Pypi and documentation build / python-${{ matrix.python-version }} / ${{ matrix.os }} diff --git a/conda/meta.yaml b/conda/meta.yaml index b60c770..5ab9072 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -1,5 +1,7 @@ {% set name = "spec2vec" %} -{% set version = "0.9.1" %} + +{% set pyproject = load_file_data('../pyproject.toml', from_recipe_dir=True) %} +{% set version = pyproject.get('tool', {}).get('poetry', {}).get('version', '0+unknown') %} package: name: {{ name|lower }} diff --git a/spec2vec/__version__.py b/spec2vec/__version__.py index 8969d49..90ddbdd 100644 --- a/spec2vec/__version__.py +++ b/spec2vec/__version__.py @@ -1 +1,7 @@ -__version__ = '0.9.1' +from importlib.metadata import PackageNotFoundError, version + + +try: + __version__ = version("spec2vec") +except PackageNotFoundError: + __version__ = "0+unknown" diff --git a/tests/test_version_string_consistency.py b/tests/test_version_string_consistency.py index f7cb8ce..b2c4fb4 100644 --- a/tests/test_version_string_consistency.py +++ b/tests/test_version_string_consistency.py @@ -1,19 +1,22 @@ +import importlib import os -import re -from spec2vec import __version__ as expected_version +import pytest +import tomli +@pytest.mark.skipif(not os.getenv("CI"),reason="Skipping version consistency test outside CI environment") def test_version_string_consistency(): """Check whether version in conda/meta.yaml is consistent with that in spec2vec.__version__""" repository_root = os.path.join(os.path.dirname(__file__), "..") - fixture = os.path.join(repository_root, "conda", "meta.yaml") + pyproject_file = os.path.join(repository_root, "pyproject.toml") - with open(fixture, "r", encoding="utf-8") as f: - metayaml_contents = f.read() + with open(pyproject_file, "rb") as f: + pyproject = tomli.load(f) + expected_version = pyproject["tool"]["poetry"]["version"] - match = re.search(r"^{% set version = \"(?P.*)\" %}$", metayaml_contents, re.MULTILINE) - actual_version = match["semver"] + spec2vec = importlib.import_module("spec2vec") + actual_version = spec2vec.__version__ - assert expected_version == actual_version, "Expected version string used in conda/meta.yaml to be consistent with" \ - " that in spec2vec.__version__" + assert expected_version == actual_version, f"Expected version {expected_version!r} in pyproject.toml to match" \ + f" spec2vec.__version__ ({actual_version!r})"