API¶
tox objects¶
register¶
Manages the tox environment registry.
- class tox.tox_env.register.ToxEnvRegister¶
Bases:
objecttox environment registry.
- add_run_env(of_type)¶
Define a new run tox environment type.
- add_package_env(of_type)¶
Define a new packaging tox environment type.
- Parameters:
of_type (type[PackageToxEnv]) – the new packaging environment type
- Return type:
None
- runner(name)¶
Lookup a run tox environment type by name.
- tox.tox_env.register.REGISTER¶
the tox register
config¶
- class tox.config.cli.parser.ArgumentParserWithEnvAndConfig(*args, **kwargs)¶
Bases:
ArgumentParserArgument parser which updates its defaults by checking the configuration files and environmental variables.
- class tox.config.cli.parser.ToxParser(*args, root=False, add_cmd=False, **kwargs)¶
Bases:
ArgumentParserWithEnvAndConfigArgument parser for tox.
- add_command(cmd, aliases, help_msg, handler)¶
- Return type:
ArgumentParser
- add_argument(*args, of_type=None, **kwargs)¶
- add_argument(option_string, option_string, ..., name=value, ...) None
- Return type:
- classmethod base()¶
- Return type:
Self
- classmethod core()¶
- Return type:
Self
- class tox.config.main.Config¶
Bases:
objectMain configuration object for tox.
- pos_args(to_path)¶
- property core¶
- Return type:
- Returns:
the core configuration
- get_section_config(section, base, of_type, for_env, loaders=None)¶
- Return type:
T
- get_env(item, package=False, loaders=None)¶
Return the configuration for a given tox environment (will create if not exist yet).
- Parameters:
- Return type:
- Returns:
the tox environments config
- class tox.config.loader.section.Section(prefix, name)¶
Bases:
objecttox configuration section.
- SEP = ':'¶
string used to separate the prefix and the section in the key
- class tox.config.loader.api.ConfigLoadArgs(chain, name, env_name)¶
Bases:
objectArguments that help loading a configuration value.
- copy()¶
- Return type:
- Returns:
create a copy of the object
- class tox.config.sets.ConfigSet(conf, section, env_name)¶
Bases:
ABCA set of configuration that belong together (such as a tox environment settings, core tox settings).
- loaders¶
active configuration loaders, can alter to change configuration values
- get_configs()¶
- Return type:
- Returns:
a mapping of config keys to their definitions
- add_config(keys, of_type, default, desc, post_process=None, factory=None)¶
Add configuration value.
- Parameters:
keys (str | Sequence[str]) – the keys under what to register the config (first is primary key)
of_type (type[V]) – the type of the config value
default (Callable[[Config, str | None], V] | V) – the default value of the config value
desc (str) – a help message describing the configuration
post_process (Callable[[V], V] | None) – a callback to post-process the configuration value after it has been loaded
factory (Factory[Any] | None) – factory method used to build contained objects (if
of_typeis a container type it should perform the contained item creation, otherwise creates objects that match the type)
- Return type:
- Returns:
the new dynamic config definition
- add_constant(keys, desc, value)¶
Add a constant value.
- load(item, chain=None)¶
Get the config value for a given key (will materialize in case of dynamic config).
- __iter__()¶
- __contains__(item)¶
Check if a configuration key is within the config set.
- unused()¶
- primary_key(key)¶
Get the primary key for a config key.
- class tox.config.sets.CoreConfigSet(conf, section, root, src_path)¶
Bases:
ConfigSetConfiguration set for the core tox config.
- class tox.config.sets.EnvConfigSet(conf, section, env_name)¶
Bases:
ConfigSetConfiguration set for a tox environment.
- class tox.config.of_type.ConfigDefinition(keys, desc)¶
-
Abstract base class for configuration definitions.
- class tox.config.of_type.ConfigDynamicDefinition(keys, desc, of_type, default, post_process=None, factory=None)¶
Bases:
ConfigDefinition[T]A configuration definition that comes from a source (such as in memory, an ini file, a toml file, etc.).
- class tox.config.of_type.ConfigConstantDefinition(keys, desc, value)¶
Bases:
ConfigDefinition[T]A configuration definition whose value is defined upfront (such as the tox environment name).
- class tox.config.source.api.Source(path)¶
Bases:
ABCSource is able to return a configuration value (for either the core or per environment source).
- FILENAME = ''¶
- path¶
the path to the configuration source
- get_loaders(section, base, override_map, conf)¶
Return a loader that loads settings from a given section name.
- abstract sections()¶
Return a loader that loads the core configuration values.
- abstract envs(core_conf)¶
- Parameters:
core_conf (CoreConfigSet) – the core configuration set
- Return type:
Iterator[str]
- Returns:
a list of environments defined within this source
- abstract get_tox_env_section(item)¶
- class tox.config.loader.api.Loader(section, overrides)¶
-
Loader loads configuration values and converts it.
- property section¶
Return the section of the configuration from where the values are extracted.
- Return type:
- abstract load_raw(key, conf, env_name)¶
Load the raw object from the config store.
- abstract found_keys()¶
A list of configuration keys found within the configuration.
- load(key, of_type, factory, conf, args)¶
Load a value (raw and then convert).
- Parameters:
key (str) – the key under it lives
of_type (type[V]) – the type to convert to
factory (Factory[V]) – factory method to build the object
conf (Config | None) – the configuration object of this tox session (needed to manifest the value)
args (ConfigLoadArgs) – the config load arguments
- Return type:
V
- Returns:
the converted type
- build(key, of_type, factory, conf, raw, args)¶
Materialize the raw configuration value from the loader.
- Parameters:
future – a future which when called will provide the converted config value
key (str) – the config key
of_type (type[V]) – the config type
conf (Config | None) – the global config
raw (T) – the raw value
args (ConfigLoadArgs) – env args
- Return type:
V
- class tox.config.loader.memory.MemoryLoader(**kwargs)¶
-
Loads configuration directly from data in memory.
- load_raw(key, conf, env_name)¶
Load the raw object from the config store.
- static to_bool(value)¶
Convert to boolean.
- static to_str(value)¶
Convert to string.
- static to_list(value, of_type)¶
Convert to list.
- static to_set(value, of_type)¶
Convert to set.
- static to_dict(value, of_type)¶
Convert to dictionary.
- static to_path(value)¶
Convert to path.
- static to_command(value)¶
Convert to a command to execute.
- class tox.config.loader.convert.Convert¶
-
A class that converts a raw type to a given tox (python) type.
- to(raw, of_type, factory)¶
Convert given raw type to python type.
- abstract static to_str(value)¶
Convert to string.
- Parameters:
value (~T) – the value to convert
- Return type:
- Returns:
a string representation of the value
- abstract static to_bool(value)¶
Convert to boolean.
- Parameters:
value (~T) – the value to convert
- Return type:
- Returns:
a boolean representation of the value
- abstract static to_list(value, of_type)¶
Convert to list.
- abstract static to_set(value, of_type)¶
Convert to set.
- abstract static to_dict(value, of_type)¶
Convert to dictionary.
- abstract static to_path(value)¶
Convert to path.
- Parameters:
value (~T) – the value to convert
- Return type:
- Returns:
path representation of the value
- abstract static to_command(value)¶
Convert to a command to execute.
environments¶
- class tox.tox_env.api.ToxEnv(create_args)¶
Bases:
ABCA tox environment.
- journal¶
handler to the tox reporting system
- conf¶
the config set to use for this environment
- core¶
the core tox config set
- options¶
CLI options
- log_handler¶
handler to the tox reporting system
- execute_async(cmd, stdin, show=None, cwd=None, run_id='', executor=None)¶
- Return type:
Iterator[ExecuteStatus]
- class tox.tox_env.package.PackageToxEnv(create_args)¶
-
- register_run_env(run_env)¶
- Return type:
Generator[tuple[str, str], PackageToxEnv, None]
- mark_active_run_env(run_env)¶
- Return type:
None
- teardown_env(conf)¶
- Return type:
None
- abstract child_pkg_envs(run_conf)¶
- Return type:
Iterator[PackageToxEnv]
journal¶
report¶
- class tox.report.ToxHandler(level, is_colored, out_err)¶
Bases:
StreamHandler- with_context(name)¶
Set a new tox environment context.
- property stdout¶
- Return type:
TextIOWrapper- Returns:
the current standard output
- property stderr¶
- Return type:
TextIOWrapper- Returns:
the current standard error
execute¶
- class tox.execute.request.ExecuteRequest(cmd, cwd, env, stdin, run_id, allow=None)¶
Bases:
objectDefines a commands execution request.
- cmd¶
the command to run
- cwd¶
the working directory to use
- env¶
the environment variables to use
- stdin¶
the type of standard input interaction allowed
- run_id¶
an id to identify this run
- class tox.execute.request.StdinSource(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
Enum- OFF = 0¶
input disabled
- USER = 1¶
input via the standard input
- API = 2¶
input via programmatic access
- static user_only()¶
- Return type:
- Returns:
USERif the standard input is tty type elseOFF
- class tox.execute.api.Outcome(request, show_on_standard, exit_code, out, err, start, end, cmd, metadata)¶
Bases:
objectResult of a command execution.
- OK = 0¶
- request¶
the execution request
- show_on_standard¶
a flag indicating if the execution was shown on stdout/stderr
- exit_code¶
the exit code for the execution
- out¶
the standard output of the execution
- err¶
the standard error of the execution
- start¶
a timer sample for the start of the execution
- end¶
a timer sample for the end of the execution
- cmd¶
the command as executed
- metadata¶
additional metadata attached to the execution
- log_run_done(lvl)¶
Log that the run was done.
- Parameters:
lvl (
int) – the level on what to log as interpreted bylogging.log()- Return type:
- class tox.execute.api.Execute(colored)¶
Bases:
ABCAbstract API for execution of a tox environment.
- call(request, show, out_err, env)¶
- Return type:
Iterator[ExecuteStatus]
- abstract build_instance(request, options, out, err)¶
- Return type:
- classmethod register_conf(env)¶
- Return type:
None
- class tox.execute.api.ExecuteInstance(request, options, out, err)¶
Bases:
ABCAn instance of a command execution.
- class tox.execute.stream.SyncWrite(name, target, color=None)¶
Bases:
objectMake sure data collected is synced in-memory and to the target stream on every newline and time period.
Used to propagate executed commands output to the standard output/error streams visible to the user.
- REFRESH_RATE = 0.1¶
installer¶
session¶
- class tox.session.state.State(options, args)¶
Bases:
objectRuntime state holder.
- property envs¶
- Return type:
- Returns:
provides access to the tox environments
- class tox.session.env_select.EnvSelector(state)¶
Bases:
object- iter(*, only_active=True, package=False)¶
Get tox environments.
- class tox.tox_env.info.Info(path)¶
Bases:
objectStores metadata about the tox environment.
- compare(value, section, sub_section=None)¶
Compare new information with the existing one and update if differs.
- Parameters:
- Return type:
- Returns:
a tuple where the first value is if it differs and the second is the old value