diff --git a/.gitignore b/.gitignore index c2ee2a574..c54116f62 100644 --- a/.gitignore +++ b/.gitignore @@ -134,3 +134,6 @@ dmypy.json # CodeTF and sarif files *.codetf* *.sarif + +# version +src/codemodder/_version.py diff --git a/pyproject.toml b/pyproject.toml index 5536340f6..3ad0731e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [build-system] -requires = ["setuptools"] +requires = ["setuptools", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" [project] +dynamic = ["version"] name = "codemodder-python" -version = "0.60.0" requires-python = ">=3.10.0" readme = "README.md" license = {file = "LICENSE"} @@ -34,6 +34,9 @@ core = "core_codemods:registry" "core_codemods.semgrep" = ["src/core_codemods/semgrep/*.yaml"] "core_codemods.docs" = ["src/core_codemods/docs/*.md"] +[tool.setuptools_scm] +version_file = "src/codemodder/_version.py" + [tool.pytest.ini_options] # Ignore integration tests and ci tests by default testpaths = ["tests"] diff --git a/src/codemodder/__init__.py b/src/codemodder/__init__.py index 57de45e60..cc5c4537e 100644 --- a/src/codemodder/__init__.py +++ b/src/codemodder/__init__.py @@ -1,2 +1,4 @@ -# TODO: use tag-based versioning -__VERSION__ = "0.57.0" +try: + from ._version import __version__ +except ImportError: + __version__ = "unknown" diff --git a/src/codemodder/cli.py b/src/codemodder/cli.py index 20b18a3f2..421e65aca 100644 --- a/src/codemodder/cli.py +++ b/src/codemodder/cli.py @@ -1,7 +1,7 @@ import argparse import sys -from codemodder import __VERSION__ +from codemodder import __version__ from codemodder.code_directory import DEFAULT_INCLUDED_PATHS, DEFAULT_EXCLUDED_PATHS from codemodder.logging import OutputFormat, logger @@ -111,7 +111,7 @@ def parse_args(argv, codemod_registry): help="Comma-separated set of codemod ID(s) to include", ) - parser.add_argument("--version", action="version", version=__VERSION__) + parser.add_argument("--version", action="version", version=__version__) parser.add_argument( "--list", action=build_list_action(codemod_registry), diff --git a/src/codemodder/codemodder.py b/src/codemodder/codemodder.py index 9a54bc257..9c8438312 100644 --- a/src/codemodder/codemodder.py +++ b/src/codemodder/codemodder.py @@ -11,7 +11,7 @@ from libcst.codemod import CodemodContext from codemodder.file_context import FileContext -from codemodder import registry, __VERSION__ +from codemodder import registry, __version__ from codemodder.logging import configure_logger, logger, log_section, log_list from codemodder.cli import parse_args from codemodder.change import ChangeSet @@ -176,7 +176,7 @@ def run(original_args) -> int: configure_logger(argv.verbose, argv.log_format, argv.project_name) log_section("startup") - logger.info("codemodder: python/%s", __VERSION__) + logger.info("codemodder: python/%s", __version__) repo_manager = PythonRepoManager(Path(argv.directory)) context = CodemodExecutionContext( diff --git a/src/codemodder/report/codetf_reporter.py b/src/codemodder/report/codetf_reporter.py index 0e0b4c1d7..0e4c3a303 100644 --- a/src/codemodder/report/codetf_reporter.py +++ b/src/codemodder/report/codetf_reporter.py @@ -1,6 +1,6 @@ import json from os.path import abspath -from codemodder import __VERSION__ +from codemodder import __version__ from codemodder.logging import logger @@ -9,7 +9,7 @@ def base_report(): "run": { "vendor": "pixee", "tool": "codemodder-python", - "version": __VERSION__, + "version": __version__, "sarifs": [], }, "results": [], diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 000000000..6cd44a0a5 --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,5 @@ +from codemodder import __version__ + + +def test_version(): + assert __version__ != "unknown"