Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use setuptools_scm to implement tag-based versioning #110

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Install Dependencies
run: pip install -r requirements/lint.txt
- name: Black Format Check
run: black --check . --exclude samples/
run: black --check .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure this is what we want? Changing the format of our samples can have some unintended effects on some codemods.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now excluded in pyproject.toml since that affects all environments and not just GitHub actions.

- name: Run pylint
run: make lint

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
15 changes: 13 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,17 @@ 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"]

[tool.black]
extend-exclude = '''
/(
tests/samples |
src/codemodder/_version.py
)/
'''
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"