Utility functions for Brian.
Utility functions to get information about the environment Brian is running in.
|running_from_ipython()||Check whether we are currently running under ipython.|
File system tools
|in_directory(new_dir)||Safely temporarily work in a subdirectory|
|copy_directory(source, target)||Copies directory source to target.|
|ensure_directory(d)||Ensures that a given directory exists (creates it if necessary)|
|ensure_directory_of_file(f)||Ensures that a directory exists for filename to go in (creates if necessary), and returns the directory path.|
Brian’s logging module.
Logging system preferences
logging.console_log_level = 'WARNING'
What log level to use for the log written to the console.
Has to be one of CRITICAL, ERROR, WARNING, INFO or DEBUG.
logging.delete_log_on_exit = True
Whether to delete the log and script file on exit.
If set to True (the default), log files (and the copy of the main script) will be deleted after the brian process has exited, unless an uncaught exception occured. If set to False, all log files will be kept.
logging.file_log = True
Whether to log to a file or not.
If set to True (the default), logging information will be written to a file. The log level can be set via the logging.file_log_level preference.
logging.file_log_level = 'DEBUG'
What log level to use for the log written to the log file.
In case file logging is activated (see logging.file_log), which log level should be used for logging. Has to be one of CRITICAL, ERROR, WARNING, INFO or DEBUG.
logging.save_script = True
Whether to save a copy of the script that is run.
If set to True (the default), a copy of the currently run script is saved to a temporary location. It is deleted after a successful run (unless logging.delete_log_on_exit is False) but is kept after an uncaught exception occured. This can be helpful for debugging, in particular when several simulations are running in parallel.
logging.std_redirection = True
Whether or not to redirect stdout/stderr to null at certain places.
This silences a lot of annoying compiler output, but will also hide error messages making it harder to debug problems. You can always temporarily switch it off when debugging. In any case, the output is saved to a file and if an error occurs the name of this file will be printed.
|BrianLogger(name)||Convenience object for logging.|
|HierarchyFilter(name)||A class for suppressing all log messages in a subtree of the name hierarchy.|
|LogCapture(log_list[, log_level])||A class for capturing log warnings.|
|NameFilter(name)||A class for suppressing log messages ending with a certain name.|
|catch_logs([log_level])||A context manager for catching log messages.|
|std_silent([alwaysprint])||Context manager that temporarily silences stdout and stderr but keeps the output saved in a temporary file and writes it if an exception is raised.|
|brian_excepthook(exc_type, exc_obj, exc_tb)||Display a message mentioning the debug log in case of an uncaught exception.|
|clean_up_logging()||Shutdown the logging system and delete the debug log file if no error occured.|
|get_logger([module_name])||Get an object that can be used for logging.|
A collection of tools for string formatting tasks.
|SpellChecker(words[, alphabet])||A simple spell checker that will be used to suggest the correct name if the user made a typo (e.g.|
|code_representation(code)||Returns a string representation for several different formats of code|
|deindent(text[, numtabs, spacespertab, ...])||Returns a copy of the string with the common indentation removed.|
|get_identifiers(expr[, include_numbers])||Return all the identifiers in a given string expr, that is everything that matches a programming language variable like expression, which is here implemented as the regexp \b[A-Za-z_][A-Za-z0-9_]*\b.|
|indent(text[, numtabs, spacespertab, tab])||Indents a given multiline string.|
|replace(s, substitutions)||Applies a dictionary of substitutions.|
|strip_empty_leading_and_trailing_lines(s)||Removes all empty leading and trailing lines in the multi-line string s.|
|strip_empty_lines(s)||Removes all empty lines from the multi-line string s.|
|stripped_deindented_lines(code)||Returns a list of the lines in a multi-line string, deindented.|
|word_substitute(expr, substitutions)||Applies a dict of word substitutions.|