Skip to content

Commit

Permalink
fixed issue with logging if no [tool.deptry] section was found in pyp… (
Browse files Browse the repository at this point in the history
#134)

* fixed issue with logging if no [tool.deptry] section was found in pyproject.toml

Co-authored-by: Florian Maas <[email protected]>
  • Loading branch information
Florian Maas and fpgmaas authored Sep 26, 2022
1 parent f387cbb commit aadd63e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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

0 comments on commit aadd63e

Please sign in to comment.