Skip to content

Commit

Permalink
add --version (fixes #173) (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored May 13, 2023
1 parent 2345076 commit 721f5fa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -46,7 +49,7 @@ changelog = "https://github.com/jameslamb/pydistcheck/releases"
[build-system]

requires = [
"setuptools>=63",
"setuptools>=67",
]
build-backend = "setuptools.build_meta"

Expand Down
2 changes: 2 additions & 0 deletions src/pydistcheck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

# no one should be importing from this package
__all__ = [] # type: ignore

__version__ = "0.4.0.99"
13 changes: 13 additions & 0 deletions src/pydistcheck/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import click

from pydistcheck import __version__ as _VERSION
from pydistcheck.checks import (
ALL_CHECKS,
_CompiledObjectsDebugSymbolCheck,
Expand All @@ -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),
Expand Down Expand Up @@ -115,6 +123,7 @@
)
def check( # pylint: disable=too-many-arguments
filepaths: str,
version: bool,
config: str,
ignore: str,
inspect: bool,
Expand All @@ -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()
Expand Down
17 changes: 17 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 721f5fa

Please sign in to comment.