aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/setuptools/py3/pkg_resources
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-02-27 16:27:23 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-02-27 17:00:48 +0300
commit6c35e9daf4dc86464e1a262236b8d3593e690ee5 (patch)
tree2727d5da08d12182c1a705ec7213a6b97f5da521 /contrib/python/setuptools/py3/pkg_resources
parent6fa64684d15341dd701bf1498ecafdd764d5f097 (diff)
downloadydb-6c35e9daf4dc86464e1a262236b8d3593e690ee5.tar.gz
Intermediate changes
Diffstat (limited to 'contrib/python/setuptools/py3/pkg_resources')
-rw-r--r--contrib/python/setuptools/py3/pkg_resources/__init__.py113
1 files changed, 46 insertions, 67 deletions
diff --git a/contrib/python/setuptools/py3/pkg_resources/__init__.py b/contrib/python/setuptools/py3/pkg_resources/__init__.py
index f41d46c634..d83283ff1c 100644
--- a/contrib/python/setuptools/py3/pkg_resources/__init__.py
+++ b/contrib/python/setuptools/py3/pkg_resources/__init__.py
@@ -18,11 +18,16 @@ This module is deprecated. Users are directed to :mod:`importlib.resources`,
"""
import sys
+
+if sys.version_info < (3, 8):
+ raise RuntimeError("Python 3.8 or later is required")
+
import os
import io
import time
import re
import types
+from typing import Protocol
import zipfile
import zipimport
import warnings
@@ -41,18 +46,10 @@ import inspect
import ntpath
import posixpath
import importlib
+import importlib.machinery
from pkgutil import get_importer
-try:
- import _imp
-except ImportError:
- # Python 3.2 compatibility
- import imp as _imp
-
-try:
- FileExistsError
-except NameError:
- FileExistsError = OSError
+import _imp
# capture these to bypass sandboxing
from os import utime
@@ -68,14 +65,6 @@ except ImportError:
from os import open as os_open
from os.path import isdir, split
-try:
- import importlib.machinery as importlib_machinery
-
- # access attribute to force import under delayed import mechanisms.
- importlib_machinery.__name__
-except ImportError:
- importlib_machinery = None
-
from pkg_resources.extern.jaraco.text import (
yield_lines,
drop_comment,
@@ -91,9 +80,6 @@ __import__('pkg_resources.extern.packaging.requirements')
__import__('pkg_resources.extern.packaging.markers')
__import__('pkg_resources.extern.packaging.utils')
-if sys.version_info < (3, 5):
- raise RuntimeError("Python 3.5 or later is required")
-
# declare some globals that will be defined later to
# satisfy the linters.
require = None
@@ -407,20 +393,18 @@ def get_provider(moduleOrReq):
return _find_adapter(_provider_factories, loader)(module)
-def _macos_vers(_cache=[]):
- if not _cache:
- version = platform.mac_ver()[0]
- # fallback for MacPorts
- if version == '':
- plist = '/System/Library/CoreServices/SystemVersion.plist'
- if os.path.exists(plist):
- if hasattr(plistlib, 'readPlist'):
- plist_content = plistlib.readPlist(plist)
- if 'ProductVersion' in plist_content:
- version = plist_content['ProductVersion']
-
- _cache.append(version.split('.'))
- return _cache[0]
+@functools.lru_cache(maxsize=None)
+def _macos_vers():
+ version = platform.mac_ver()[0]
+ # fallback for MacPorts
+ if version == '':
+ plist = '/System/Library/CoreServices/SystemVersion.plist'
+ if os.path.exists(plist):
+ with open(plist, 'rb') as fh:
+ plist_content = plistlib.load(fh)
+ if 'ProductVersion' in plist_content:
+ version = plist_content['ProductVersion']
+ return version.split('.')
def _macos_arch(machine):
@@ -546,54 +530,54 @@ def get_entry_info(dist, group, name):
return get_distribution(dist).get_entry_info(group, name)
-class IMetadataProvider:
- def has_metadata(name):
+class IMetadataProvider(Protocol):
+ def has_metadata(self, name):
"""Does the package's distribution contain the named metadata?"""
- def get_metadata(name):
+ def get_metadata(self, name):
"""The named metadata resource as a string"""
- def get_metadata_lines(name):
+ def get_metadata_lines(self, name):
"""Yield named metadata resource as list of non-blank non-comment lines
Leading and trailing whitespace is stripped from each line, and lines
with ``#`` as the first non-blank character are omitted."""
- def metadata_isdir(name):
+ def metadata_isdir(self, name):
"""Is the named metadata a directory? (like ``os.path.isdir()``)"""
- def metadata_listdir(name):
+ def metadata_listdir(self, name):
"""List of metadata names in the directory (like ``os.listdir()``)"""
- def run_script(script_name, namespace):
+ def run_script(self, script_name, namespace):
"""Execute the named script in the supplied namespace dictionary"""
-class IResourceProvider(IMetadataProvider):
+class IResourceProvider(IMetadataProvider, Protocol):
"""An object that provides access to package resources"""
- def get_resource_filename(manager, resource_name):
+ def get_resource_filename(self, manager, resource_name):
"""Return a true filesystem path for `resource_name`
`manager` must be an ``IResourceManager``"""
- def get_resource_stream(manager, resource_name):
+ def get_resource_stream(self, manager, resource_name):
"""Return a readable file-like object for `resource_name`
`manager` must be an ``IResourceManager``"""
- def get_resource_string(manager, resource_name):
+ def get_resource_string(self, manager, resource_name):
"""Return a string containing the contents of `resource_name`
`manager` must be an ``IResourceManager``"""
- def has_resource(resource_name):
+ def has_resource(self, resource_name):
"""Does the package contain the named resource?"""
- def resource_isdir(resource_name):
+ def resource_isdir(self, resource_name):
"""Is the named resource a directory? (like ``os.path.isdir()``)"""
- def resource_listdir(resource_name):
+ def resource_listdir(self, resource_name):
"""List of resource names in the directory (like ``os.listdir()``)"""
@@ -1143,8 +1127,7 @@ class Environment:
None is returned instead. This method is a hook that allows subclasses
to attempt other ways of obtaining a distribution before falling back
to the `installer` argument."""
- if installer is not None:
- return installer(requirement)
+ return installer(requirement) if installer else None
def __iter__(self):
"""Yield the unique project names of the available distributions"""
@@ -1734,7 +1717,7 @@ class DefaultProvider(EggProvider):
'SourcelessFileLoader',
)
for name in loader_names:
- loader_cls = getattr(importlib_machinery, name, type(None))
+ loader_cls = getattr(importlib.machinery, name, type(None))
register_loader_type(loader_cls, cls)
@@ -1895,7 +1878,7 @@ class ZipProvider(EggProvider):
try:
rename(tmpnam, real_path)
- except os.error:
+ except OSError:
if os.path.isfile(real_path):
if self._is_current(real_path, zip_path):
# the file became current since it was checked above,
@@ -1908,7 +1891,7 @@ class ZipProvider(EggProvider):
return real_path
raise
- except os.error:
+ except OSError:
# report a user-friendly error
manager.extraction_error()
@@ -2229,7 +2212,7 @@ def resolve_egg_link(path):
if hasattr(pkgutil, 'ImpImporter'):
register_finder(pkgutil.ImpImporter, find_on_path)
-register_finder(importlib_machinery.FileFinder, find_on_path)
+register_finder(importlib.machinery.FileFinder, find_on_path)
_declare_state('dict', _namespace_handlers={})
_declare_state('dict', _namespace_packages={})
@@ -2396,7 +2379,7 @@ if hasattr(pkgutil, 'ImpImporter'):
register_namespace_handler(pkgutil.ImpImporter, file_ns_handler)
register_namespace_handler(zipimport.zipimporter, file_ns_handler)
-register_namespace_handler(importlib_machinery.FileFinder, file_ns_handler)
+register_namespace_handler(importlib.machinery.FileFinder, file_ns_handler)
def null_ns_handler(importer, path_item, packageName, module):
@@ -2422,12 +2405,9 @@ def _cygwin_patch(filename): # pragma: nocover
return os.path.abspath(filename) if sys.platform == 'cygwin' else filename
-def _normalize_cached(filename, _cache={}):
- try:
- return _cache[filename]
- except KeyError:
- _cache[filename] = result = normalize_path(filename)
- return result
+@functools.lru_cache(maxsize=None)
+def _normalize_cached(filename):
+ return normalize_path(filename)
def _is_egg_path(path):
@@ -2852,9 +2832,7 @@ class Distribution:
def _get_version(self):
lines = self._get_metadata(self.PKG_INFO)
- version = _version_from_file(lines)
-
- return version
+ return _version_from_file(lines)
def activate(self, path=None, replace=False):
"""Ensure distribution is importable on `path` (default=sys.path)"""
@@ -2901,7 +2879,7 @@ class Distribution:
def __dir__(self):
return list(
- set(super(Distribution, self).__dir__())
+ set(super().__dir__())
| set(attr for attr in self._provider.__dir__() if not attr.startswith('_'))
)
@@ -3168,7 +3146,7 @@ class RequirementParseError(packaging.requirements.InvalidRequirement):
class Requirement(packaging.requirements.Requirement):
def __init__(self, requirement_string):
"""DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
- super(Requirement, self).__init__(requirement_string)
+ super().__init__(requirement_string)
self.unsafe_name = self.name
project_name = safe_name(self.name)
self.project_name, self.key = project_name, project_name.lower()
@@ -3229,6 +3207,7 @@ def _find_adapter(registry, ob):
for t in types:
if t in registry:
return registry[t]
+ return None
def ensure_directory(path):