API¶
Main Functionalities¶
-
fret.
workspace
(path, config=None, config_dict=None)¶ Workspace utilities. One can save/load configurations, build models with specific configuration, save snapshots, open results, etc., using workspace objects.
-
fret.
configurable
(wraps=None, submodules=None, build_subs=True, states=None)[source]¶ Class decorator that registers configurable module under current app.
Parameters:
-
fret.
command
(wraps=None, help=None, description=None)[source]¶ Function decorator that would turn a function into a fret command.
-
class
fret.
argspec
(*args, **kwargs)[source]¶ In control of the behavior of commands. Replicates arguments for
argparse.ArgumentParser.add_argument()
.
Common Components¶
-
class
fret.common.
Module
(**kwargs)[source]¶ Interface for configurable modules.
Each module class should have an
add_arguments
class method to define model arguments along with their types, default values, etc.Parameters: config (dict) – module configuration
-
class
fret.common.
Plugin
[source]¶ Interface for external plugin
Pour new commands, or modify workspace object.
-
class
fret.common.
argspec
(*args, **kwargs)[source]¶ In control of the behavior of commands. Replicates arguments for
argparse.ArgumentParser.add_argument()
.
-
class
fret.common.
funcspec
(f)[source]¶ Utility to generate argument specification from function signature.
-
fret.common.
command
(wraps=None, help=None, description=None)[source]¶ Function decorator that would turn a function into a fret command.
-
fret.common.
configurable
(wraps=None, submodules=None, build_subs=True, states=None)[source]¶ Class decorator that registers configurable module under current app.
Parameters:
-
class
fret.workspace.
Workspace
(path, config=None, config_dict=None)[source]¶ Workspace utilities. One can save/load configurations, build models with specific configuration, save snapshots, open results, etc., using workspace objects.
-
build
(name='main', **kwargs)[source]¶ Build module according to the configurations in current workspace.
-
load
(name='main', tag=None, path=None)[source]¶ Load module from a snapshot.
Parameters: tag (str or pathlib.Path) – snapshot tag or path.
-
log
(*filename)[source]¶ Get log file path within current workspace.
Parameters: filename (str or list) – relative path to file; if ommited, returns root path of logs.
-
logger
(name: str)[source]¶ Get a logger that logs to a file under workspace.
Notice that same logger instance is returned for same names.
Parameters: name (str) – logger name
-
result
(*filename)[source]¶ Get result file path within current workspace.
Parameters: filename (str or list) – relative path to file; if ommited, returns root path of results.
-
run
(tag, resume=True)[source]¶ Initiate a context manager that provides a persistent running environment. Mainly used to suspend and resume a time consuming process.
-
save
(obj, tag)[source]¶ Save module as a snapshot.
Parameters: tag (str or pathlib.Path) – snapshot tag or path.
-
snapshot
(*filename)[source]¶ Get snapshot file path within current workspace.
Parameters: filename (str or list) – relative path to file; if ommited, returns root path of snapshots.
-
config_path
¶ Workspace configuration path.
-
path
¶ Workspace root path.
-
-
class
fret.workspace.
Run
(ws, tag, resume)[source]¶ Class designed for running state persistency.
Application Object and CLI¶
-
class
fret.cli.
ParserBuilder
(parser, style='java')[source]¶ Utility to generate CLI arguments in different styles.
-
class
fret.cli.
_ArgumentParser
(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True)[source]¶
-
fret.cli.
clean
(ws, config=(False, 'remove workspace configuration'), log=(False, 'clear workspace logs'), snapshot=(False, 'clear snapshots'), everything=<fret.common.argspec object>, all=<fret.common.argspec object>, force=(False, 'do without confirmation'))[source]¶ Command
clean
.Remove all snapshots in specific workspace. If
--all
is specified, clean the entire workspace
Utilities¶
-
class
fret.util.
ColoredFormatter
(fmt=None, datefmt=None, style='%')[source]¶ Formatter for colored log.
Initialize the formatter with specified format strings.
Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.
Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting,
str.format()
({}
) formatting orstring.Template
formatting in your format string.Changed in version 3.2: Added the
style
parameter.-
format
(record)[source]¶ Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
-
-
class
fret.util.
Configuration
(*args, **kwargs)[source]¶ Easy to construct, use and read configuration class.
-
class
fret.util.
Iterator
(data, *label, prefetch=False, length=None, batch_size=None, shuffle=True, full_shuffle=False)[source]¶ Iterator on data and labels, with states for save and restore.
-
fret.util.
colored
(fmt, fg=None, bg=None, style=None)[source]¶ Return colored string.
- List of colours (for fg and bg):
- k: black
- r: red
- g: green
- y: yellow
- b: blue
- m: magenta
- c: cyan
- w: white
- List of styles:
- b: bold
- i: italic
- u: underline
- s: strike through
- x: blinking
- r: reverse
- y: fast blinking
- f: faint
- h: hide
Parameters: