How to use the invoke.config.Config function in invoke

To help you get started, we’ve selected a few invoke examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyinvoke / invoke / tests / config.py View on Github external
def allows_comparison_with_real_dicts(self):
            c = Config({"foo": {"bar": "biz"}})
            assert c["foo"] == {"bar": "biz"}
github pyinvoke / invoke / tests / config.py View on Github external
def overrides_can_be_given_via_method(self):
                c = Config(defaults={"foo": "bar"})
                assert c.foo == "bar"  # defaults level
                c.load_overrides({"foo": "notbar"})
                assert c.foo == "notbar"  # overrides level
github pyinvoke / invoke / tests / config.py View on Github external
def overrides_dict_is_also_a_kwarg(self):
            c = Config(overrides={"run": {"hide": True}})
            assert c.run.hide is True
github pyinvoke / invoke / tests / config.py View on Github external
def can_defer_loading_system_and_user_files(self, load_u, load_s):
            config = Config(lazy=True)
            assert not load_s.called
            assert not load_u.called
            # Make sure default levels are still in place! (When bug present,
            # i.e. merge() never called, config appears effectively empty.)
            assert config.run.echo is False
github pyinvoke / invoke / tests / config.py View on Github external
def subkeys_get_merged_not_overwritten(self):
            # Ensures nested keys merge deeply instead of shallowly.
            defaults = {"foo": {"bar": "baz"}}
            overrides = {"foo": {"notbar": "notbaz"}}
            c = Config(defaults=defaults, overrides=overrides)
            assert c.foo.notbar == "notbaz"
            assert c.foo.bar == "baz"
github pyinvoke / invoke / tests / config.py View on Github external
def config_itself_stored_as_private_name(self):
            # I.e. one can refer to a key called 'config', which is relatively
            # commonplace (e.g. .myservice.config -> a config file
            # contents or path or etc)
            c = Config()
            c["foo"] = {"bar": "baz"}
            c["whatever"] = {"config": "myconfig"}
            assert c.foo.bar == "baz"
            assert c.whatever.config == "myconfig"
github pyinvoke / invoke / tests / config.py View on Github external
def runtime_overrides_collection(self):
            c = Config(runtime_path=join(CONFIGS_PATH, "json", "invoke.json"))
            c.load_collection({"outer": {"inner": {"hooray": "defaults"}}})
            c.load_runtime()
            assert c.outer.inner.hooray == "json"
github pyinvoke / invoke / tests / config.py View on Github external
        @patch.object(Config, "merge")
        def system_and_user_files_loaded_automatically(
            self, merge, load_u, load_s
        ):
            Config()
            load_s.assert_called_once_with(merge=False)
            load_u.assert_called_once_with(merge=False)
            merge.assert_called_once_with()
github pyinvoke / invoke / tests / config.py View on Github external
def booleans(self):
                for input_, result in (
                    ("0", False),
                    ("1", True),
                    ("", False),
                    ("meh", True),
                    ("false", True),
                ):
                    os.environ["INVOKE_FOO"] = input_
                    c = Config(defaults={"foo": bool()})
                    c.load_shell_env()
                    assert c.foo == result
github ooni / sysadmin / tasks.py View on Github external
from __future__ import absolute_import, print_function, unicode_literals

import logging
import logging.config
import json
import time
import traceback
import sys
import os

from invoke.config import Config
from invoke import Collection, ctask as task

config = Config(runtime_path="invoke.yaml")
assert config._runtime_found, "you probably need to 'cp invoke.yaml.example invoke.yaml'"

os.environ["PYTHONPATH"] = os.environ.get("PYTHONPATH") if os.environ.get("PYTHONPATH") else ""
os.environ["PYTHONPATH"] = ":".join(os.environ["PYTHONPATH"].split(":") + [config.core.ooni_sysadmin_path])

class Timer(object):
    def __init__(self):
        self.start_time = None
        self.end_time = None

    @property
    def runtime(self):
        if self.start_time is None:
            raise RuntimeError("Did not call start")
        if self.end_time:
            return self.end_time - self.start_time