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 31, 2023
1 parent cf2c50c commit 4dce8ee
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
source = codemodder
omit =
*/codemodder/scripts/*
*/codemodder/_version.py

[paths]
codemodder =
Expand Down
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
4 changes: 2 additions & 2 deletions integration_tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pathlib
import subprocess

from codemodder import __VERSION__
from codemodder import __version__
from codemodder import registry
from tests.validations import execute_code

Expand Down Expand Up @@ -70,7 +70,7 @@ def setup_method(self):
def _assert_run_fields(self, run, output_path):
assert run["vendor"] == "pixee"
assert run["tool"] == "codemodder-python"
assert run["version"] == __VERSION__
assert run["version"] == __version__
assert run["elapsed"] != ""
assert (
run["commandLine"]
Expand Down
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: # pragma: no cover
__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
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest

from codemodder.cli import parse_args
from codemodder import __VERSION__
from codemodder import __version__
from codemodder.registry import load_registered_codemods


Expand Down Expand Up @@ -61,7 +61,7 @@ def test_version_is_printed(self, mock_print_msg, cli_args):
with pytest.raises(SystemExit) as err:
parse_args(cli_args, self.registry)

assert mock_print_msg.call_args_list[0][0][0].strip() == __VERSION__
assert mock_print_msg.call_args_list[0][0][0].strip() == __version__
assert err.value.args[0] == 0

@pytest.mark.parametrize(
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 4dce8ee

Please sign in to comment.