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, and if yes, post a warning about it and return the variable in the new module Raises AttributeError if a moved variable isn’t found.

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, and variables are the set of variables that were moved

  • module_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.deprecate(func, to_remove_in=None, replacement=None, *args, **kwargs)

Post a warning about the function being deprecated

Parameters
  • func (callable) – The function that is deprecated

  • to_remove_in (str) – The release in which the function will be removed

  • replacement (callable) – The function to call instead

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