Nexus Generic Module#
- class nexus.generic.generic_settings[source]#
Bases:
object- devlog = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>#
- raise_error = False#
- 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
- class nexus.generic.NexusUnpickler(file, *, fix_imports=True, encoding='ASCII', errors='strict', buffers=())[source]#
Bases:
UnpicklerThis class is designed for backwards compatibility with pickles generated before Nexus was packaged (PR #5700, December 20, 2025). It shouldn’t touch anything but old Nexus pickles.
- Attributes:
- memo
Methods
find_class(module, name)Return an object from a specified module.
load(/)Load a pickle.
persistent_load
- find_class(module, name)[source]#
Return an object from a specified module.
If necessary, the module will be imported. Subclasses may override this method (e.g. to restrict unpickling of arbitrary classes and functions).
This method is called whenever a class or a function object is needed. Both arguments passed are str objects.
- nexus.generic.warn(msg: str, indent: str = ' ', warn_type: str = 'user', cls: str | None = None) None[source]#
Report a warning.
- Parameters:
- msg
str 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.
- cls
str, optional Meant to be passed through
self.warn()in a class that derives fromobject_interface.
- msg
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 fromDevBase, 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_deprecatedecorator 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.
- nexus.generic.error(msg: str, header: str | None = None, exit: bool = True, trace: int | None = -1, indent: str = ' ', logfile: TextIO | None = None)[source]#
Report an error.
- Parameters:
- msg
str The message to write
- header
str, optional Header to print before the message. Will have
" error:"appended to it.- exitbool, default=True
Whether or not to force an exit through
sys.exit(). See Notes.- trace
intorNone, default=-1 How much of the traceback to print.
Noneprints the full traceback, positive integers limit to a number of frames relative to this function, and negative integers limit to a number of frames up to this function. Setting this to0will disable the traceback completely.The default value is
-1, which will print only the traceback up to the location that this function was called, but will not show the location of this function.- indent
str, default=” “ A string that will be used to indent the error message.
- logfile
TextIO, default=generic_settings.devlog The already-opened file to write to. Typically this is
sys.stdout.
- msg
- Raises:
NexusErrorIf
generic_settings.raise_error = True.
See also
Notes
If you set
exit=True, then this will callsys.exit(1), which will force an exit that can not be caught or handled.
- class nexus.generic.object_interface[source]#
Bases:
objectMethods
class_error(message[, header, exit, trace, ...])Report an error relating to a class.
error(message[, header, exit, trace])Report an error inside a class.
keys()open_log(filepath)save([fpath])warn(msg[, indent])Warning from inside a Nexus class.
class_get
class_has
class_items
class_keys
class_log
class_set
class_set_optional
class_set_single
class_warn
clear
close_log
copy
data_repr
items
load
log
tree
values
write
- warn(msg: str, indent: str = ' ')[source]#
Warning from inside a Nexus class.
See
generic.warn()for description.
- error(message, header=None, exit=True, trace=-2)[source]#
Report an error inside a class.
This is the same as
generic.error(), but withtrace=-2as the default. This has the benefit of only printing a traceback up to the call location, and not inadvertently pointing someone togeneric.py.
- classmethod class_error(message, header=None, exit=True, trace=-2, post_header=' Error:')[source]#
Report an error relating to a class.
See also
object_interface.errorUsed inside subclasses of
object_interface.generic.errorCalled when you are not reporting an error specific to a class.
- class nexus.generic.obj(*vars, **kwargs)[source]#
Bases:
object_interfaceMethods
append(value)class_error(message[, header, exit, trace, ...])Report an error relating to a class.
error(message[, header, exit, trace])Report an error inside a class.
first()keys()list(*keys)open_log(filepath)save([fpath])warn(msg[, indent])Warning from inside a Nexus class.
add
add_optional
check_required
check_types
check_types_optional
class_get
class_has
class_items
class_keys
class_log
class_set
class_set_optional
class_set_single
class_warn
clear
close_log
copy
copy_from
copy_to
data_repr
delete
delete_optional
delete_required
dict
extract
extract_optional
get
get_optional
get_path
get_required
inverse
items
last
list_optional
load
log
move_from
move_from_optional
move_to
move_to_optional
obj
path_exists
random_key
select_random
serial
set
set_optional
set_path
shallow_copy
to_dict
to_obj
transfer_from
transfer_to
tree
tuple
values
write
- class nexus.generic.hobj(*args, **kwargs)[source]#
Bases:
objMethods
append(value)class_error(message[, header, exit, trace, ...])Report an error relating to a class.
error(message[, header, exit, trace])Report an error inside a class.
first()list(*keys)open_log(filepath)save([fpath])sorted_keys()warn(msg[, indent])Warning from inside a Nexus class.
add
add_optional
check_required
check_types
check_types_optional
class_get
class_has
class_items
class_keys
class_log
class_set
class_set_optional
class_set_single
class_warn
clear
close_log
copy
copy_from
copy_to
data_repr
delete
delete_optional
delete_required
dict
extract
extract_optional
get
get_optional
get_path
get_required
inverse
items
keys
last
list_optional
load
log
move_from
move_from_optional
move_to
move_to_optional
obj
path_exists
random_key
select_random
serial
set
set_optional
set_path
shallow_copy
to_dict
to_obj
transfer_from
transfer_to
tree
tuple
values
write
Bases:
hobjMethods
append(value)class_error(message[, header, exit, trace, ...])Report an error relating to a class.
error(message[, header, exit, trace])Report an error inside a class.
first()list(*keys)save([fpath])sorted_keys()warn(msg[, indent])Warning from inside a Nexus class.
add
add_optional
check_required
check_types
check_types_optional
class_get
class_has
class_items
class_keys
class_log
class_set
class_set_optional
class_set_single
class_warn
clear
close_log
copy
copy_from
copy_to
data_repr
delete
delete_optional
delete_required
dict
extract
extract_optional
get
get_optional
get_path
get_required
hidden
inverse
items
keys
last
list_optional
load
log
move_from
move_from_optional
move_to
move_to_optional
obj
open_log
path_exists
public
random_key
select_random
serial
set
set_optional
set_path
shallow_copy
to_dict
to_obj
transfer_from
transfer_to
tree
tuple
values
write