Commit 4ba68643 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

[reader/abbreviations] rename modname function argument to module_name

parent 72d9dd3a5149
Pipeline #6966 failed with stage
in 53 seconds
......@@ -149,7 +149,7 @@ class SchemaLoader:
) -> yams_types.Schema:
"""return a schema from the schema definition read from <module_names> (a
list of (PACKAGE, modname))
list of (PACKAGE, module_name))
self.defined: Dict = {}
......@@ -226,8 +226,8 @@ class SchemaLoader:
@deprecation.argument_renamed(old_name="modnames", new_name="module_names")
def _load_modnames(self, module_names: Sequence[Tuple[Any, str]]) -> None:
for package, modname in module_names:
loader = pkgutil.find_loader(modname)
for package, module_name in module_names:
loader = pkgutil.find_loader(module_name)
if loader is None:
......@@ -244,7 +244,7 @@ class SchemaLoader:
with tempattr(buildobjs, "PACKAGE", package):
self.handle_file(file_path, modname=modname)
self.handle_file(file_path, module_name=module_name)
# has to be overridable sometimes (usually for test purpose)
main_schema_directory: str = "schema"
......@@ -280,20 +280,21 @@ class SchemaLoader:
return result
@deprecation.argument_renamed(old_name="filepath", new_name="file_path")
def handle_file(self, file_path: str, modname: Optional[str] = None) -> None:
@deprecation.argument_renamed(old_name="modname", new_name="module_name")
def handle_file(self, file_path: str, module_name: Optional[str] = None) -> None:
"""handle a partial schema definition file according to its extension
assert file_path.endswith(".py"), "not a python file"
if file_path not in self.loaded_files:
modname, module = self.exec_file(file_path, modname)
module_name, module = self.exec_file(file_path, module_name)
objects_to_add = set()
for name, object_ in vars(module).items():
if (
isinstance(object_, type)
and issubclass(object_, buildobjs.Definition)
and object_.__module__ == modname
and object_.__module__ == module_name
and not name.startswith("_")
......@@ -331,10 +332,11 @@ class SchemaLoader:
@deprecation.argument_renamed(old_name="filepath", new_name="file_path")
def exec_file(self, file_path: str, modname: Optional[str]) -> Tuple[str, types.ModuleType]:
if modname is None:
@deprecation.argument_renamed(old_name="modname", new_name="module_name")
def exec_file(self, file_path: str, module_name: Optional[str]) -> Tuple[str, types.ModuleType]:
if module_name is None:
modname = ".".join(modpath_from_file(file_path, self.extra_path))
module_name = ".".join(modpath_from_file(file_path, self.extra_path))
except ImportError:
"module for %s can't be found, add necessary "
......@@ -342,25 +344,25 @@ class SchemaLoader:
modname = splitext(basename(file_path))[0]
module_name = splitext(basename(file_path))[0]
cast(str, modname)
cast(str, module_name)
if modname in sys.modules:
module: types.ModuleType = sys.modules[modname]
if module_name in sys.modules:
module: types.ModuleType = sys.modules[module_name]
# NOTE: don't test raw equality to avoid .pyc / .py comparisons
mpath: str = realpath(abspath(module.__file__))
fpath: str = realpath(abspath(file_path))
assert mpath.startswith(fpath), (modname, file_path, module.__file__)
assert mpath.startswith(fpath), (module_name, file_path, module.__file__)
file_globals: Dict[str, str] = {} # self.context.copy()
file_globals["__file__"] = file_path
file_globals["__name__"] = modname
file_globals["__name__"] = module_name
package: str = ".".join(modname.split(".")[:-1])
package: str = ".".join(module_name.split(".")[:-1])
if package and package not in sys.modules:
......@@ -375,20 +377,20 @@ class SchemaLoader:
file_globals["__file__"] = file_path
module = types.ModuleType(str(modname))
module = types.ModuleType(str(module_name))
sys.modules[modname] = module
sys.modules[module_name] = module
if package:
setattr(sys.modules[package], modname.split(".")[-1], module)
setattr(sys.modules[package], module_name.split(".")[-1], module)
if basename(file_path) == "":
# add __path__ to make dynamic loading work as defined in PEP 302
module.__path__ = [dirname(file_path)] # type: ignore # dynamic attribute
return (modname, module)
return (module_name, module)
def fill_schema_from_namespace(
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment