luminal.managers.resolver
Module Contents
Classes
This class provides a way to resolve module and package paths for the current operating system. |
- class Resolver
This class provides a way to resolve module and package paths for the current operating system.
- _add_path(path)
Append a path to the
PYTHONPATHvariable to allow relative imports of an imported module, and save the updated path information in the_modified_pathsdictionary.Important
This method should not be called outside of the current
Resolverinstance.- Parameters:
path (
str) – The path to be added to the_modified_pathsdictionary.- Return type:
None
Notes
This method appends the specified path to the
PYTHONPATHvariable and updates the_modified_pathsdictionary with thepathas the key and the index of thepathin thesys.pathlist as the value. It is used to facilitate relative imports of modules from a given path, and to keep track of any changes in the module paths.This method does not return anything and always adds the new path to the end of the
sys.pathlist. If the specified path is already present in thesys.pathlist, it will not be added again and the method will simply update the_modified_pathsdictionary with the new information.
- _remove_path(path)
Remove the specified path from the system path
sys.pathand clears its index in the_modified_pathsdictionary.Important
This method should not be called outside of the current
Resolverinstance.- Parameters:
path (
str) – A string representing the path to be removed from the system path.- Return type:
None
Notes
Helper method for
Resolverobjects that removes a given path from the system path. If the provided path is in_modified_pathsdictionary, this method clears its saved index by deleting the corresponding key-value pair. Then it checks if the saved index is still valid. If it is valid, then it removes the path from the system path using thepop()method with the saved index as the argument. If the saved index is not valid, then it removes the last occurrence of the path from the system path by iterating thesys.pathin reverse order.This method does not return anything and modifies
sys.pathand the local_modified_pathsdictionary directly.
- normalize_paths(path)
Converts and adds the input path as an absolute and normalized path to
sys.path.Important
This method should not be called outside of the current
Resolverinstance.- Parameters:
path (
str) – The path to be normalized.- Return type:
None
Notes
This method is a helper function used by the
Resolverclass to ensure consistency in the format of the input path. Theos.path.abspath()andos.path.normpath()functions are used to convert the inputpathto an absolute and normalized path. The normalized path is then added to the system path via the_add_path()method. The method does not return anything and modifies the current system path.
- reset_paths(path)
Removes the specified path from
sys.pathand the internal_modified_pathsdictionary.Important
This method should not be called outside of the current
Resolverinstance.- Parameters:
path (
str) – The path to be removed from the system path- Return type:
None
Notes
This method is a helper function used by the
Resolverclass to remove a specified path from the system path. The method calls_remove_path()with the given path to remove the path fromsys.path. The method does not return anything and modifies the system path.