Skip to content
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
26 changes: 25 additions & 1 deletion fawltydeps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)


Expand All @@ -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."""
Expand Down Expand Up @@ -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",
Comment thread
jherland marked this conversation as resolved.
version=f"FawltyDeps v{version()}",
help=("Print the version number of FawltyDeps"),
)
select_action.add_argument(
"--check-undeclared",
dest="actions",
Expand Down
25 changes: 11 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down