Skip to content

Commit

Permalink
Use setuptools_scm to implement tag-based versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Oct 27, 2023
1 parent c9634a5 commit 7c5fcef
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ dmypy.json
# CodeTF and sarif files
*.codetf*
*.sarif

# version
src/codemodder/_version.py
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"}
Expand Down Expand Up @@ -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"]
6 changes: 4 additions & 2 deletions src/codemodder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# TODO: use tag-based versioning
__VERSION__ = "0.57.0"
try:
from ._version import __version__
except ImportError:
__version__ = "unknown"
4 changes: 2 additions & 2 deletions src/codemodder/cli.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/codemodder/codemodder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/codemodder/report/codetf_reporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from os.path import abspath
from codemodder import __VERSION__
from codemodder import __version__
from codemodder.logging import logger


Expand All @@ -9,7 +9,7 @@ def base_report():
"run": {
"vendor": "pixee",
"tool": "codemodder-python",
"version": __VERSION__,
"version": __version__,
"sarifs": [],
},
"results": [],
Expand Down
5 changes: 5 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from codemodder import __version__


def test_version():
assert __version__ != "unknown"

0 comments on commit 7c5fcef

Please sign in to comment.