From 4644fcf11e114a643a35244d6605501bbfa002ec Mon Sep 17 00:00:00 2001 From: Maria Knorps Date: Tue, 25 Jul 2023 11:33:50 +0200 Subject: [PATCH] ADD CLI option for --install-deps --- README.md | 2 ++ fawltydeps/cli_parser.py | 9 +++++++++ tests/test_cmdline.py | 24 ++++++++++++++++++++++++ tests/test_cmdline_options.py | 2 +- tests/test_settings.py | 2 +- 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a375723..0d8bad9b 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,8 @@ Here is a complete list of configuration directives we support: declared dependencies. Must be one of `"requirements.txt"`, `"setup.py"`, `"setup.cfg"`, `"pyproject.toml"`, or leave it unset (i.e. the default) for auto-detection (based on filename). +- `install-deps`: Install Python dependencies gathered with FawltyDeps to + a temporary virtual environment. Dependencies will be installed from PyPI. - `verbosity`: An integer controlling the default log level of FawltyDeps: - `-2`: Only `CRITICAL`-level log messages are shown. - `-1`: `ERROR`-level log messages and above are shown. diff --git a/fawltydeps/cli_parser.py b/fawltydeps/cli_parser.py index 1ffffe5f..4ea49bc8 100644 --- a/fawltydeps/cli_parser.py +++ b/fawltydeps/cli_parser.py @@ -171,6 +171,15 @@ def populate_parser_paths_options(parser: argparse._ActionsContainer) -> None: " Python environment where FawltyDeps is installed." ), ) + parser.add_argument( + "--install-deps", + dest="install_deps", + action="store_true", + help=( + "Allow FawltyDeps to `pip install` declared dependencies into a" + " separate temporary virtualenv to discover the imports they expose." + ), + ) parser.add_argument( "--custom-mapping-file", nargs="+", diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 3586bbee..0ff4991f 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -910,6 +910,30 @@ def test_cmdline_on_ignored_undeclared_option( ).splitlines(), id="generate_toml_config_with_multiple_pyenvs", ), + pytest.param( + {}, + ["--install-deps", "--generate-toml-config"], + dedent( + """\ + # Copy this TOML section into your pyproject.toml to configure FawltyDeps + # (default values are commented) + [tool.fawltydeps] + # actions = ['check_undeclared', 'check_unused'] + # output_format = 'human_summary' + # code = ['.'] + # deps = ['.'] + # pyenvs = [] + # ignore_undeclared = [] + # ignore_unused = [] + # deps_parser_choice = ... + install_deps = true + # verbosity = 0 + # custom_mapping_file = [] + # [tool.fawltydeps.custom_mapping] + """ + ).splitlines(), + id="generate_toml_config_with_install_deps", + ), ], ) def test_cmdline_args_in_combination_with_config_file( diff --git a/tests/test_cmdline_options.py b/tests/test_cmdline_options.py index 95a66417..f0b58d01 100644 --- a/tests/test_cmdline_options.py +++ b/tests/test_cmdline_options.py @@ -60,7 +60,7 @@ """ ) venvs = [str(project_with_no_issues / ".venv")] -other = ["--generate-toml-file", "--version"] +other = ["--generate-toml-config", "--version", "--install-deps"] # Options below contain paths specific for an input project diff --git a/tests/test_settings.py b/tests/test_settings.py index c9ca26c8..905dad06 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -28,7 +28,6 @@ code={Path(".")}, deps={Path(".")}, pyenvs=set(), - custom_mapping_file=set(), custom_mapping=None, output_format=OutputFormat.HUMAN_SUMMARY, ignore_undeclared=set(), @@ -36,6 +35,7 @@ deps_parser_choice=None, install_deps=False, verbosity=0, + custom_mapping_file=set(), )