diff --git a/pyproject.toml b/pyproject.toml index 603fcba0..f6c4ecde 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,12 +26,14 @@ authors = [ url = "https://github.com/RasmussenLab/vamb" description = "Variational and Adversarial autoencoders for Metagenomic Binning" license = "MIT" -[tool.setuptools.dynamic] -version = {attr = "vamb.__version__"} readme = {file = "README.md"} [build-system] -requires = ["setuptools ~= 63.0", "Cython ~= 0.29.5"] +requires = [ + "setuptools ~= 64.0", + "setuptools-scm >= 8.0", + "Cython ~= 0.29.5" +] build-backend = "setuptools.build_meta" [tool.ruff] @@ -43,3 +45,5 @@ filterwarnings = [ "error", "ignore::UserWarning", ] + +[tool.setuptools_scm] diff --git a/test/ci.py b/test/ci.py deleted file mode 100644 index 398852ae..00000000 --- a/test/ci.py +++ /dev/null @@ -1,102 +0,0 @@ -import vamb -import re -import subprocess -import unittest - - -def grep(path, regex): - with open(path) as file: - for line in file: - m = regex.search(line) - if m is not None: - g = m.groups() - return (int(g[0]), int(g[1]), int(g[2])) - - raise ValueError(f"Could not find regex in path {path}") - - -def snakemake_vamb_version(path): - regex = re.compile( - r"https://github\.com/RasmussenLab/vamb/archive/v([0-9]+)\.([0-9]+)\.([0-9]+)\.zip" - ) - return grep(path, regex) - - -def changelog_version(path): - with open(path) as file: - next(file) # header - textline = next(filter(None, map(str.strip, file))) - regex = re.compile(r"## v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z]+)?)?") - m = regex.search(textline) - if m is None: - raise ValueError("Could not find version in first non-header line of CHANGELOG") - g = m.groups() - v_nums = (int(g[0]), int(g[1]), int(g[2]), g[3]) - return v_nums[:3] if not v_nums[3] else v_nums - - -def readme_vamb_version(path): - regex = re.compile( - r"https://github\.com/RasmussenLab/vamb/archive/v([0-9]+)\.([0-9]+)\.([0-9]+)\.zip" - ) - return grep(path, regex) - - -def validate_init(init): - if not ( - isinstance(init, tuple) - and len(init) in (3, 4) - and all(isinstance(i, int) for i in init[:3]) - ): - raise ValueError("Wrong format of __version__ in __init__.py") - - -def latest_git_tag(): - st = subprocess.run( - ["git", "describe", "--tags", "--abbrev=0"], capture_output=True - ).stdout.decode() - regex = re.compile(r"^v?([0-9]+)\.([0-9]+)\.([0-9])\n?$") - m = regex.match(st) - if m is None: - raise ValueError("Could not find last git tag") - else: - return tuple(int(i) for i in m.groups()) - - -def head_git_tag(): - st = subprocess.run( - ["git", "tag", "--points-at", "HEAD"], capture_output=True - ).stdout.decode() - if len(st) == 0: - return (None, None) - regex = re.compile(r"^(v([0-9]+)\.([0-9]+)\.([0-9]))\n?$") - m = regex.match(st) - if m is None: - raise ValueError("HEADs git tag is not a valid version number") - return tuple(int(i) for i in m.groups()[1:4]) - - -class TestVersions(unittest.TestCase): - @classmethod - def setUpClass(cls): - validate_init(vamb.__version__) - cls.v_init = vamb.__version__ - cls.v_changelog = changelog_version("CHANGELOG.md") - cls.last_tag = latest_git_tag() - head_tag = head_git_tag() - cls.head_tag = head_tag - - def test_same_versions(self): - # The version in the changelog must fit the one in __init__ - self.assertEqual(self.v_init, self.v_changelog) - - def test_dev_version(self): - # If the current version is a DEV version, it must be a greater version - # than the latest release. - # If not, it must be the same version as the tag of the current commit, - # i.e. the current commit must be a release version. - if len(self.v_init) > 3: - self.assertGreater(self.v_init[:3], self.last_tag) - else: - self.assertEqual(self.v_init, self.head_tag) - self.assertEqual(self.v_init[:3], self.last_tag) diff --git a/vamb/__init__.py b/vamb/__init__.py index fefb8ecc..7fd33c80 100644 --- a/vamb/__init__.py +++ b/vamb/__init__.py @@ -2,8 +2,6 @@ Documentation: https://github.com/RasmussenLab/vamb/ """ -__version__ = (4, 1, 3) - from . import vambtools from . import parsebam from . import parsecontigs @@ -15,8 +13,10 @@ from . import taxvamb_encode from . import reclustering +from importlib.metadata import version as get_version from loguru import logger +__version_str__ = get_version("vamb") logger.remove() __all__ = [ diff --git a/vamb/__main__.py b/vamb/__main__.py index 7e9fc6fd..b3b0c917 100755 --- a/vamb/__main__.py +++ b/vamb/__main__.py @@ -1413,7 +1413,7 @@ def run(self): ) logger.add(sys.stderr, format=format_log) begintime = time.time() - logger.info("Starting Vamb version " + ".".join(map(str, vamb.__version__))) + logger.info("Starting Vamb version " + vamb.__version_str__) logger.info("Random seed is " + str(self.vamb_options.seed)) self.run_inner() logger.info(f"Completed Vamb in {round(time.time() - begintime, 2)} seconds.") @@ -2071,7 +2071,7 @@ def add_reclustering_arguments(subparser): def main(): doc = f""" - Version: {'.'.join([str(i) for i in vamb.__version__])} + Version: {vamb.__version_str__} Default use, good for most datasets: vamb bin default --outdir out --fasta my_contigs.fna --bamfiles *.bam -o C @@ -2091,7 +2091,7 @@ def main(): helpos.add_argument( "--version", action="version", - version=f'Vamb {".".join(map(str, vamb.__version__))}', + version=f"Vamb {vamb.__version_str__}", ) if len(sys.argv) == 1: