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..02dcdb8d 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 = [] + # custom_mapping_file = [] + # ignore_undeclared = [] + # ignore_unused = [] + # deps_parser_choice = ... + install_deps = true + # verbosity = 0 + # [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..8a100faf 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-file", "--version", "--install-deps"] # Options below contain paths specific for an input project @@ -87,6 +87,7 @@ def available_deps_values(project_dir: Path) -> List[str]: output_formats_strategy = st.lists( st.sampled_from(output_formats), min_size=0, max_size=1 ) +others_strategy = st.lists(st.sampled_from(other), min_size=0, max_size=1) def code_option_strategy(paths: List[str]): @@ -167,6 +168,7 @@ def cli_arguments_combinations(draw): deps_parser, draw(verbosity_strategy), draw(venv_strategy), + draw(others_strategy), ] ) args = reduce(lambda x, y: x + y, draw(strategy)) 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(), )