01-add-arcadia-support.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --- contrib/python/importlib-metadata/py3/.dist-info/METADATA (index)
  2. +++ contrib/python/importlib-metadata/py3/.dist-info/METADATA (working tree)
  3. @@ -15,1 +15,0 @@ Classifier: License :: OSI Approved :: Apache Software License
  4. -Requires-Dist: zipp>=3.20
  5. --- contrib/python/importlib-metadata/py3/importlib_metadata/__init__.py (index)
  6. +++ contrib/python/importlib-metadata/py3/importlib_metadata/__init__.py (working tree)
  7. @@ -796,6 +795,59 @@ class PathDistribution(Distribution):
  8. return name
  9. +class ArcadiaDistribution(Distribution):
  10. + def __init__(self, prefix):
  11. + self._prefix = prefix
  12. + self._path = pathlib.Path(prefix)
  13. +
  14. + def read_text(self, filename):
  15. + data = res.resfs_read(f"{self._prefix}{filename}")
  16. + if data is not None:
  17. + return data.decode("utf-8")
  18. +
  19. + read_text.__doc__ = Distribution.read_text.__doc__
  20. +
  21. + def locate_file(self, path):
  22. + return self._path.parent / path
  23. +
  24. +
  25. +@install
  26. +class MetadataArcadiaFinder(DistributionFinder):
  27. + METADATA_NAME = re.compile("^Name: (.*)$", re.MULTILINE)
  28. + prefixes = {}
  29. +
  30. + @classmethod
  31. + def find_distributions(cls, context=DistributionFinder.Context()):
  32. + found = cls._search_prefixes(context.name)
  33. + return map(ArcadiaDistribution, found)
  34. +
  35. + @classmethod
  36. + def _init_prefixes(cls):
  37. + cls.prefixes.clear()
  38. +
  39. + for resource in res.resfs_files():
  40. + resource = resource.decode("utf-8")
  41. + if not resource.endswith("METADATA"):
  42. + continue
  43. + data = res.resfs_read(resource).decode("utf-8")
  44. + metadata_name = cls.METADATA_NAME.search(data)
  45. + if metadata_name:
  46. + cls.prefixes[Prepared(metadata_name.group(1)).normalized] = resource.removesuffix("METADATA")
  47. +
  48. + @classmethod
  49. + def _search_prefixes(cls, name):
  50. + if not cls.prefixes:
  51. + cls._init_prefixes()
  52. +
  53. + if name:
  54. + try:
  55. + yield cls.prefixes[Prepared(name).normalized]
  56. + except KeyError:
  57. + pass
  58. + else:
  59. + yield from sorted(cls.prefixes.values())
  60. +
  61. +
  62. def distribution(distribution_name: str) -> Distribution:
  63. """Get the ``Distribution`` instance for the named package.