Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move requirement-normalization logic to utils.py
  • Loading branch information
AlexWaygood committed Dec 27, 2022
commit dd7a229b0d9d29578ad54a28c60542f4897e8430
6 changes: 1 addition & 5 deletions tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from typing_extensions import Annotated, TypeAlias

import tomli
from packaging.requirements import Requirement
from utils import (
VERSIONS_RE as VERSION_LINE_RE,
PackageDependencies,
Expand Down Expand Up @@ -397,10 +396,7 @@ def setup_virtual_environments(distributions: dict[str, PackageDependencies], ar
for distribution_name, requirements in distributions.items():
if requirements.external_pkgs:
num_pkgs_with_external_reqs += 1
# convert to Requirement and then back to str
# to make sure that the requirements all have a normalised string representation
# (This will also catch any malformed requirements early)
external_requirements = frozenset(str(Requirement(pkg)) for pkg in requirements.external_pkgs)
external_requirements = frozenset(requirements.external_pkgs)
external_requirements_to_distributions[external_requirements].append(distribution_name)
else:
_DISTRIBUTION_TO_VENV_MAPPING[distribution_name] = no_external_dependencies_venv
Expand Down
5 changes: 4 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ def read_dependencies(distribution: str) -> PackageDependencies:
if maybe_typeshed_dependency in pypi_name_to_typeshed_name_mapping:
typeshed.append(pypi_name_to_typeshed_name_mapping[maybe_typeshed_dependency])
else:
external.append(dependency)
# convert to Requirement and then back to str
# to make sure that the requirements all have a normalised string representation
# (This will also catch any malformed requirements early)
external.append(str(Requirement(dependency)))
return PackageDependencies(tuple(typeshed), tuple(external))


Expand Down