jacinle.config.environ#

Classes

Environ

A global environment object.

Functions

get_env([default])

Get a value of a environment provided a key.

has_env(key)

Check whether a key is in current env object.

load_env([incremental])

set_env([value, do_inc, do_replace, inc_default])

Set an environment value by key-value pair.

update_env(env_spec)

with_env(env_spec[, incremental])

Class Environ

class Environ[source]#

Bases: object

A global environment object.

__init__(envs=None)[source]#
__new__(**kwargs)#
as_dict()[source]#
as_dict_ref()[source]#
clone()[source]#
dump(path, prefix=None)[source]#
get(default=None)[source]#

Get a value of a environment provided a key. You can provide a default value, but this value will not affect the env object.

Parameters:
  • key – the key. Dict of dict can (should) be imploded by ..

  • default – the default value.

Returns:

The value if the env contains the given key, otherwise the default value provided.

has(key)[source]#

Check whether a key is in current env object.

Parameters:

key (str) – the key.

Returns:

True if the key is in current env object, otherwise False.

Return type:

bool

inc(key, inc=1, default=0)[source]#

Increase the environment value provided a key.

Parameters:
  • key (str) – the key.

  • inc (Any) – the increment.

  • default (Any) – the default value.

Returns:

self

keys(is_flattened=True)[source]#
load(incremental=False)[source]#
set(value=None, do_inc=False, do_replace=True, inc_default=0)[source]#

Set an environment value by key-value pair.

Parameters:
  • key (str) – the key, note that dict of dict can (should) be imploded by ``.’’.

  • value (Any) – the value.

  • do_inc (bool) – whether to increase the value.

  • do_replace (bool) – whether to replace the value if the key already exists.

  • inc_default (Any) – the default value of the accumulator.

Returns:

self

set_default(key, default=None)[source]#

Set an environment value by key-value pair. If the key already exists, it will not be overwritten.

Parameters:
  • key (str) – the key, note that dict of dict can (should) be imploded by ``.’’.

  • default (Any) – the default value.

  • key – the key, note that dict of dict can (should) be imploded by ``.’’.

  • default – the ``default’’ value.

Returns:

self

Returns:

self

update(env_spec)[source]#

Functions

get_env()#

Get a value of a environment provided a key. You can provide a default value, but this value will not affect the env object.

Parameters:
  • key – the key. Dict of dict can (should) be imploded by ..

  • default – the default value.

Returns:

The value if the env contains the given key, otherwise the default value provided.

has_env(key)#

Check whether a key is in current env object.

Parameters:

key (str) – the key.

Returns:

True if the key is in current env object, otherwise False.

Return type:

bool

load_env()#
set_env(do_inc=False, do_replace=True, inc_default=0)#

Set an environment value by key-value pair.

Parameters:
  • key – the key, note that dict of dict can (should) be imploded by ``.’’.

  • value (Any) – the value.

  • do_inc (bool) – whether to increase the value.

  • do_replace (bool) – whether to replace the value if the key already exists.

  • inc_default (Any) – the default value of the accumulator.

Returns:

self

update_env(env_spec)#
with_env(env_spec, incremental=True)[source]#