Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate another pkg_resources usage #22043

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading