diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 00ca941..ecd7ec7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,4 +20,4 @@ make build install - ensure that the tag that'll be created matches the version number, in the form `v{major}.{minor}.{patch}` 4. click "publish" - when that happens, CI jobs will run that automatically publish the package to PyPI. -5. Open another pull request with title `bump development version` adding `.99` to the version in `pyproject.toml`. +5. Open another pull request with title `bump development version` adding `.99` to the version in `src/pydistcheck/__init__.py`. diff --git a/pyproject.toml b/pyproject.toml index 268fa24..48832ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,10 @@ maintainers = [ name = "pydistcheck" readme = "README.md" requires-python = ">=3.8" -version = "0.4.0.99" +dynamic = ["version"] + +[tool.setuptools.dynamic] +version = {attr = "pydistcheck.__version__"} [project.scripts] pydistcheck = "pydistcheck.cli:check" @@ -46,7 +49,7 @@ changelog = "https://github.com/jameslamb/pydistcheck/releases" [build-system] requires = [ - "setuptools>=63", + "setuptools>=67", ] build-backend = "setuptools.build_meta" diff --git a/src/pydistcheck/__init__.py b/src/pydistcheck/__init__.py index 2d0de63..86c4d2e 100644 --- a/src/pydistcheck/__init__.py +++ b/src/pydistcheck/__init__.py @@ -2,3 +2,5 @@ # no one should be importing from this package __all__ = [] # type: ignore + +__version__ = "0.4.0.99" diff --git a/src/pydistcheck/cli.py b/src/pydistcheck/cli.py index f70a718..4d91f8e 100644 --- a/src/pydistcheck/cli.py +++ b/src/pydistcheck/cli.py @@ -7,6 +7,7 @@ import click +from pydistcheck import __version__ as _VERSION from pydistcheck.checks import ( ALL_CHECKS, _CompiledObjectsDebugSymbolCheck, @@ -31,6 +32,13 @@ type=click.Path(exists=True), nargs=-1, ) +@click.option( + "--version", + is_flag=True, + show_default=False, + default=False, + help="Print the version of pydistcheck and exit.", +) @click.option( "--config", type=click.Path(exists=True), @@ -115,6 +123,7 @@ ) def check( # pylint: disable=too-many-arguments filepaths: str, + version: bool, config: str, ignore: str, inspect: bool, @@ -128,6 +137,10 @@ def check( # pylint: disable=too-many-arguments Run the contents of a distribution through a set of checks, and warn about any problematic characteristics that are detected. """ + if version: + print(f"pydistcheck {_VERSION}") + sys.exit(0) + print("==================== running pydistcheck ====================") filepaths_to_check = [click.format_filename(f) for f in filepaths] conf = _Config() diff --git a/tests/test_cli.py b/tests/test_cli.py index 7efea80..06d35d5 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -40,6 +40,23 @@ def test_check_runs_without_error(distro_file): assert result.exit_code == 0 +def test_version_flag_works(): + runner = CliRunner() + result = runner.invoke( + check, + [ + "--version", + ], + ) + assert result.exit_code == 0 + + _assert_log_matches_pattern( + result=result, + pattern=(r"^pydistcheck [0-9]{1}\.[0-9]{1,2}\.[0-9]{1,2}\.*[0-9]*$"), + num_times=1, + ) + + def test_check_fails_with_informative_error_if_file_doesnt_exist(): runner = CliRunner() result = runner.invoke(check, ["some-garbage.exe"])