Profiles¶
- class omnifig.organization.profiles.ProfileBase(data=None)¶
Bases:
AbstractProfile
Generally, a run environment uses a single profile to keep track of loading projects, and invoking the top level methods (such as
entry()
,main()
,run()
,quick_run()
, etc.).It is recommended to subclass this class to create a custom profile classes with expected functionality (unlike
AbstractProfile
).- behavior_registry = {'debug': _Behavior_Registry_Entry(name='debug', cls=<class 'omnifig.behaviors.debug.Debug'>, description='Switch to debug mode'), 'help': _Behavior_Registry_Entry(name='help', cls=<class 'omnifig.behaviors.help.Help'>, description='Display this help message'), 'quiet': _Behavior_Registry_Entry(name='quiet', cls=<class 'omnifig.behaviors.quiet.Quiet'>, description='Set config to silent')}¶
- Project¶
alias of
ProjectBase
- classmethod get_project_type(ident, default=<class 'omnibelt.typing.unspecified_argument'>)¶
Gets the project type entry for the given identifier (from a registry).
- Parameters:
ident (
str
) – Name of the registered project type.default (
Optional
[Any
]) – Default value to return if the identifier is not found.
- Return type:
NamedTuple
- Returns:
Project type entry.
- classmethod replace_profile(profile=None)¶
Replaces the current profile instance with the given profile. This is used to set the global profile.
- Parameters:
profile (
ProfileBase
) – New profile instance.- Return type:
- Returns:
Old profile instance (which is now replaced).
- classmethod get_profile()¶
Gets the current profile instance of the runtime environment.
- Return type:
- Returns:
Profile instance.
- classmethod register_behavior(name, typ, *, description=None)¶
Registers a new behavior in the profile.
Behaviors are classes which are instantiated and managed by .
- Parameters:
name (
str
) – Name of the behavior.typ (
Type
[AbstractBehavior
]) – Behavior class (recommended to subclassAbstractBehavior
).description (
Optional
[str
]) – Description of the behavior.
- Return type:
NamedTuple
- Returns:
Registration entry for the behavior.
- classmethod get_behavior(name)¶
Gets the behavior entry for the given identifier (from the registry).
- Parameters:
name (
str
) – Name of the registered behavior.- Return type:
NamedTuple
- Returns:
Behavior entry.
- classmethod iterate_behaviors()¶
Iterates over all registered behaviors.
- Return type:
Iterator
[NamedTuple
]- Returns:
Iterator over all behavior entries.
- __init__(data=None)¶
Loads the info if the provided data is a file path.
- Parameters:
data (
Dict
[str
,Any
]) – A file path to a yaml file, or a dictionary containing the info**kwargs – Other arguments passed on to
super()
- property path¶
- entry(script_name=None)¶
Primary entry point for the profile. This method is called when using the fig command.
- Parameters:
script_name (
Optional
[str
]) – Manually specified script name to run (if not provided, will be parsed fromsys.argv
).- Return type:
None
- Returns:
None
- initialize(*projects, **kwargs)¶
Initializes the specified projects (including activating them, which generally registers all associated configs and imports files and packages)
- Parameters:
*projects (
str
) – Identifiers of projects to initialize (activates the current project only, if none is provided).- Return type:
None
- Returns:
None
- main(argv, script_name=<class 'omnibelt.typing.unspecified_argument'>)¶
Runs the script with the given arguments using
main()
of the current project.- Parameters:
argv (
Sequence
[str
]) – List of top-level arguments (expected to besys.argv[1:]
).script_name (
Optional
[str
]) – specified name of the scriptobject). ((defaults to what is specified in argv when it is parsed into a config) –
- Return type:
None
- Returns:
The output of the script.
- run_script(script_name, config, *args, **kwargs)¶
Runs the script registered with the given name and the given arguments using
run_script()
of the current project.- Parameters:
script_name (
str
) – Name of the script to run (must be registered).config (
AbstractConfig
) – Config object to run the script with.*args (
Any
) – Manual arguments to pass to the script.**kwargs (
Any
) – Manual keyword arguments to pass to the script.
- Return type:
Any
- Returns:
The output of the script.
- run(config, *args, **kwargs)¶
Runs the script with the given arguments using
run()
of the current project.- Parameters:
config (
AbstractConfig
) – Config object to run the script with.*args (
Any
) – Manual arguments to pass to the script.**kwargs (
Any
) – Manual keyword arguments to pass to the script.
- Returns:
The output of the script.
- quick_run(script_name, *configs, **parameters)¶
Creates a config object and runs the script using
quick_run()
of the current project.- Parameters:
script_name (
str
) – Name of the script to run (should be registered).*configs (
str
) – Names of registered config files to load and merge (in order of precedence).**parameters (
Any
) – Manual config parameters to populate the config object with.
- Returns:
Output of the script.
- cleanup(*args, **kwargs)¶
Calls
cleanup()
of the current project.- Parameters:
*args (
Any
) – Arguments to pass to the cleanup function.**kwargs (
Any
) – Keyword arguments to pass to the cleanup function.
- Return type:
None
- Returns:
None
- create_config(*configs, **parameters)¶
Process the provided data to create a config object (using the current project).
- Parameters:
configs (
str
) – usually a list of parent configs to be mergedparameters (
Union
[Dict
[str
,Union
[Dict
[str
, JSONABLE],List
[JSONABLE],str
,int
,float
,bool
,None
]],List
[Union
[Dict
[str
, JSONABLE],List
[JSONABLE],str
,int
,float
,bool
,None
]],str
,int
,float
,bool
,None
]) – any manual parameters to include in the config object
- Return type:
- Returns:
Config object resulting from loading/merging configs and including data.
- parse_argv(argv, script_name=None)¶
Parses the given arguments and returns a config object.
- Arguments are expected in the following order (all of which are optional):
Behaviors to modify the config loading process and script execution.
Name of the script to run.
Names of registered config files that should be loaded and merged (in order of precedence).
Manual config parameters (usually keys, prefixed by
--
and corresponding values)
- Parameters:
argv (
Sequence
[str
]) – List of arguments to parse (expected to besys.argv[1:]
).script_name – Manually specified name of the script (defaults to what is specified in the resulting config).
- Return type:
- Returns:
Config object containing the parsed arguments.
- extract_info(other)¶
Extract data from the provided profile instance and store it in self.
Recommended to use if a project expects a custom profile different from the currently used one.
- Parameters:
profile – Base profile instance.
- Return type:
None
- Returns:
None
- get_current_project()¶
Gets the current project instance.
- Return type:
- Returns:
Current project instance.
- create_project(name, path=None, set_as_current=True)¶
Creates a new project instance and registers it.
- Parameters:
name (
str
) – Name of the project.path (
Path
) – Path to the project (defaults to the current working directory).set_as_current (
bool
) – If True, sets the new project as the current project.
- Return type:
- Returns:
New project instance.
- switch_project(ident=None)¶
Switches the current project to the one with the given identifier.
- Parameters:
ident (
Union
[str
,AbstractProject
]) – Name of the project to switch to, defaults to the default project (with name: None).- Return type:
- Returns:
New current project instance.
- iterate_projects()¶
Iterates over all loaded projects.
- Return type:
Iterator
[AbstractProject
]- Returns:
Iterator over all loaded project instances.
- project_context(ident=None)¶
Context manager to temporarily switch to a different current project.
- Parameters:
ident (
Union
[str
,AbstractProject
]) – Name of the project to switch to, defaults to the default project (with name: None).- Return type:
ContextManager
[AbstractProject
]- Returns:
Context manager to switch to the specified project.
- omnifig.organization.profiles.get_profile()¶
Returns the current profile instance.
- Return type: