diff --git a/src/python/pants/backend/java/dependency_inference/java_parser.py b/src/python/pants/backend/java/dependency_inference/java_parser.py index a34725f8a86..087e0331c6d 100644 --- a/src/python/pants/backend/java/dependency_inference/java_parser.py +++ b/src/python/pants/backend/java/dependency_inference/java_parser.py @@ -3,13 +3,12 @@ from __future__ import annotations +import importlib.resources import json import logging import os.path from dataclasses import dataclass -import pkg_resources - from pants.backend.java.dependency_inference.types import JavaSourceDependencyAnalysis from pants.core.goals.resolves import ExportableTool from pants.core.util_rules.source_files import SourceFiles @@ -142,7 +141,8 @@ async def analyze_java_source_dependencies( def _load_javaparser_launcher_source() -> bytes: - return pkg_resources.resource_string(__name__, _LAUNCHER_BASENAME) + parent_module = ".".join(__name__.split(".")[:-1]) + return importlib.resources.files(parent_module).joinpath(_LAUNCHER_BASENAME).read_bytes() # TODO(13879): Consolidate compilation of wrapper binaries to common rules. diff --git a/src/python/pants/jvm/jar_tool/jar_tool.py b/src/python/pants/jvm/jar_tool/jar_tool.py index 2bbfe8565df..09787d290b9 100644 --- a/src/python/pants/jvm/jar_tool/jar_tool.py +++ b/src/python/pants/jvm/jar_tool/jar_tool.py @@ -3,13 +3,12 @@ from __future__ import annotations +import importlib.resources import os from collections.abc import Iterable, Mapping from dataclasses import dataclass from enum import Enum, unique -import pkg_resources - from pants.base.glob_match_error_behavior import GlobMatchErrorBehavior from pants.core.goals.resolves import ExportableTool from pants.engine.fs import ( @@ -211,17 +210,18 @@ async def run_jar_tool( def _load_jar_tool_sources() -> list[FileContent]: + parent_module = ".".join(__name__.split(".")[:-1]) result = [] for package in _JAR_TOOL_SRC_PACKAGES: # pkg_path = package.replace(".", os.path.sep) # relative_folder = os.path.join("src", pkg_path) - for basename in pkg_resources.resource_listdir(__name__, package): + for resource in importlib.resources.files(parent_module).joinpath(package).iterdir(): + if not resource.is_file(): + continue result.append( FileContent( - path=os.path.join(package, basename), - content=pkg_resources.resource_string( - __name__, os.path.join(package, basename) - ), + path=os.path.join(package, resource.name), + content=resource.read_bytes(), ) ) return result diff --git a/src/python/pants/jvm/strip_jar/strip_jar.py b/src/python/pants/jvm/strip_jar/strip_jar.py index 07b49fe8952..675e2f21186 100644 --- a/src/python/pants/jvm/strip_jar/strip_jar.py +++ b/src/python/pants/jvm/strip_jar/strip_jar.py @@ -1,10 +1,9 @@ # Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). +import importlib.resources from dataclasses import dataclass -import pkg_resources - from pants.core.goals.resolves import ExportableTool from pants.engine.fs import AddPrefix, CreateDigest, Digest, Directory, FileContent from pants.engine.internals.native_engine import MergeDigests, RemovePrefix @@ -97,7 +96,8 @@ async def strip_jar( def _load_strip_jar_source() -> bytes: - return pkg_resources.resource_string(__name__, _STRIP_JAR_BASENAME) + parent_module = ".".join(__name__.split(".")[:-1]) + return importlib.resources.files(parent_module).joinpath(_STRIP_JAR_BASENAME).read_bytes() # TODO(13879): Consolidate compilation of wrapper binaries to common rules.