schrodinger.application.matsci.codeutils module¶
Module for utilities related to code maintenance
Copyright Schrodinger, LLC. All rights reserved.
- class schrodinger.application.matsci.codeutils.ModuleInfo(parents, name)¶
Bases:
tuple
- __contains__(key, /)¶
Return key in self.
- __len__()¶
Return len(self).
- count(value, /)¶
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- name¶
Alias for field number 1
- parents¶
Alias for field number 0
- schrodinger.application.matsci.codeutils.check_moved_variables(var_name, moved_variables, module_name)¶
Check if the target variable has been moved. If yes, post a warning when it was moved this or last release, and raise an error if it has been longer than that. Raises AttributeError if the variable was not moved.
- Parameters
var_name (str) – Name of the target variable
moved_variables (tuple) – Tuple of tuples. Each inner tuple has a format of (module, moved_release, variables), where
module
is the new module name,moved_release
is the release in which the variable was moved, andvariables
are the set of variables that were movedmodule_name (str) – Name of the calling module, for attribute error msg
- Raises
AttributeError – If
var_name
is not a moved variable- Return type
Any
- Returns
The moved variable
- schrodinger.application.matsci.codeutils.is_python_file(path)¶
Return whether the passed path is a python file
- Parameters
path (str) – The file path
- Return type
bool
- Returns
Whether the path is a python file
- schrodinger.application.matsci.codeutils.get_matsci_module_paths()¶
Return a dict of file paths and dot paths of all matsci modules, sorted
- Return dict
A dict mapping file paths to dot paths
- class schrodinger.application.matsci.codeutils.MissingModule¶
Bases:
object
Dummy class to return instead of missing modules. Will raise if any attribute is accessed.
- schrodinger.application.matsci.codeutils.get_safe_package(name)¶
Get a desmond or jaguar package without raising if the package doesn’t exist
- Parameters
name (str) – “namespace.package” where namespace is either desmond or jaguar
- Raises
ValueError – If the namespace is not included or correct
ImportError – If the package name is incorrect
- Return type
module or MissingModule
- Returns
The module or a MissingModule object
- schrodinger.application.matsci.codeutils.get_imports(script_path, parent_required='matsci')¶
Gets all the imported module/methods in the passed script
- Parameters
script_path (str) – The script path
parent_required (str) – Only include the methods and modules from the passed parent.
- Returns
iterator of module info of imported module/methods
- Return type
iter
- schrodinger.application.matsci.codeutils.get_matsci_module_graph()¶
Get the directed graph for matsci module imports
- Returns
Directed graph where each node is a matsci module and the edge represents importing of the module.
- Return type
networkx.DiGraph
- schrodinger.application.matsci.codeutils.is_python_pre311()¶
Check if the current Python version is earlier than 3.11
- Return type
bool
- Returns
True if using Python < 3.11, False if not