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
10 changes: 7 additions & 3 deletions deptry/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@ def convert(
COMMA_SEPARATED_TUPLE = CommaSeparatedTupleParamType()


def configure_logger(ctx: click.Context, _param: click.Parameter, value: bool) -> None:
log_level = logging.DEBUG if value else logging.INFO
logging.basicConfig(level=log_level, handlers=[logging.StreamHandler()], format="%(message)s")


@click.command()
@click.argument("root", type=click.Path(exists=True), required=False)
@click.option(
"--verbose",
"-v",
is_flag=True,
help="Boolean flag for verbosity. Using this flag will display more information about files, imports and dependencies while running.",
is_eager=True,
callback=configure_logger,
)
@click.option(
"--skip-obsolete",
Expand Down Expand Up @@ -190,9 +197,6 @@ def deptry(

"""

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)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ def test_cli_extend_exclude(dir_with_venv_installed):
assert "The project contains obsolete dependencies:\n\n\tisort\n\trequests\n\ttoml\n\n" in result.stderr


def test_cli_verbose(dir_with_venv_installed):
with run_within_dir(str(dir_with_venv_installed)):
result = subprocess.run(shlex.split("poetry run deptry . "), capture_output=True, text=True)
assert result.returncode == 1
assert not "The project contains the following dependencies:" in result.stderr

with run_within_dir(str(dir_with_venv_installed)):
result = subprocess.run(shlex.split("poetry run deptry . -v "), capture_output=True, text=True)
assert result.returncode == 1
assert "The project contains the following dependencies:" in result.stderr


def test_cli_with_json_output(dir_with_venv_installed):
with run_within_dir(str(dir_with_venv_installed)):

Expand Down