Skip to content

Commit

Permalink
Use pip_requirements_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed May 28, 2023
1 parent bf90ef0 commit edb87ff
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 955 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
- id: mypy
args: ["--strict"]
exclude: '^(docs|tasks|tests)|setup\.py'
additional_dependencies: ["httpx", "packaging", "typer>=0.3.2"]
additional_dependencies: ["packaging", "typer>=0.3.2"]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.270
Expand Down
2 changes: 2 additions & 0 deletions news/107.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use `pip-requirements-parser <https://pypi.org/project/pip-requirements-parser/>`_
instead of our own copy of pip's parser.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ classifiers = [
]
requires-python = ">=3.7"
dependencies=[
"httpx",
"packaging>=23",
"pip-requirements-parser",
"tomli ; python_version<'3.11'",
"typer[all]>=0.3.2",
"typing-extensions ; python_version<'3.8'", # for Protocol, TypedDict
Expand Down
22 changes: 9 additions & 13 deletions src/pip_deepfreeze/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from packaging.utils import NormalizedName
from packaging.version import Version
from pip_requirements_parser import RequirementsFile # type: ignore[import]

from .compat import TypedDict, shlex_join
from .installed_dist import (
Expand All @@ -17,11 +18,6 @@
list_installed_depends_by_extra,
)
from .project_name import get_project_name
from .req_file_parser import (
NestedRequirementsLine,
RequirementLine,
parse as parse_req_file,
)
from .req_parser import get_req_name
from .sanity import get_pip_version
from .utils import (
Expand Down Expand Up @@ -73,14 +69,14 @@ def pip_upgrade_project(
"""
# 1. parse constraints
constraint_reqs = {}
for req_line in parse_req_file(
str(constraints_filename), recurse=False, reqs_only=False
):
assert not isinstance(req_line, NestedRequirementsLine)
if isinstance(req_line, RequirementLine):
req_name = get_req_name(req_line.requirement)
assert req_name # XXX user error instead?
constraint_reqs[req_name] = normalize_req_line(req_line.requirement)
parsed_constraints_file = RequirementsFile.from_file(
str(constraints_filename), include_nested=False
)
for constraint_req in parsed_constraints_file.requirements:
assert constraint_req.name # XXX user error instead?
constraint_reqs[constraint_req.name] = normalize_req_line(
constraint_req.requirement_line.line
)
# 2. get installed frozen dependencies of project
installed_reqs = {
get_req_name(req_line): normalize_req_line(req_line)
Expand Down
Loading

0 comments on commit edb87ff

Please sign in to comment.