MCPcopy
hub / github.com/hylang/hy / _same_modules

Function _same_modules

hy/macros.py:91–115  ·  view source on GitHub ↗

Compare the filenames associated with the given modules names. This tries to not actually load the modules.

(source_module, target_module)

Source from the content-addressed store, hash-verified

89
90
91def _same_modules(source_module, target_module):
92 """Compare the filenames associated with the given modules names.
93
94 This tries to not actually load the modules.
95 """
96 if not (source_module or target_module):
97 return False
98
99 if target_module is source_module:
100 return True
101
102 def get_filename(module):
103 if inspect.ismodule(module):
104 return inspect.getfile(module)
105 elif (
106 (spec := importlib.util.find_spec(module)) and
107 isinstance(spec.loader, importlib.machinery.SourceFileLoader)):
108 return spec.loader.get_filename()
109
110 try:
111 return os.path.samefile(
112 get_filename(source_module),
113 get_filename(target_module))
114 except (ValueError, TypeError, ImportError, FileNotFoundError):
115 return False
116
117
118def derive_target_module(target_module, parent_frame):

Callers 2

require_readerFunction · 0.85
requireFunction · 0.85

Calls 1

get_filenameFunction · 0.85

Tested by

no test coverage detected