diff --git a/fawltydeps/main.py b/fawltydeps/main.py index 852f45d7..bef5bc12 100644 --- a/fawltydeps/main.py +++ b/fawltydeps/main.py @@ -7,7 +7,7 @@ from enum import Enum, auto from operator import attrgetter from pathlib import Path -from typing import List, Optional, Set, TextIO +from typing import List, Optional, Set, TextIO, no_type_check from fawltydeps import extract_imports from fawltydeps.check import compare_imports_to_dependencies @@ -21,6 +21,12 @@ UnusedDependency, ) +if sys.version_info >= (3, 8): + import importlib.metadata as importlib_metadata +else: + import importlib_metadata + + logger = logging.getLogger(__name__) @@ -33,6 +39,17 @@ class Action(Enum): REPORT_UNUSED = auto() +@no_type_check +def version() -> str: + """Returns the version of fawltydeps.""" + + # This function is extracted to allow annotation with `@no_type_check`. + # Using `#type: ignore` on the line below leads to an + # "unused type ignore comment" MyPy error in python's version 3.8 and + # higher. + return str(importlib_metadata.version("fawltydeps")) + + @dataclass class Analysis: """Result from FawltyDeps analysis, to be presented to the user.""" @@ -132,6 +149,13 @@ def main() -> int: const={Action.REPORT_UNDECLARED, Action.REPORT_UNUSED}, help="Report both undeclared and unused dependencies", ) + parser.add_argument( + "-V", + "--version", + action="version", + version=f"FawltyDeps v{version()}", + help=("Print the version number of FawltyDeps"), + ) select_action.add_argument( "--check-undeclared", dest="actions", diff --git a/poetry.lock b/poetry.lock index 0eda9ece..74403f21 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,13 +1,10 @@ [[package]] name = "argcomplete" -version = "2.0.0" +version = "1.10.3" description = "Bash tab completion for argparse" category = "dev" optional = false -python-versions = ">=3.6" - -[package.dependencies] -importlib-metadata = {version = ">=0.23,<5", markers = "python_version == \"3.7\""} +python-versions = "*" [package.extras] test = ["coverage", "flake8", "pexpect", "wheel"] @@ -158,9 +155,9 @@ testing = ["covdefaults (>=2.2.2)", "coverage (>=7.0.1)", "pytest (>=7.2)", "pyt [[package]] name = "importlib-metadata" -version = "4.13.0" +version = "5.2.0" description = "Read metadata from Python packages" -category = "dev" +category = "main" optional = false python-versions = ">=3.7" @@ -169,7 +166,7 @@ typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} zipp = ">=0.5" [package.extras] -docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)"] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] perf = ["ipython"] testing = ["flake8 (<5)", "flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)"] @@ -432,7 +429,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" name = "zipp" version = "3.11.0" description = "Backport of pathlib-compatible object wrapper for zip files" -category = "dev" +category = "main" optional = false python-versions = ">=3.7" @@ -443,12 +440,12 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "1.1" python-versions = "^3.7.2" -content-hash = "cca7500c5ae2dae19f39740be5ded33c3c048ed5acd4898cccbbf55aeb2626bf" +content-hash = "a4f2d1af4030c992db990af6d33127f8cba91e3198b784b3fd4516fd51357b81" [metadata.files] argcomplete = [ - {file = "argcomplete-2.0.0-py2.py3-none-any.whl", hash = "sha256:cffa11ea77999bb0dd27bb25ff6dc142a6796142f68d45b1a26b11f58724561e"}, - {file = "argcomplete-2.0.0.tar.gz", hash = "sha256:6372ad78c89d662035101418ae253668445b391755cfe94ea52f1b9d22425b20"}, + {file = "argcomplete-1.10.3-py2.py3-none-any.whl", hash = "sha256:d8ea63ebaec7f59e56e7b2a386b1d1c7f1a7ae87902c9ee17d377eaa557f06fa"}, + {file = "argcomplete-1.10.3.tar.gz", hash = "sha256:a37f522cf3b6a34abddfedb61c4546f60023b3799b22d1cd971eacdc0861530a"}, ] astroid = [ {file = "astroid-2.13.3-py3-none-any.whl", hash = "sha256:14c1603c41cc61aae731cad1884a073c4645e26f126d13ac8346113c95577f3b"}, @@ -505,8 +502,8 @@ filelock = [ {file = "filelock-3.9.0.tar.gz", hash = "sha256:7b319f24340b51f55a2bf7a12ac0755a9b03e718311dac567a0f4f7fabd2f5de"}, ] importlib-metadata = [ - {file = "importlib_metadata-4.13.0-py3-none-any.whl", hash = "sha256:8a8a81bcf996e74fee46f0d16bd3eaa382a7eb20fd82445c3ad11f4090334116"}, - {file = "importlib_metadata-4.13.0.tar.gz", hash = "sha256:dd0173e8f150d6815e098fd354f6414b0f079af4644ddfe90c71e2fc6174346d"}, + {file = "importlib_metadata-5.2.0-py3-none-any.whl", hash = "sha256:0eafa39ba42bf225fc00e67f701d71f85aead9f878569caf13c3724f704b970f"}, + {file = "importlib_metadata-5.2.0.tar.gz", hash = "sha256:404d48d62bba0b7a77ff9d405efd91501bef2e67ff4ace0bed40a0cf28c3c7cd"}, ] iniconfig = [ {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, diff --git a/pyproject.toml b/pyproject.toml index edf554ce..e441ee62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ fawltydeps = "fawltydeps.main:main" # These are the main dependencies for fawltydeps at runtime. # Do not add anything here that is only needed by CI/tests/linters/developers python = "^3.7.2" +importlib_metadata = {version = "^5.0.0", python = "<3.8"} isort = "^5.10" tomli = {version = "^2.0.1", python = "<3.11"} typing-extensions = {version = "^4.4.0", python = "<3.8"}