Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/loader.py
Show First 20 Lines • Show All 901 Lines • ▼ Show 20 Lines | def get_loader_version(self) -> str: | ||||
module_name_parts = module_name.split(".") | module_name_parts = module_name.split(".") | ||||
# Iterate rootward through the package hierarchy until we find a parent of this | # Iterate rootward through the package hierarchy until we find a parent of this | ||||
# loader's module with a __version__ attribute. | # loader's module with a __version__ attribute. | ||||
for prefix_size in range(len(module_name_parts), 0, -1): | for prefix_size in range(len(module_name_parts), 0, -1): | ||||
package_name = ".".join(module_name_parts[0:prefix_size]) | package_name = ".".join(module_name_parts[0:prefix_size]) | ||||
module = sys.modules[package_name] | module = sys.modules[package_name] | ||||
if hasattr(module, "__version__"): | if hasattr(module, "__version__"): | ||||
return module.__version__ # type: ignore | return module.__version__ | ||||
# If this loader's class has no parent package with a __version__, | # If this loader's class has no parent package with a __version__, | ||||
# it should implement it itself. | # it should implement it itself. | ||||
raise NotImplementedError( | raise NotImplementedError( | ||||
f"Could not dynamically find the version of {self.get_loader_name()}." | f"Could not dynamically find the version of {self.get_loader_name()}." | ||||
) | ) | ||||
def get_metadata_fetcher(self) -> MetadataFetcher: | def get_metadata_fetcher(self) -> MetadataFetcher: | ||||
▲ Show 20 Lines • Show All 157 Lines • Show Last 20 Lines |