Nexus Generic Module#

exception nexus.generic.NexusError[source]#

Bases: Exception

Exception for errors that are caused by a bug in Nexus.

exception nexus.generic.FileFormatError[source]#

Bases: Exception

Exception raised when a file is not formatted as expected.

exception nexus.generic.NotAnElementError[source]#

Bases: ValueError

Exception raised when a value can not be interpreted as an element.

exception nexus.generic.NexusDevWarning(msg: str, indent: str = '    ', cls: str | None = None)[source]#

Bases: Warning

exception nexus.generic.NexusUserWarning(msg: str, indent: str = '    ', cls: str | None = None)[source]#

Bases: NexusDevWarning

nexus.generic.nocopy(value)[source]#
nexus.generic.nxs_print(*items, indent: str | None = None, logfile: TextIO | None = None, n: int = 0) → None[source]#
nexus.generic.message(msg, header=None, post_header=' message:', indent='    ', logfile=None)[source]#
nexus.generic.warn(msg: str, indent: str = '    ', warn_type: str = 'user', cls: str | None = None) → None[source]#

Report a warning.

Parameters:
msgstr

The message for the warning.

indentstr. default=” “

The indentation for the warning message.

warn_type{“user”, “dev”, “deprecate”, “class”}

See the notes for a description of when you should use each warning type.

clsstr, optional

Meant to be passed through self.warn() in a class that derives from object_interface.

Notes

If you are a developer who wants to use this function but are unsure of what kind of warning type to use, here are some basic guidelines for choosing:

  • If the function you’re putting a warning in will be directly called by a user, you should use "user", as this will show them where in their own script they’ve called the function.

  • If the function you’re putting a warning in will be indirectly called by a function that a user has called, and if the problem is due to something the user has done you should use the class’s self.warn() functionality if it inherits from DevBase, otherwise use the warning type "class" and pass in the name of the class and/or function you’re calling from.

  • If the function is called indirectly by a user and it is not necessarily their fault that something has gone awry, you should use "dev". This should likely only be used in places where you are mostly sure there won’t be any problems but the code has not been thoroughly tested.

  • If you are deprecating a function, use the @nxs_deprecate decorator and supply the version and the replacement that a user should use instead of the soon-to-be-removed function.

nexus.generic.nxs_deprecate(since: str, replacement: str, indent: str = '    ')[source]#

Decorator for signaling the deprecation of a Nexus function.

This should itself be deprecated when the minimum Python version is 3.13, when the official warnings.deprecated() decorator is added.

Parameters:
sinceVersion

The version of Nexus when the function was deprecated.

replacementstr

The replacement function for the function being deprecated.

indentstr, default = “ “

Indentation to go before the warning.

nexus.generic.error(msg: str, header: str | None = None) → NoReturn[source]#

Raise a NexusError

Parameters:
msgstr

The message to write

headerstr, optional

Header to print before the message. Will have " error:" appended to it.