Skip to content

Commit

Permalink
Added functionality to display current version (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Maas authored Sep 7, 2022
1 parent 604ddd8 commit 806f948
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions deptry/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

from deptry.config import Config
from deptry.core import Core
from deptry.utils import run_within_dir
from deptry.utils import import_importlib_metadata, run_within_dir


@click.command()
@click.argument("directory", type=click.Path(exists=True))
@click.argument("directory", type=click.Path(exists=True), required=False)
@click.option(
"--verbose",
"-v",
Expand Down Expand Up @@ -69,6 +69,11 @@
is_flag=True,
help="Boolean flag to specify if notebooks should be ignored while scanning for imports.",
)
@click.option(
"--version",
is_flag=True,
help="Display the current version and exit.",
)
def deptry(
directory: pathlib.Path,
verbose: bool,
Expand All @@ -80,11 +85,21 @@ def deptry(
skip_transitive: bool,
ignore_directories: List[str],
ignore_notebooks: bool,
version: bool,
) -> None:

log_level = logging.DEBUG if verbose else logging.INFO
logging.basicConfig(level=log_level, handlers=[logging.StreamHandler()], format="%(message)s")

if version:
display_deptry_version()
sys.exit(0)

if not directory:
logging.warning("Missing argument directory. E.g. `deptry .`")
sys.exit(1)

with run_within_dir(directory):
log_level = logging.DEBUG if verbose else logging.INFO
logging.basicConfig(level=log_level, handlers=[logging.StreamHandler()], format="%(message)s")

# Pass the CLI arguments to Config, if they are provided, otherwise pass 'None'.
# This way, we can distinguish if a argument was actually passed by the user
Expand Down Expand Up @@ -182,3 +197,8 @@ def log_additional_info():
If you have encountered a bug, have a feature request or if you have any other feedback, please file a bug report at https://github.com/fpgmaas/deptry/issues/new/choose.
"""
)


def display_deptry_version():
metadata, *_ = import_importlib_metadata()
logging.info(f'deptry {metadata.version("deptry")}')

0 comments on commit 806f948

Please sign in to comment.