luminal.managers.resolver

Module Contents

Classes

Resolver

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 PYTHONPATH variable to allow relative imports of an imported module, and save the updated path information in the _modified_paths dictionary.

Important

This method should not be called outside of the current Resolver instance.

Parameters:

path (str) – The path to be added to the _modified_paths dictionary.

Return type:

None

Notes

  • This method appends the specified path to the PYTHONPATH variable and updates the _modified_paths dictionary with the path as the key and the index of the path in the sys.path list 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.path list. If the specified path is already present in the sys.path list, it will not be added again and the method will simply update the _modified_paths dictionary with the new information.

_remove_path(path)

Remove the specified path from the system path sys.path and clears its index in the _modified_paths dictionary.

Important

This method should not be called outside of the current Resolver instance.

Parameters:

path (str) – A string representing the path to be removed from the system path.

Return type:

None

Notes

  • Helper method for Resolver objects that removes a given path from the system path. If the provided path is in _modified_paths dictionary, 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 the pop() 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 the sys.path in reverse order.

  • This method does not return anything and modifies sys.path and the local _modified_paths dictionary 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 Resolver instance.

Parameters:

path (str) – The path to be normalized.

Return type:

None

Notes

  • This method is a helper function used by the Resolver class to ensure consistency in the format of the input path. The os.path.abspath() and os.path.normpath() functions are used to convert the input path to 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.path and the internal _modified_paths dictionary.

Important

This method should not be called outside of the current Resolver instance.

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 Resolver class to remove a specified path from the system path. The method calls _remove_path() with the given path to remove the path from sys.path. The method does not return anything and modifies the system path.

resolve_path(path)

Extracts the module name and its full path from the provided relative path.

Important

This method should not be called outside of the current Resolver instance.

Parameters:

path (str) – The relative path to the desired Python module.

Returns:

A tuple containing the name and resolved path of the Python module corresponding to the provided relative path.

Return type:

tuple