aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-04-13 18:01:38 +0300
committershadchin <shadchin@yandex-team.com>2024-04-13 18:08:29 +0300
commitda6de0aefb4620d2a3515de3f478b5a0925d55ef (patch)
tree889aecfc7a5f810dae068add0ab74cc4ef0322fe
parent6314a988276bdaf1916a5013d309448aa31c7598 (diff)
downloadydb-da6de0aefb4620d2a3515de3f478b5a0925d55ef.tar.gz
Simplify support `importlib.metadata`
996025a2ee725b626c3b77aac016d8f8c0ac4e76
-rw-r--r--library/python/runtime_py3/importer.pxi13
-rw-r--r--library/python/runtime_py3/sitecustomize.pyx14
2 files changed, 16 insertions, 11 deletions
diff --git a/library/python/runtime_py3/importer.pxi b/library/python/runtime_py3/importer.pxi
index 493c17204d..bd65921840 100644
--- a/library/python/runtime_py3/importer.pxi
+++ b/library/python/runtime_py3/importer.pxi
@@ -408,6 +408,19 @@ class ResourceImporter:
path = os.path.dirname(self.get_filename(fullname))
return _ResfsResourceReader(self, path)
+ @staticmethod
+ def find_distributions(*args, **kwargs):
+ """
+ Find distributions.
+
+ Return an iterable of all Distribution instances capable of
+ loading the metadata for packages matching ``context.name``
+ (or all names if ``None`` indicated) along the paths in the list
+ of directories ``context.path``.
+ """
+ from sitecustomize import MetadataArcadiaFinder
+ return MetadataArcadiaFinder.find_distributions(*args, **kwargs)
+
class _ResfsResourceReader:
diff --git a/library/python/runtime_py3/sitecustomize.pyx b/library/python/runtime_py3/sitecustomize.pyx
index 46ca0f986e..7a73f3241b 100644
--- a/library/python/runtime_py3/sitecustomize.pyx
+++ b/library/python/runtime_py3/sitecustomize.pyx
@@ -8,7 +8,6 @@ import warnings
from importlib.metadata import (
Distribution,
DistributionFinder,
- PackageNotFoundError,
Prepared,
)
from importlib.resources.abc import Traversable
@@ -129,7 +128,7 @@ class ArcadiaDistribution(Distribution):
return self._path.parent / path
-class ArcadiaMetadataFinder(DistributionFinder):
+class MetadataArcadiaFinder(DistributionFinder):
prefixes = {}
@classmethod
@@ -148,8 +147,7 @@ class ArcadiaMetadataFinder(DistributionFinder):
data = __res.resfs_read(resource).decode("utf-8")
metadata_name = METADATA_NAME.search(data)
if metadata_name:
- metadata_name = Prepared(metadata_name.group(1))
- cls.prefixes[metadata_name.normalized] = resource[: -len("METADATA")]
+ cls.prefixes[Prepared(metadata_name.group(1)).normalized] = resource.removesuffix("METADATA")
@classmethod
def _search_prefixes(cls, name):
@@ -160,12 +158,6 @@ class ArcadiaMetadataFinder(DistributionFinder):
try:
yield cls.prefixes[Prepared(name).normalized]
except KeyError:
- raise PackageNotFoundError(name)
+ pass
else:
yield from sorted(cls.prefixes.values())
-
-
-# monkeypatch standart library
-import importlib.metadata
-
-importlib.metadata.MetadataPathFinder = ArcadiaMetadataFinder