From 03617d279fe89d6c3895a528b798783a6d2e08f4 Mon Sep 17 00:00:00 2001 From: Dominic Davis-Foster Date: Fri, 12 Jan 2024 12:21:48 +0000 Subject: [PATCH] Fix venv handling in `show requirements` --- repo_helper/cli/commands/show.py | 12 +++++------- requirements.txt | 2 +- .../test_cli/test_show_/test_requirements_3_10_.tree | 2 +- .../test_show_/test_requirements_3_11__.tree | 2 +- .../test_cli/test_show_/test_requirements_3_6_.tree | 2 +- .../test_cli/test_show_/test_requirements_3_7_.tree | 2 +- .../test_cli/test_show_/test_requirements_3_8_.tree | 2 +- .../test_cli/test_show_/test_requirements_3_9_.tree | 2 +- .../test_show_/test_requirements_concise_3_10_.tree | 2 +- .../test_show_/test_requirements_concise_3_11__.tree | 2 +- .../test_show_/test_requirements_concise_3_6_.tree | 2 +- .../test_show_/test_requirements_concise_3_7_.tree | 2 +- .../test_show_/test_requirements_concise_3_8_.tree | 2 +- .../test_show_/test_requirements_concise_3_9_.tree | 2 +- .../test_show_/test_requirements_no_pager_3_10_.tree | 2 +- .../test_requirements_no_pager_3_11__.tree | 2 +- .../test_show_/test_requirements_no_pager_3_6_.tree | 2 +- .../test_show_/test_requirements_no_pager_3_7_.tree | 2 +- .../test_show_/test_requirements_no_pager_3_8_.tree | 2 +- .../test_show_/test_requirements_no_pager_3_9_.tree | 2 +- 20 files changed, 24 insertions(+), 26 deletions(-) diff --git a/repo_helper/cli/commands/show.py b/repo_helper/cli/commands/show.py index b0f35f63..4c73f308 100644 --- a/repo_helper/cli/commands/show.py +++ b/repo_helper/cli/commands/show.py @@ -24,6 +24,7 @@ # # stdlib +import sys from datetime import datetime from functools import partial from typing import Iterable, List, Optional, Union @@ -212,7 +213,6 @@ def requirements( import shutil # 3rd party - from domdf_python_tools.compat import importlib_metadata from domdf_python_tools.iterative import make_tree from domdf_python_tools.paths import PathPlus, in_directory from domdf_python_tools.stringlist import StringList @@ -237,15 +237,14 @@ def requirements( tree: List[Union[str, List[str], List[Union[str, List]]]] = [] venv_dir = (rh.target_repo / "venv") + search_path = sys.path + if venv_dir.is_dir() and not no_venv: # Use virtualenv as it exists search_path = [] for directory in (venv_dir / "lib").glob("python3.*"): search_path.append(str(directory / "site-packages")) - - importlib_metadata.DistributionFinder.Context.path = search_path # type: ignore[assignment] - if concise: concise_requirements = [] @@ -258,8 +257,7 @@ def flatten(iterable: Iterable[Union[Requirement, Iterable]]): for requirement in raw_requirements: concise_requirements.append(requirement) - # TODO: remove "extra == " marker - for req in flatten(list_requirements(str(requirement), depth=depth - 1)): + for req in flatten(list_requirements(str(requirement), depth=depth - 1, path=search_path)): concise_requirements.append(ComparableRequirement(re.sub('; extra == ".*"', '', req))) concise_requirements = sorted(set(combine_requirements(concise_requirements))) @@ -268,7 +266,7 @@ def flatten(iterable: Iterable[Union[Requirement, Iterable]]): else: for requirement in raw_requirements: tree.append(str(requirement)) - deps = list(list_requirements(str(requirement), depth=depth - 1)) + deps = list(list_requirements(str(requirement), depth=depth - 1, path=search_path)) if deps: tree.append(deps) diff --git a/requirements.txt b/requirements.txt index ee76d3ab..2b9ce845 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ natsort>=7.1.1 packaging>=20.9 pypi-json>=0.2.1 ruamel.yaml>=0.17.4 -shippinglabel>=1.6.0 +shippinglabel>=1.7.1 shippinglabel-conda>=0.1.0 southwark>=0.7.1 tabulate>=0.8.8 diff --git a/tests/test_cli/test_show_/test_requirements_3_10_.tree b/tests/test_cli/test_show_/test_requirements_3_10_.tree index 16e72eda..51b56b99 100644 --- a/tests/test_cli/test_show_/test_requirements_3_10_.tree +++ b/tests/test_cli/test_show_/test_requirements_3_10_.tree @@ -483,7 +483,7 @@ repo_helper==2020.12.18 │ └── urllib3<3,>=1.21.1 ├── ruamel.yaml>=0.17.4 │ └── ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_3_11__.tree b/tests/test_cli/test_show_/test_requirements_3_11__.tree index affdbdaf..8ce7c7f3 100644 --- a/tests/test_cli/test_show_/test_requirements_3_11__.tree +++ b/tests/test_cli/test_show_/test_requirements_3_11__.tree @@ -479,7 +479,7 @@ repo_helper==2020.12.18 │ ├── idna<4,>=2.5 │ └── urllib3<3,>=1.21.1 ├── ruamel.yaml>=0.17.4 -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_3_6_.tree b/tests/test_cli/test_show_/test_requirements_3_6_.tree index 63ef43f9..cbe22545 100644 --- a/tests/test_cli/test_show_/test_requirements_3_6_.tree +++ b/tests/test_cli/test_show_/test_requirements_3_6_.tree @@ -830,7 +830,7 @@ repo_helper==2020.12.18 │ └── urllib3<1.27,>=1.21.1 ├── ruamel.yaml>=0.17.4 │ └── ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_3_7_.tree b/tests/test_cli/test_show_/test_requirements_3_7_.tree index 4ba9f4ed..36922bd0 100644 --- a/tests/test_cli/test_show_/test_requirements_3_7_.tree +++ b/tests/test_cli/test_show_/test_requirements_3_7_.tree @@ -700,7 +700,7 @@ repo_helper==2020.12.18 │ └── urllib3<3,>=1.21.1 ├── ruamel.yaml>=0.17.4 │ └── ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_3_8_.tree b/tests/test_cli/test_show_/test_requirements_3_8_.tree index c9f50925..e695b77a 100644 --- a/tests/test_cli/test_show_/test_requirements_3_8_.tree +++ b/tests/test_cli/test_show_/test_requirements_3_8_.tree @@ -610,7 +610,7 @@ repo_helper==2020.12.18 │ └── urllib3<3,>=1.21.1 ├── ruamel.yaml>=0.17.4 │ └── ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_3_9_.tree b/tests/test_cli/test_show_/test_requirements_3_9_.tree index 16e72eda..51b56b99 100644 --- a/tests/test_cli/test_show_/test_requirements_3_9_.tree +++ b/tests/test_cli/test_show_/test_requirements_3_9_.tree @@ -483,7 +483,7 @@ repo_helper==2020.12.18 │ └── urllib3<3,>=1.21.1 ├── ruamel.yaml>=0.17.4 │ └── ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_concise_3_10_.tree b/tests/test_cli/test_show_/test_requirements_concise_3_10_.tree index 578d89b3..4b3d90c3 100644 --- a/tests/test_cli/test_show_/test_requirements_concise_3_10_.tree +++ b/tests/test_cli/test_show_/test_requirements_concise_3_10_.tree @@ -45,7 +45,7 @@ repo_helper==2020.12.18 ├── rpds-py>=0.7.1 ├── ruamel-yaml-clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" ├── ruamel.yaml>=0.17.4 -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 ├── shippinglabel-conda>=0.1.0 ├── shippinglabel-pypi>=0.1.0 ├── six diff --git a/tests/test_cli/test_show_/test_requirements_concise_3_11__.tree b/tests/test_cli/test_show_/test_requirements_concise_3_11__.tree index 3669624b..9d53177c 100644 --- a/tests/test_cli/test_show_/test_requirements_concise_3_11__.tree +++ b/tests/test_cli/test_show_/test_requirements_concise_3_11__.tree @@ -44,7 +44,7 @@ repo_helper==2020.12.18 ├── requests>=2.27.1 ├── rpds-py>=0.7.1 ├── ruamel.yaml>=0.17.4 -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 ├── shippinglabel-conda>=0.1.0 ├── shippinglabel-pypi>=0.1.0 ├── six diff --git a/tests/test_cli/test_show_/test_requirements_concise_3_6_.tree b/tests/test_cli/test_show_/test_requirements_concise_3_6_.tree index 76087543..b8b9bdd4 100644 --- a/tests/test_cli/test_show_/test_requirements_concise_3_6_.tree +++ b/tests/test_cli/test_show_/test_requirements_concise_3_6_.tree @@ -48,7 +48,7 @@ repo_helper==2020.12.18 ├── ruamel-yaml-clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" ├── ruamel.yaml>=0.17.4 ├── setuptools -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 ├── shippinglabel-conda>=0.1.0 ├── shippinglabel-pypi>=0.1.0 ├── six>=1.11.0 diff --git a/tests/test_cli/test_show_/test_requirements_concise_3_7_.tree b/tests/test_cli/test_show_/test_requirements_concise_3_7_.tree index 06674f22..b4c7a098 100644 --- a/tests/test_cli/test_show_/test_requirements_concise_3_7_.tree +++ b/tests/test_cli/test_show_/test_requirements_concise_3_7_.tree @@ -47,7 +47,7 @@ repo_helper==2020.12.18 ├── requests>=2.27.1 ├── ruamel-yaml-clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" ├── ruamel.yaml>=0.17.4 -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 ├── shippinglabel-conda>=0.1.0 ├── shippinglabel-pypi>=0.1.0 ├── six diff --git a/tests/test_cli/test_show_/test_requirements_concise_3_8_.tree b/tests/test_cli/test_show_/test_requirements_concise_3_8_.tree index f3d06bf7..7a2721df 100644 --- a/tests/test_cli/test_show_/test_requirements_concise_3_8_.tree +++ b/tests/test_cli/test_show_/test_requirements_concise_3_8_.tree @@ -48,7 +48,7 @@ repo_helper==2020.12.18 ├── rpds-py>=0.7.1 ├── ruamel-yaml-clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" ├── ruamel.yaml>=0.17.4 -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 ├── shippinglabel-conda>=0.1.0 ├── shippinglabel-pypi>=0.1.0 ├── six diff --git a/tests/test_cli/test_show_/test_requirements_concise_3_9_.tree b/tests/test_cli/test_show_/test_requirements_concise_3_9_.tree index 578d89b3..4b3d90c3 100644 --- a/tests/test_cli/test_show_/test_requirements_concise_3_9_.tree +++ b/tests/test_cli/test_show_/test_requirements_concise_3_9_.tree @@ -45,7 +45,7 @@ repo_helper==2020.12.18 ├── rpds-py>=0.7.1 ├── ruamel-yaml-clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" ├── ruamel.yaml>=0.17.4 -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 ├── shippinglabel-conda>=0.1.0 ├── shippinglabel-pypi>=0.1.0 ├── six diff --git a/tests/test_cli/test_show_/test_requirements_no_pager_3_10_.tree b/tests/test_cli/test_show_/test_requirements_no_pager_3_10_.tree index 16e72eda..51b56b99 100644 --- a/tests/test_cli/test_show_/test_requirements_no_pager_3_10_.tree +++ b/tests/test_cli/test_show_/test_requirements_no_pager_3_10_.tree @@ -483,7 +483,7 @@ repo_helper==2020.12.18 │ └── urllib3<3,>=1.21.1 ├── ruamel.yaml>=0.17.4 │ └── ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_no_pager_3_11__.tree b/tests/test_cli/test_show_/test_requirements_no_pager_3_11__.tree index affdbdaf..8ce7c7f3 100644 --- a/tests/test_cli/test_show_/test_requirements_no_pager_3_11__.tree +++ b/tests/test_cli/test_show_/test_requirements_no_pager_3_11__.tree @@ -479,7 +479,7 @@ repo_helper==2020.12.18 │ ├── idna<4,>=2.5 │ └── urllib3<3,>=1.21.1 ├── ruamel.yaml>=0.17.4 -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_no_pager_3_6_.tree b/tests/test_cli/test_show_/test_requirements_no_pager_3_6_.tree index 63ef43f9..cbe22545 100644 --- a/tests/test_cli/test_show_/test_requirements_no_pager_3_6_.tree +++ b/tests/test_cli/test_show_/test_requirements_no_pager_3_6_.tree @@ -830,7 +830,7 @@ repo_helper==2020.12.18 │ └── urllib3<1.27,>=1.21.1 ├── ruamel.yaml>=0.17.4 │ └── ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_no_pager_3_7_.tree b/tests/test_cli/test_show_/test_requirements_no_pager_3_7_.tree index 4ba9f4ed..36922bd0 100644 --- a/tests/test_cli/test_show_/test_requirements_no_pager_3_7_.tree +++ b/tests/test_cli/test_show_/test_requirements_no_pager_3_7_.tree @@ -700,7 +700,7 @@ repo_helper==2020.12.18 │ └── urllib3<3,>=1.21.1 ├── ruamel.yaml>=0.17.4 │ └── ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_no_pager_3_8_.tree b/tests/test_cli/test_show_/test_requirements_no_pager_3_8_.tree index c9f50925..e695b77a 100644 --- a/tests/test_cli/test_show_/test_requirements_no_pager_3_8_.tree +++ b/tests/test_cli/test_show_/test_requirements_no_pager_3_8_.tree @@ -610,7 +610,7 @@ repo_helper==2020.12.18 │ └── urllib3<3,>=1.21.1 ├── ruamel.yaml>=0.17.4 │ └── ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0 diff --git a/tests/test_cli/test_show_/test_requirements_no_pager_3_9_.tree b/tests/test_cli/test_show_/test_requirements_no_pager_3_9_.tree index 16e72eda..51b56b99 100644 --- a/tests/test_cli/test_show_/test_requirements_no_pager_3_9_.tree +++ b/tests/test_cli/test_show_/test_requirements_no_pager_3_9_.tree @@ -483,7 +483,7 @@ repo_helper==2020.12.18 │ └── urllib3<3,>=1.21.1 ├── ruamel.yaml>=0.17.4 │ └── ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.13" -├── shippinglabel>=1.6.0 +├── shippinglabel>=1.7.1 │ ├── apeye>=1.0.0 │ │ ├── apeye-core>=1.0.0b2 │ │ │ ├── domdf-python-tools>=2.6.0