diff --git a/.coveragerc b/.coveragerc index 7ad0266..bbecf7c 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,2 +1,4 @@ [run] -omit = pip_tree/cli.py +omit = + pip_tree/cli.py + pip_tree/_version.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a4cfa5..d00649c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v3.1.0 (2023-08-24) + +- Adds `--version` flag + ## v3.0.0 (2023-07-01) - Drop support for Python 3.7 diff --git a/pip_tree/_version.py b/pip_tree/_version.py new file mode 100644 index 0000000..7f5601d --- /dev/null +++ b/pip_tree/_version.py @@ -0,0 +1 @@ +__version__ = '3.1.0' diff --git a/pip_tree/cli.py b/pip_tree/cli.py index 628f661..457e365 100644 --- a/pip_tree/cli.py +++ b/pip_tree/cli.py @@ -2,6 +2,7 @@ import json import pip_tree +from pip_tree._version import __version__ class PipTreeCli: @@ -20,6 +21,11 @@ def __init__(self): ' the virtual environment Pip Tree is run from will be used.' ), ) + parser.add_argument( + '--version', + action='version', + version=f'%(prog)s {__version__}', + ) parser.parse_args(namespace=self) def generate_console_output(self): diff --git a/setup.py b/setup.py index f8d0107..1a28ebb 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,18 @@ +import re + import setuptools -with open('README.md', 'r') as fh: - long_description = fh.read() +with open('README.md', 'r') as readme_file: + long_description = readme_file.read() + +# Inspiration: https://stackoverflow.com/a/7071358/6064135 +with open('pip_tree/_version.py', 'r') as version_file: + version_groups = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file.read(), re.M) + if version_groups: + version = version_groups.group(1) + else: + raise RuntimeError('Unable to find version string!') DEV_REQUIREMENTS = [ 'bandit == 1.7.*', @@ -10,7 +20,7 @@ 'build == 0.10.*', 'flake8 == 6.*', 'isort == 5.*', - 'mypy == 1.3.*', + 'mypy == 1.5.*', 'pytest == 7.*', 'pytest-cov == 4.*', 'twine == 4.*', @@ -19,7 +29,7 @@ setuptools.setup( name='pip-tree', - version='3.0.0', + version=version, description='Get the dependency tree of your Python virtual environment via Pip.', long_description=long_description, long_description_content_type="text/markdown",