spotterbase.utils package

Submodules

spotterbase.utils.config_loader module

Code extensible for configuration and configuration management.

Both, configuration files and (optionally) command line arguments are supported (using configargparse). The configuration can be extended with custom ConfigExtension.

The configuration can be loaded with the ConfigLoader.

class spotterbase.utils.config_loader.ArgumentGroup(name: str, description: str)

Bases: _Group

prepare_argparser(argparser: ArgumentParser)
class spotterbase.utils.config_loader.ConfigExtension

Bases: object

Can be used to adjust anything related to ArgumentParser, in particular to add further arguments.

prepare_argparser(argparser: ArgumentParser)
process_namespace(args: Namespace)
class spotterbase.utils.config_loader.ConfigFlag(name: str, description: str, group: _Group | None = None, **kwargs)

Bases: SimpleConfigExtension

value: bool = False
class spotterbase.utils.config_loader.ConfigInt(name: str, description: str, group: _Group | None = None, **kwargs)

Bases: SimpleConfigExtension

value: int | None = None
class spotterbase.utils.config_loader.ConfigLoader(extensions: list[ConfigExtension] | None = None, config_paths: list[Path] | None = None)

Bases: object

config_has_been_loaded: ClassVar[bool] = False
default_extensions: list[ConfigExtension] = [<spotterbase.utils.config_loader.LogConfigExtension object>, <spotterbase.sparql.sb_sparql.EndpointConfig object>, <spotterbase.sparql.sb_sparql.EndpointConfig object>, <spotterbase.utils.config_loader.ArgumentGroup object>, <spotterbase.data.locator.Locator object>, <spotterbase.data.locator.Locator object>, <spotterbase.data.locator.Locator object>, <spotterbase.data.zipfilecache.SharedZipFileCacheExtension object>, <spotterbase.utils.config_loader.ArgumentGroup object>, <spotterbase.utils.config_loader.ConfigInt object>, <spotterbase.utils.config_loader.ConfigPath object>]
load_from_args(args: list[str] | None = None) Namespace
load_from_namespace(namespace: Namespace)
class spotterbase.utils.config_loader.ConfigPath(name: str, description: str, group: _Group | None = None, **kwargs)

Bases: SimpleConfigExtension

value: Path | None = None
class spotterbase.utils.config_loader.ConfigString(name: str, description: str, group: _Group | None = None, **kwargs)

Bases: SimpleConfigExtension

value: str | None = None
class spotterbase.utils.config_loader.ConfigUri(name: str, description: str, group: _Group | None = None, **kwargs)

Bases: SimpleConfigExtension

value: Uri | None = None
class spotterbase.utils.config_loader.LogConfigExtension

Bases: ConfigExtension

prepare_argparser(argparser: ArgumentParser)
process_namespace(namespace: Namespace)
class spotterbase.utils.config_loader.MutexGroup(required: bool, group: ArgumentGroup | None = None)

Bases: _Group

prepare_argparser(argparser: ArgumentParser)
class spotterbase.utils.config_loader.SimpleConfigExtension(name: str, description: str, group: _Group | None = None, **kwargs)

Bases: ConfigExtension

prepare_argparser(argparser: ArgumentParser)
process_namespace(args: Namespace)
value: Any
spotterbase.utils.config_loader.auto(args: list[str] | None = None)

spotterbase.utils.exit module

spotterbase.utils.exit.DefaultSignalDelay()
class spotterbase.utils.exit.SignalDelayManager(signals_to_delay: list[Signals])

Bases: object

A very hacky implementation to delay signals to ensure that crucial operations can finish undisturbed. I’m fairly sure that not all edge cases have been covered

spotterbase.utils.logging module

spotterbase.utils.logging.warn_once(logger: Logger, message: str)

spotterbase.utils.plugin_loader module

Loads SpotterBase plugins.

load_plugins is called from spotterbase.__init__

class spotterbase.utils.plugin_loader.LoadingStatus(error: str | None = None, message: str | None = None)

Bases: object

error: str | None = None
message: str | None = None
spotterbase.utils.plugin_loader.load_core_plugins()
spotterbase.utils.plugin_loader.load_plugins()
spotterbase.utils.plugin_loader.log_plugin_loading_results()

Logging is only configured after plugins are loaded.

spotterbase.utils.progress_updater module

class spotterbase.utils.progress_updater.FixedDelay(delay_in_secs: float = 5)

Bases: PrintTimerStrategy

delay_in_secs: float = 5
get_delay_in_sec() float
class spotterbase.utils.progress_updater.IncreasingDelay(start_delay_secs: float, end_delay_secs: float)

Bases: PrintTimerStrategy

Increases the delay to show frequent updates initially without j

get_delay_in_sec() float
class spotterbase.utils.progress_updater.PrintTimerStrategy

Bases: ABC

abstract get_delay_in_sec() float
class spotterbase.utils.progress_updater.ProgressUpdater(message: str, timer_strategy: PrintTimerStrategy | None = None)

Bases: object

Prints regular messages about the progress of a large task.

Note that it does not start a background thread and only considers creating a log when update() is called.

update(progress)

Logs the progress iff enough time has passed since the last log message.

spotterbase.utils.resources module

spotterbase.utils.snippet_runner_utils module

Utilities for running documentation snippets

They are used in snippet_test.py files in the documentation to run the snippets and ensure they are up-to-date.

spotterbase.utils.snippet_runner_utils.run_python_file(py_file: Path, cwd: Path | None = None) str
spotterbase.utils.snippet_runner_utils.run_shell_file(shell_file: Path, cwd: Path | None = None) str

spotterbase.utils.sphinx_rdf module

A Sphinx extension for dealing with RDF and SB records.

class spotterbase.utils.sphinx_rdf.AbstractRdfDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)

Bases: SphinxDirective

has_content = True

May the directive have content?

option_spec: dict[str, Callable[[str], Any]] = {'show': <function unchanged>}

Mapping of option names to validator functions.

optional_arguments = 0

Number of optional arguments after the required arguments.

required_arguments = 1

Number of required directive arguments.

run()
class spotterbase.utils.sphinx_rdf.RdfDomain(env: BuildEnvironment)

Bases: Domain

directives: dict[str, type[Directive]] = {'record': <class 'spotterbase.utils.sphinx_rdf.RecordDirective'>, 'turtle': <class 'spotterbase.utils.sphinx_rdf.TurtleDirective'>}

directive name -> directive class

get_full_qualified_name(node)

Return full qualified name for given node.

get_objects()

Return an iterable of “object descriptions”.

Object descriptions are tuples with six items:

name

Fully qualified name.

dispname

Name to display when searching/linking.

type

Object type, a key in self.object_types.

docname

The document where it is to be found.

anchor

The anchor name for the object.

priority

How “important” the object is (determines placement in search results). One of:

1

Default priority (placed before full-text matches).

0

Object is important (placed before default-priority objects).

2

Object is unimportant (placed after full-text matches).

-1

Object should not show up in search at all.

indices: dict = {}

a list of Index subclasses

initial_data: dict = {}

data value for a fresh environment

label = 'RDF domain'

domain label: longer, more descriptive (used in messages)

name = 'rdf'

domain name: should be short, but unique

roles: dict = {}

role name -> role callable

class spotterbase.utils.sphinx_rdf.RecordDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)

Bases: AbstractRdfDirective

class spotterbase.utils.sphinx_rdf.TurtleDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)

Bases: AbstractRdfDirective

spotterbase.utils.sphinx_rdf.html_visit_rdfnode(self: HTML5Translator, node: rdfnode) None
class spotterbase.utils.sphinx_rdf.rdfnode(rawsource='', *children, **attributes)

Bases: General, Element

Confusingly, this is a Sphinx node, corresponding to a small RDF graph (not a node in an RDF graph).

spotterbase.utils.sphinx_rdf.setup(app: Sphinx)

spotterbase.utils.sphinx_warnings module

class spotterbase.utils.sphinx_warnings.SbLinkWarnings(document, startnode=None)

Bases: SphinxPostTransform

nitpicky=True is too strict for me, this is essentially a restricted form under my control

default_priority = 5

Numerical priority of this transform, 0 through 999 (override).

run()

Main method of post transforms.

Subclasses should override this method instead of apply().

spotterbase.utils.sphinx_warnings.setup(app: Sphinx)

Module contents