brain_pkg_resources.py 2.3 KB

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