Skip to content

Commit

Permalink
Fix venv handling in show requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Jan 15, 2024
1 parent 952df6f commit 03617d2
Show file tree
Hide file tree
Showing 20 changed files with 24 additions and 26 deletions.
12 changes: 5 additions & 7 deletions repo_helper/cli/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#

# stdlib
import sys
from datetime import datetime
from functools import partial
from typing import Iterable, List, Optional, Union
Expand Down Expand Up @@ -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
Expand All @@ -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 = []

Expand All @@ -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)))
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_show_/test_requirements_3_10_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_show_/test_requirements_3_11__.tree
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_show_/test_requirements_3_6_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_show_/test_requirements_3_7_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_show_/test_requirements_3_8_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_show_/test_requirements_3_9_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03617d2

Please sign in to comment.