sas.system package¶
Subpackages¶
- sas.system.config package
- Submodules
- sas.system.config.config module
- sas.system.config.config_meta module
ConfigBaseConfigBase.__annotations__ConfigBase.__dict__ConfigBase.__doc__ConfigBase.__init__()ConfigBase.__module__ConfigBase.__setattr__()ConfigBase.__weakref__ConfigBase._generate_schema()ConfigBase._state_copy()ConfigBase.config_filename()ConfigBase.defaultsConfigBase.finalise()ConfigBase.load()ConfigBase.load_from_file_object()ConfigBase.override_with_defaults()ConfigBase.save()ConfigBase.save_to_file_object()ConfigBase.update()ConfigBase.validate()
ConfigLockedConfigMetaMalformedFile
- sas.system.config.schema_elements module
- Module contents
Submodules¶
sas.system.console module¶
Windows console binding for SasView
- class sas.system.console.Singleton¶
Bases:
typeMetaclass indicating that all object instantiations should return the same instance.
Usage:
class Stateful(metaclass=Singleton): …
The init will only be triggered for the first instance, so you probably shouldn’t parameterize it, or only parameterize it during setup before any other instances are created.
- __annotations__ = {}¶
- __call__(*args, **kwargs)¶
Call self as a function.
- __doc__ = "\n Metaclass indicating that all object instantiations should return the same instance.\n\n Usage:\n\n class Stateful(metaclass=Singleton): ...\n\n The init will only be triggered for the first instance, so you probably shouldn't\n parameterize it, or only parameterize it during setup before any other instances\n are created.\n "¶
- __module__ = 'sas.system.console'¶
- _instances = {}¶
- class sas.system.console.WindowsConsole(*args, **kwargs)¶
Bases:
objectWindows console object.
This only creates the console when you read to it or write from it. This reduces flashing windows when using the app in a pipeline.
This presents as an incomplete standard rw file interface.
Unfortunately it does not regiister as a windows console stdio object so the cpython myreadline code does not call PyOS_InputHook during read. The practical consequence is that pyplot.ion() does not create an interactive plot, and you instead need to call pyplot.pause(0.1) to draw the figure. You can try tracing through myreadline.c to see what we need to do to get sys.stdin recognized as stdin here: https://github.com/python/cpython/blob/main/Parser/myreadline.c
- __dict__ = mappingproxy({'__module__': 'sas.system.console', '__doc__': '\n Windows console object.\n\n This only creates the console when you read to it or write from it. This reduces\n flashing windows when using the app in a pipeline.\n\n This presents as an incomplete standard rw file interface.\n\n Unfortunately it does not regiister as a windows console stdio object so the\n cpython myreadline code does not call PyOS_InputHook during read. The practical\n consequence is that pyplot.ion() does not create an interactive plot, and you\n instead need to call pyplot.pause(0.1) to draw the figure. You can try tracing\n through myreadline.c to see what we need to do to get sys.stdin recognized as\n stdin here: https://github.com/python/cpython/blob/main/Parser/myreadline.c\n ', '__init__': <function WindowsConsole.__init__>, 'close_wait': <function WindowsConsole.close_wait>, '_attach_console': <function WindowsConsole._attach_console>, '_read_fd': <property object>, '_write_fd': <property object>, 'readline': <function WindowsConsole.readline>, 'write': <function WindowsConsole.write>, 'flush': <function WindowsConsole.flush>, 'read': <function WindowsConsole.read>, 'isatty': <function WindowsConsole.isatty>, 'readable': <function WindowsConsole.readable>, 'writeable': <function WindowsConsole.writeable>, 'seekable': <function WindowsConsole.seekable>, 'name': <function WindowsConsole.name>, '__dict__': <attribute '__dict__' of 'WindowsConsole' objects>, '__weakref__': <attribute '__weakref__' of 'WindowsConsole' objects>, '__annotations__': {}})¶
- __doc__ = '\n Windows console object.\n\n This only creates the console when you read to it or write from it. This reduces\n flashing windows when using the app in a pipeline.\n\n This presents as an incomplete standard rw file interface.\n\n Unfortunately it does not regiister as a windows console stdio object so the\n cpython myreadline code does not call PyOS_InputHook during read. The practical\n consequence is that pyplot.ion() does not create an interactive plot, and you\n instead need to call pyplot.pause(0.1) to draw the figure. You can try tracing\n through myreadline.c to see what we need to do to get sys.stdin recognized as\n stdin here: https://github.com/python/cpython/blob/main/Parser/myreadline.c\n '¶
- __init__()¶
- __module__ = 'sas.system.console'¶
- __weakref__¶
list of weak references to the object
- _attach_console()¶
- property _read_fd¶
- property _write_fd¶
- close_wait()¶
Registered with atexit to give users a chance to see the output.
- flush()¶
- isatty()¶
- name()¶
- read(*args, **kwargs)¶
- readable()¶
- readline(*args, **kwargs)¶
- seekable()¶
- write(*args, **kwargs)¶
- writeable()¶
- sas.system.console.attach_windows_console()¶
Attach a console to a windows program that does not normally have one.
Note: Uses a lazy import for win32console so you will to add pywin32 to requirements.txt and tell the installer to include win32.win32console
- sas.system.console.demo()¶
- sas.system.console.setup_console(stderr_as='console')¶
Lazy redirect of stdio to windows console.
Handling of stderr is defined by the caller:
console: create a console for stderr even if stdin/stdout are redirected.
stdout: redirect stderr to whereever stdout is going
null: redirect stderr to the NUL device (untested!!)
none: don’t redirect stderr; instead windows displays an error box with stderr contents
- sas.system.console.setup_console_simple(stderr_to_stdout=True)¶
Simple version of stdio redirection: always open a console, and don’t pause before closing.
sas.system.legal module¶
- class sas.system.legal.Legal¶
Bases:
object- __dict__ = mappingproxy({'__module__': 'sas.system.legal', '__init__': <function Legal.__init__>, '__dict__': <attribute '__dict__' of 'Legal' objects>, '__weakref__': <attribute '__weakref__' of 'Legal' objects>, '__doc__': None, '__annotations__': {}})¶
- __doc__ = None¶
- __init__()¶
- __module__ = 'sas.system.legal'¶
- __weakref__¶
list of weak references to the object
sas.system.lib module¶
Setup third-party libraries (e.g., qt, sasview, periodictable, bumps)
These functions are used to setup up the GUI and the scripting environment.
- sas.system.lib.reset_sasmodels(sas_opencl)¶
Trigger a reload of all sasmodels calculators using the new value of sas_opencl. The new value will be saved in the sasview configuration file.
- sas.system.lib.setup_qt_env()¶
Setup the Qt environment.
The environment values are set by the user and managed by sasview config.
This function does not import the Qt libraries so it is safe to use from a script.
- sas.system.lib.setup_sasmodels()¶
Initialize sasmodels settings from the sasview configuration.
sas.system.log module¶
- sas.system.log.development()¶
- sas.system.log.print_config(msg='Logger config:')¶
When debugging the logging configuration it is handy to see exactly how it is configured. To do so you will need to pip install the logging_tree package and add log.print_config() at choice points in the code.
- sas.system.log.production()¶
- sas.system.log.setup_logging(level=20)¶
sas.system.resources module¶
Extract resources from a Python module
Python modules can have resources such as icons or source code within them. The resources will often be sitting beside the Python files in the source tree or when installed, with the exception of PEP 660 editable installs where the resources can be sitting inside a tree in site-packages, while the source code remains in the original source directory.
These utilities can transparently extract resources from the appropriate location.
The approach is:
Look in the distribution file manifest via importlib.metadata; these are the files that have been installed into site-packages and have been recorded in the dist-info/RECORD manifest. This code calls them “recorded” files.
Look at the files that are part of the module tree as sitting on disk via importlib.resources; in the case of an installed module, this will cover the same files as #1, but for an editable install, it will only include the files that are in the source tree and not the files in site-packages. This code calls them “adjacent” files.
The approach described above prioritises files that are installed (hence part of a wheel distribution, known to pip, and can be removed when uninstalling).
- This module is extensible for future work to
remove path calculation of the location of resources
provide filehandles to resources rather than copies of resources
deduplicate some resources across the codebase
- class sas.system.resources.ModuleResources(module: str)¶
Bases:
objectLocate and extract resources in Python modules
- __dict__ = mappingproxy({'__module__': 'sas.system.resources', '__doc__': 'Locate and extract resources in Python modules', '__init__': <function ModuleResources.__init__>, 'extract_resource': <function ModuleResources.extract_resource>, 'extract_resource_tree': <function ModuleResources.extract_resource_tree>, 'path_to_resource': <function ModuleResources.path_to_resource>, 'path_to_resource_directory': <function ModuleResources.path_to_resource_directory>, '_dist_name': <property object>, '_distribution': <property object>, '_is_zip_distribution': <property object>, '_incompatible_with_recorded': <property object>, '_distribution_files': <function ModuleResources._distribution_files>, '_path_to_resource_recorded': <function ModuleResources._path_to_resource_recorded>, '_locate_resource_recorded': <function ModuleResources._locate_resource_recorded>, '_extract_resource_recorded': <function ModuleResources._extract_resource_recorded>, '_extract_resource_tree_recorded': <function ModuleResources._extract_resource_tree_recorded>, '_copy_resource_recorded': <function ModuleResources._copy_resource_recorded>, '_path_to_resource_adjacent': <function ModuleResources._path_to_resource_adjacent>, '_extract_resource_adjacent': <function ModuleResources._extract_resource_adjacent>, '_extract_resource_tree_adjacent': <function ModuleResources._extract_resource_tree_adjacent>, '__dict__': <attribute '__dict__' of 'ModuleResources' objects>, '__weakref__': <attribute '__weakref__' of 'ModuleResources' objects>, '__annotations__': {}})¶
- __doc__ = 'Locate and extract resources in Python modules'¶
- __init__(module: str)¶
Create a resource extractor with a module name.
- Parameters:
module: The importable name of the module to extract resources from.
For SasView, the module name would be “sas”, while, the distribution name (dist_name) that is calculated from it is “sasview”.
- __module__ = 'sas.system.resources'¶
- __weakref__¶
list of weak references to the object
- _copy_resource_recorded(resource: PackagePath, dest: Path) None¶
copy the resource to the filesystem
dest needs to be the file path including the filename
- property _dist_name: str | None¶
- property _distribution: Distribution¶
- _distribution_files() list[PackagePath] | None¶
- _extract_resource_adjacent(src: str, dest: Path) bool¶
extract the adjacent resource (if it exists) to the destination filename
dest must be a file path including the target filename
This method should should transparently access resources in zip bundles
- _extract_resource_recorded(src: str, dest: Path) bool¶
extract the recorded resource (if it exists) to the destination filename
dest must be a file path including the target filename
- _extract_resource_tree_adjacent(src: str | Path, dest: Path) bool¶
extract the adjacent resource tree (if it exists) to the destination directory
dest must be a directory
- _extract_resource_tree_recorded(src: str, dest: Path) bool¶
extract the recorded resource tree (if it exists) to the destination directory
dest must be a directory
- property _incompatible_with_recorded: bool¶
- property _is_zip_distribution: bool¶
- _locate_resource_recorded(src: str) PackagePath | None¶
obtain the PackagePath record for the resource if it exists
- _path_to_resource_adjacent(src: str, accept: ~sas.system.resources._ResType = <_ResType.FILE: 1>) Path | None¶
calculate the filesystem path to the recorded resource if it exists
- _path_to_resource_recorded(src: str) Path | None¶
calculate the filesystem path to the recorded resource if it exists
- extract_resource(src: str | PurePath, dest: Path | str) bool¶
Extract a single resource from the module.
- Parameters:
src: The source path for the file within the module (does not include the module name) dest: The destination path to which the resource will be copied (including filename).
Returns: True if resource was extracted
- extract_resource_tree(src: str | PurePath, dest: Path | str) bool¶
Extract a tree of resources from the module.
- Parameters:
src: The source path for the directory within the module (does not include the module name) dest: The destination path to which the resources will be copied recursively.
- path_to_resource(src: str | PurePath) Path¶
Provide the filesystem path to a file resource
If the resource is already available on the filesystem, then provide the path to it directly; if it is not available, then a FileNotFoundError is raised and the caller should extract into a filesystem location that they can clean up after use.
- path_to_resource_directory(src: str | PurePath) Path¶
Provide the filesystem path to a file resource directory
If the resource is already available on the filesystem, then provide the path to it directly; if it is not available, then a NotADirectoryError is raised and the caller should extract into a filesystem location that they can clean up after use.
Note that completely empty directories might not be found by this method as they are not recorded in the dist-info/RECORD.
- class sas.system.resources._ResType(value)¶
Bases:
Flag- DIR = 2¶
- FILE = 1¶
- __and__(other)¶
- __doc__ = None¶
- __invert__()¶
- __module__ = 'sas.system.resources'¶
- __new__(value)¶
- __or__(other)¶
Return self|value.
- __rand__(other)¶
- __ror__(other)¶
Return value|self.
- __rxor__(other)¶
- __xor__(other)¶
- _all_bits_ = 3¶
- _boundary_ = 'strict'¶
- _flag_mask_ = 3¶
- _generate_next_value_(start, count, last_values)¶
Generate the next value when not given.
name: the name of the member start: the initial start value or None count: the number of existing members last_values: the last value assigned or None
- _inverted_ = None¶
- _singles_mask_ = 3¶
- sas.system.resources._clean_path(src: str | PurePath) str¶
- sas.system.resources._dist_name(module: str) str | None¶
- sas.system.resources._distribution(dist_name: str) Distribution¶
- sas.system.resources._distribution_files(dist_name: str) list[PackagePath] | None¶
- sas.system.resources._is_zip_distribution(dist_name: str) bool¶
identify whether the module is inside a zip bundle or whl
- sas.system.resources.main(argv: list[str]) bool¶
Extract a resource from a Python module.
Extracts resources such as config files, icons, data files that are part of a Python module.
The Python module is specified via its importable name (not the distribution name).
Resources shipped in the following ways are supported:
resources that are installed on-disk in a normal pip installed module; these are in site-packages and recorded within the dist-info.
resources that are still adjacent to the code and not in site-packages, such as in an editable install.
resources that are inside a wheel file (whl) that has been added to PYTHONPATH
resources that are inside a module shipped in zip-bundle form
sas.system.user module¶
- sas.system.user._copy_documentation() Path | None¶
Extract the module documentation and copy it to a configured location
- sas.system.user._copy_example_data() None¶
- sas.system.user._get_user_dir(create_if_nonexistent: bool = False) Path¶
DEPRECATED Do not use this function to create new files.
v6.1.0: This is only used to move files from previous version locations to new locations
- sas.system.user._locate_module_documentation_path() Path | None¶
Attempt to find a filesystem path directly to the sasview module’s documentation
- sas.system.user._setup_module_documentation() None¶
Get the documentation tree ready for the user
The first of these to succeed is what is used:
look for the documentation inside the sas module and if it is available on disk, then directly use that
extract the documentation from the sas module to the configured doc location and use that.
- sas.system.user.copy_old_files_to_new_location()¶
Only run at app startup A check to see if files in the old user locations exist and move them if they haven’t already been moved.
- sas.system.user.copy_resources() None¶
Set up user environment with resource files
- sas.system.user.create_user_files_if_needed() None¶
Create user documentation directories if necessary and copy built docs there.
- sas.system.user.find_plugins_dir() str¶
A helper function that returns a string representation of the plugins directory as defined by sas.system.user.
- sas.system.user.get_app_dir(create_if_nonexistent: bool = True) Path¶
The directory where the os-specific app data is stored.
Returns the directory as a pathlib.Path object, creating the directory if it does not already exist.
- sas.system.user.get_app_dir_versioned(create_if_nonexistent: bool = True) Path¶
The directory where the version-dependent, os-specific app data is stored.
Returns the directory as a pathlib.Path object, creating the directory if it does not already exist.
- sas.system.user.get_cache_dir(create_if_nonexistent: bool = True) Path¶
The directory where the os-specific cache is stored.
Returns the directory as a pathlib.Path object, creating the directory if it does not already exist.
- sas.system.user.get_config_dir(create_if_nonexistent: bool = True) Path¶
The directory where os-specific configurations are stored.
Returns the directory as a pathlib.Path object, creating the directory if it does not already exist.
- sas.system.user.get_dir_and_create_if_needed(path: Path | str | PathLike[str], create_if_nonexistent: bool = True) Path¶
Returns the requested directory as a pathlib.Path object, creating the directory if it does not already exist.
- sas.system.user.get_log_dir(create_if_nonexistent: bool = True) Path¶
The directory where the os-specific logs are stored.
Returns the directory as a pathlib.Path object, creating the directory if it does not already exist.
- sas.system.user.get_plugin_dir(create_if_nonexistent: bool = True) Path¶
The directory where the os-specific cache for plugin models is stored.
Returns the directory as a pathlib.Path object, creating the directory if it does not already exist.
sas.system.version module¶
sas.system.web module¶
- class sas.system.web.WebLinks¶
Bases:
object- __dict__ = mappingproxy({'__module__': 'sas.system.web', '__init__': <function WebLinks.__init__>, '__dict__': <attribute '__dict__' of 'WebLinks' objects>, '__weakref__': <attribute '__weakref__' of 'WebLinks' objects>, '__doc__': None, '__annotations__': {}})¶
- __doc__ = None¶
- __init__()¶
- __module__ = 'sas.system.web'¶
- __weakref__¶
list of weak references to the object