brain_pkg_resources.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  2. # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
  3. # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
  4. from astroid import nodes
  5. from astroid.brain.helpers import register_module_extender
  6. from astroid.builder import parse
  7. from astroid.manager import AstroidManager
  8. def pkg_resources_transform() -> nodes.Module:
  9. return parse(
  10. """
  11. def require(*requirements):
  12. return pkg_resources.working_set.require(*requirements)
  13. def run_script(requires, script_name):
  14. return pkg_resources.working_set.run_script(requires, script_name)
  15. def iter_entry_points(group, name=None):
  16. return pkg_resources.working_set.iter_entry_points(group, name)
  17. def resource_exists(package_or_requirement, resource_name):
  18. return get_provider(package_or_requirement).has_resource(resource_name)
  19. def resource_isdir(package_or_requirement, resource_name):
  20. return get_provider(package_or_requirement).resource_isdir(
  21. resource_name)
  22. def resource_filename(package_or_requirement, resource_name):
  23. return get_provider(package_or_requirement).get_resource_filename(
  24. self, resource_name)
  25. def resource_stream(package_or_requirement, resource_name):
  26. return get_provider(package_or_requirement).get_resource_stream(
  27. self, resource_name)
  28. def resource_string(package_or_requirement, resource_name):
  29. return get_provider(package_or_requirement).get_resource_string(
  30. self, resource_name)
  31. def resource_listdir(package_or_requirement, resource_name):
  32. return get_provider(package_or_requirement).resource_listdir(
  33. resource_name)
  34. def extraction_error():
  35. pass
  36. def get_cache_path(archive_name, names=()):
  37. extract_path = self.extraction_path or get_default_cache()
  38. target_path = os.path.join(extract_path, archive_name+'-tmp', *names)
  39. return target_path
  40. def postprocess(tempname, filename):
  41. pass
  42. def set_extraction_path(path):
  43. pass
  44. def cleanup_resources(force=False):
  45. pass
  46. def get_distribution(dist):
  47. return Distribution(dist)
  48. _namespace_packages = {}
  49. """
  50. )
  51. def register(manager: AstroidManager) -> None:
  52. register_module_extender(manager, "pkg_resources", pkg_resources_transform)