From 0cb632ad18c8724a99ec1cce28ec0b914d15e246 Mon Sep 17 00:00:00 2001 From: Tomas Capretto Date: Wed, 24 Jan 2024 18:17:57 -0300 Subject: [PATCH] Add automatic versioning to the library --- .github/workflows/publish-pypi.yml | 8 +++++++- formulae/__init__.py | 7 ++++++- formulae/version.py | 12 ------------ formulae/version.txt | 1 - pyproject.toml | 7 +++---- 5 files changed, 16 insertions(+), 19 deletions(-) delete mode 100644 formulae/version.py delete mode 100644 formulae/version.txt diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index e8234a6..15ba9b5 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -84,4 +84,10 @@ jobs: env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN_FORMULAE }} - run: python3 -m twine upload dist/* \ No newline at end of file + run: python3 -m twine upload dist/* + + +# See documentation on accesing the tag from the release +# Look for 'github.ref' and 'github.ref_name' in https://docs.github.com/en/actions/learn-github-actions/contexts +# On October, 2023 it says "For workflows triggered by release, this is the release tag created" +# So 'github.ref_name' should be the version number of the release we're making. \ No newline at end of file diff --git a/formulae/__init__.py b/formulae/__init__.py index 08bbb9d..9b38564 100644 --- a/formulae/__init__.py +++ b/formulae/__init__.py @@ -1,9 +1,14 @@ import logging +from importlib.metadata import version + from .config import config from .matrices import design_matrices from .model_description import model_description -from .version import __version__ + +# from .version import __version__ + +__version__ = version("formulae") __all__ = [ "config", diff --git a/formulae/version.py b/formulae/version.py deleted file mode 100644 index 7f4ec64..0000000 --- a/formulae/version.py +++ /dev/null @@ -1,12 +0,0 @@ -import os - -here = os.path.dirname(os.path.realpath(__file__)) - - -def read_version(): - version_file = os.path.join(here, "version.txt") - with open(version_file, encoding="utf-8") as buff: - return buff.read().splitlines()[0] - - -__version__ = read_version() diff --git a/formulae/version.txt b/formulae/version.txt deleted file mode 100644 index 5d4294b..0000000 --- a/formulae/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.5.1 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 98a8871..56996b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,8 @@ [build-system] build-backend = "setuptools.build_meta" -requires = ["setuptools>=61.0"] +requires = ["setuptools>=61.0", "setuptools_scm>=8"] + +[tool.setuptools_scm] [project] name = "formulae" @@ -40,9 +42,6 @@ changelog = "https://github.com/bambinos/formulae/blob/main/docs/CHANGELOG.md" [tool.setuptools] packages = ["formulae", "formulae.terms"] -[tool.setuptools.dynamic] -version = {file = "formulae/version.txt"} - [tool.black] line-length = 100 target-version = ["py39", "py310"] \ No newline at end of file