Skip to content

Commit

Permalink
Remove normalize_requires method (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtheturtle committed Oct 30, 2023
1 parent 042a85a commit 9434435
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 41 deletions.
14 changes: 0 additions & 14 deletions src/pyproject_fmt/formatter/pep508.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ def normalize_req(req: str) -> str:
return str(parsed)


def normalize_requires(raws: list[str]) -> list[str]:
"""
Normalize a list of requirements.
:param raws: the raw values
:return: the normalized values
"""
return sorted(
(normalize_req(req) for req in raws if req),
key=lambda req: (";" in req, Requirement(req).name, req),
)


def _best_effort_string_repr(req: str) -> String:
# Convert requirement to a TOML string, choosing the most appropriate representation (basic or literal).
# This function will attempt to use literal strings to avoid escaping double-quotes ("), if the requirement value
Expand Down Expand Up @@ -70,7 +57,6 @@ def normalize_pep508_array(requires_array: Array | None, indent: int) -> None:


__all__ = [
"normalize_requires",
"normalize_req",
"normalize_pep508_array",
]
47 changes: 20 additions & 27 deletions tests/formatter/test_pep508.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,35 @@

import pytest

from pyproject_fmt.formatter.pep508 import normalize_req, normalize_requires
from pyproject_fmt.formatter.pep508 import normalize_req


@pytest.mark.parametrize(
("value", "result"),
[
("", []),
("\t", []),
("\n\t\n", []),
("b\na\n", ["a", "b"]),
("a\nb\n", ["a", "b"]),
("A\na\n", ["A", "a"]),
("\nA\n\n\nb\n\n", ["A", "b"]),
("a", "a"),
('packaging>=20.0;python_version>"3.4"', 'packaging>=20; python_version > "3.4"'),
(
'packaging>=20.0;python_version>"3.4"\n'
"xonsh>=0.9.16;python_version > '3.4' and python_version != '3.9'\n"
"pytest-xdist>=1.31.0\n"
"foo@http:https://foo.com\n"
"bar [fred,al] @ http:https://bat.com ;python_version=='2.7'\n"
"baz [quux, strange];python_version<\"2.7\" and platform_version=='2'\n",
[
"foo@ http:https://foo.com",
"pytest-xdist>=1.31",
'bar[al,fred]@ http:https://bat.com ; python_version == "2.7"',
'baz[quux,strange]; python_version < "2.7" and platform_version == "2"',
'packaging>=20; python_version > "3.4"',
'xonsh>=0.9.16; python_version > "3.4" and python_version != "3.9"',
],
"xonsh>=0.9.16;python_version>'3.4' and python_version!='3.9'",
'xonsh>=0.9.16; python_version > "3.4" and python_version != "3.9"',
),
("pytest>=6.0.0", ["pytest>=6"]),
("pytest==6.0.0", ["pytest==6"]),
("pytest~=6.0.0", ["pytest~=6.0.0"]),
("pytest-xdist>=1.31.0", "pytest-xdist>=1.31"),
("foo@http:https://foo.com", "foo@ http:https://foo.com"),
(
"bar [fred,al] @ http:https://bat.com ;python_version=='2.7'",
'bar[al,fred]@ http:https://bat.com ; python_version == "2.7"',
),
(
"baz [quux, strange];python_version<\"2.7\" and platform_version=='2'",
'baz[quux,strange]; python_version < "2.7" and platform_version == "2"',
),
("pytest>=6.0.0", "pytest>=6"),
("pytest==6.0.0", "pytest==6"),
("pytest~=6.0.0", "pytest~=6.0.0"),
],
)
def test_requires_fmt(value: str, result: list[str]) -> None:
outcome = normalize_requires([i.strip() for i in value.splitlines() if i.strip()])
def test_requires_fmt(value: str, result: str) -> None:
outcome = normalize_req(req=value)
assert outcome == result


Expand Down

0 comments on commit 9434435

Please sign in to comment.