Skip to content

Commit

Permalink
feat(cli): set max terminal width based on terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed Aug 10, 2024
1 parent fb09300 commit d825440
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 8 additions & 1 deletion python/deptry/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import shutil
import sys
from collections import defaultdict
from importlib.metadata import version
Expand Down Expand Up @@ -250,7 +251,7 @@ def display_deptry_version(ctx: click.Context, _param: click.Parameter, value: b
is_flag=True,
help="Enable experimental support for namespace package (PEP 420) when detecting local modules (https://peps.python.org/pep-0420/).",
)
def deptry(
def cli(
root: tuple[Path, ...],
config: Path,
no_ansi: bool,
Expand Down Expand Up @@ -308,3 +309,9 @@ def deptry(
pep621_dev_dependency_groups=pep621_dev_dependency_groups,
experimental_namespace_package=experimental_namespace_package,
).run()


def deptry() -> None:
column_size, _line_size = shutil.get_terminal_size()

Check warning on line 315 in python/deptry/cli.py

View check run for this annotation

Codecov / codecov/patch

python/deptry/cli.py#L315

Added line #L315 was not covered by tests

cli(max_content_width=column_size)

Check warning on line 317 in python/deptry/cli.py

View check run for this annotation

Codecov / codecov/patch

python/deptry/cli.py#L317

Added line #L317 was not covered by tests
4 changes: 2 additions & 2 deletions tests/functional/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from click.testing import CliRunner

from deptry.cli import deptry
from deptry.cli import cli
from tests.functional.utils import Project
from tests.utils import get_issues_report, stylize

Expand Down Expand Up @@ -625,6 +625,6 @@ def test_cli_with_json_output(poetry_venv_factory: PoetryVenvFactory) -> None:


def test_cli_help() -> None:
result = CliRunner().invoke(deptry, "--help")
result = CliRunner().invoke(cli, "--help")

assert result.exit_code == 0
10 changes: 5 additions & 5 deletions tests/unit/deprecate/test_requirements_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from click.testing import CliRunner

from deptry.cli import deptry
from deptry.cli import cli
from deptry.deprecate.requirements_txt import (
REQUIREMENTS_TXT_DEPRECATION_MESSAGE,
REQUIREMENTS_TXT_DEV_DEPRECATION_MESSAGE,
Expand All @@ -31,7 +31,7 @@

def test_requirements_txt_deprecated() -> None:
with patch("deptry.cli.Core") as mock_core, patch("logging.warning") as mock_warning:
result = CliRunner().invoke(deptry, [".", "--requirements-txt", "somefile.txt"])
result = CliRunner().invoke(cli, [".", "--requirements-txt", "somefile.txt"])

assert result.exit_code == 0
mock_warning.assert_called_once_with(REQUIREMENTS_TXT_DEPRECATION_MESSAGE)
Expand All @@ -46,7 +46,7 @@ def test_requirements_txt_deprecated() -> None:

def test_requirements_txt_dev_deprecated() -> None:
with patch("deptry.cli.Core") as mock_core, patch("logging.warning") as mock_warning:
result = CliRunner().invoke(deptry, [".", "--requirements-txt-dev", "somefile.txt"])
result = CliRunner().invoke(cli, [".", "--requirements-txt-dev", "somefile.txt"])

assert result.exit_code == 0
mock_warning.assert_called_once_with(REQUIREMENTS_TXT_DEV_DEPRECATION_MESSAGE)
Expand All @@ -59,7 +59,7 @@ def test_requirements_txt_dev_deprecated() -> None:

def test_requirements_files_works_as_expected() -> None:
with patch("deptry.cli.Core") as mock_core, patch("logging.warning") as mock_warning:
result = CliRunner().invoke(deptry, [".", "--requirements-files", "somefile.txt"])
result = CliRunner().invoke(cli, [".", "--requirements-files", "somefile.txt"])

assert result.exit_code == 0
mock_warning.assert_not_called()
Expand All @@ -74,7 +74,7 @@ def test_requirements_files_works_as_expected() -> None:

def test_requirements_files_dev_works_as_expected() -> None:
with patch("deptry.cli.Core") as mock_core, patch("logging.warning") as mock_warning:
result = CliRunner().invoke(deptry, [".", "--requirements-files-dev", "somefile.txt"])
result = CliRunner().invoke(cli, [".", "--requirements-files-dev", "somefile.txt"])

assert result.exit_code == 0
mock_warning.assert_not_called()
Expand Down

0 comments on commit d825440

Please sign in to comment.