Skip to content

Commit

Permalink
migrate another pkg_resources usage (#22043)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdyas authored Mar 5, 2025
1 parent 4c8696c commit 1208403
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/python/pants/backend/openapi/sample/resources.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import importlib.resources as pkg_resources
import importlib.resources

from pants.backend.openapi import sample

PETSTORE_SAMPLE_SPEC = pkg_resources.read_text(sample.__name__, "petstore_spec.yaml")
PETSTORE_SAMPLE_SPEC = (
importlib.resources.files(sample.__name__).joinpath("petstore_spec.yaml").read_text()
)
8 changes: 3 additions & 5 deletions src/python/pants/backend/python/util_rules/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import packaging.specifiers
import packaging.version
from pkg_resources import Requirement
from packaging.requirements import Requirement

from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import (
Expand Down Expand Up @@ -1319,7 +1319,7 @@ class PexDistributionInfo:
version: packaging.version.Version
requires_python: packaging.specifiers.SpecifierSet | None
# Note: These are parsed from metadata written by the pex tool, and are always
# a valid pkg_resources.Requirement.
# a valid packaging.requirements.Requirement.
requires_dists: tuple[Requirement, ...]


Expand Down Expand Up @@ -1353,9 +1353,7 @@ def iter_dist_info() -> Iterator[PexDistributionInfo]:
if requires_python is not None
else None
),
requires_dists=tuple(
Requirement.parse(req) for req in sorted(info["requires_dists"])
),
requires_dists=tuple(Requirement(req) for req in sorted(info["requires_dists"])),
)

return PexResolveInfo(sorted(iter_dist_info(), key=lambda dist: dist.project_name))
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/python/util_rules/pex_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

import pytest
import requests
from packaging.requirements import Requirement
from packaging.specifiers import SpecifierSet
from packaging.version import Version
from pkg_resources import Requirement

from pants.backend.python.goals import lockfile
from pants.backend.python.goals.lockfile import GeneratePythonLockfile
Expand Down Expand Up @@ -614,7 +614,7 @@ def test_venv_pex_resolve_info(rule_runner: RuleRunner, pex_type: type[Pex | Ven
assert dists[3].version == Version("2.23.0")
# requires_dists is parsed from metadata written by the pex tool, and is always
# a set of valid pkg_resources.Requirements.
assert Requirement.parse('PySocks!=1.5.7,>=1.5.6; extra == "socks"') in dists[3].requires_dists
assert Requirement('PySocks!=1.5.7,>=1.5.6; extra == "socks"') in dists[3].requires_dists
assert dists[4].project_name == "urllib3"


Expand Down

0 comments on commit 1208403

Please sign in to comment.