Пример #1
0
    def _update_configs(configs, template=None):
        """
        Method: update the template with customized configs
        Params:
            configs: a dict type of configurations that describe the properties of milvus to be deployed
            template: Optional. Pass the template file location if there is a template to apply
        Return: a dict type customized configs
        """
        if not isinstance(configs, dict):
            log.error("customize configurations must be in dict type")
            return None

        if template is None:
            # d_configs = benedict()
            log.debug(f'template yaml {template_yaml}')
            d_configs = benedict.from_yaml(template_yaml)
            d_configs['apiVersion'] = f'{MILVUS_GRP}/{MILVUS_VER}'
            d_configs['kind'] = MILVUS_KIND
        else:
            d_configs = benedict.from_yaml(template)

        for key in configs.keys():
            d_configs[key] = configs[key]

        # return a python dict if it is not none
        return d_configs._dict if d_configs._dict is not None else d_configs
Пример #2
0
def load_config (logger, config):
    #Check that the config exists
    logger.info(f"Loading config file {config}")
    if os.path.exists(config):
        config_dict = benedict.from_yaml(config, keypath_separator=None)
    else:
        logger.error(f"Config file {config} does not exist. Exiting.")
        sys.exit(1)

    return config_dict
Пример #3
0
def load_config(stage: str) -> Dict:
    # Load common file
    try:
        common_config = benedict.from_yaml('config/common.yaml')
    except ValueError:
        print('No config found in config/common.yaml.')
        common_config = benedict([])

    # Load stage specific file
    try:
        env_config = benedict.from_yaml('config/' + stage + '.yaml')
    except ValueError:
        print('No config found in config/' + stage + '.yaml')
        env_config = benedict([])

    # merge the configs
    common_config.merge(env_config)

    # extract stage to set env
    common_config['stage'] = stage

    return common_config
Пример #4
0
def get_hosts(ctx, port_forward='portforward.yaml'):
    hosts = []
    # Get mapping ports
    config_file = get_config(port_forward)
    print("Loading", config_file)
    ports = benedict.from_yaml(config_file)
    private_key = get_config(os.path.join('private_key', ports['key']))
    for port, ip in ports['mapping'].items():
        hosts.append('localhost:' + str(port))

    print("user", ports['username'], "key_filename", private_key)

    return Group(*hosts,
                 user=ports['username'],
                 connect_kwargs={"key_filename": private_key})
Пример #5
0
def update_configs(yaml):
    if not isinstance(yaml, dict):
        log.error("customize configurations must be in dict type")
        return None

    template_yaml = 'template/default.yaml'
    _configs = benedict.from_yaml(template_yaml)

    for key in yaml.keys():
        _configs[key] = yaml[key]

    filename = gen_unique_str('cus_config')
    customized_yaml = f'template/{filename}.yaml'

    customized_yaml = _configs.to_yaml(filepath=customized_yaml)
    return customized_yaml
    def load_dict():
        yaml_str = """
SERVER:
    S01:
        alias: s01_alias
        ssh_port: s01_port
        host: s01_host
        credentials:
            username: s01_user
            password: s01_passw
        location:
            building: s01_building
            floar: s01_floar
            room: s01_room
        """
        servers = benedict.from_yaml(yaml_str)
        # print(servers.dump())
        return dict(servers)
Пример #7
0
runner.py

Example:
    $ python3 runner.py filename.yaml

"""
import sys

from benedict import benedict

from association_football.association_football import AssociationFootballLeague
from baseball.baseball import BaseballLeague
from basketball.basketball import BasketballLeague
from chess.chess_tournament import ChessTournament
from hockey.hockey import HockeyLeague


def play(params):
    sport = list(params.keys())[0]
    {
        'association football': AssociationFootballLeague,
        'baseball': BaseballLeague,
        'basketball': BasketballLeague,
        'chess': ChessTournament,
        'hockey': HockeyLeague,
    }[sport.lower()](**params[sport])


if __name__ == '__main__':
    play(benedict.from_yaml(sys.argv[1]))
Пример #8
0
                          aug=val_aug,
                          path=self.trn_path)
        val_dl = torch.utils.data.DataLoader(val_ds,
                                             shuffle=False,
                                             batch_size=self.batch_size,
                                             num_workers=self.num_workers)
        return val_dl


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--config', type=str, required=True)
    parser.add_argument('--resume', type=str, required=False)
    args = parser.parse_args()

    cfg = benedict.from_yaml(args.config)
    module = RanzcrModule(cfg=cfg)

    early_stop = EarlyStopping(monitor='val/_avg_roc_auc',
                               verbose=True,
                               patience=20,
                               mode='max')
    logger = TensorBoardLogger("lightning_logs", name=args.config)
    lrm = LearningRateMonitor()
    mdl_ckpt = ModelCheckpoint(monitor='val/_avg_roc_auc',
                               save_top_k=3,
                               mode='max')
    precision = get_or_default(cfg, 'precision', 32)
    grad_clip = float(get_or_default(cfg, 'grad_clip', 0))
    trainer = pl.Trainer(gpus=1,
                         max_epochs=100,
Пример #9
0
from benedict import benedict
from mosartwmpy.utilities.download_data import download_data
import pkg_resources

available_data = benedict.from_yaml(
    pkg_resources.resource_filename('mosartwmpy', 'data_manifest.yaml'))

data_list = []
data = []

for i, name in enumerate(available_data.keys()):
    data_list.append(name)
    data.append(f"""
        {i + 1}) {name} - {available_data.get(f'{name}.description')}""")

# clear the terminal
print(chr(27) + "[2J")

print(f"""
    🎶 Welcome to the mosartwmpy download utility! 🎵

       Please select the data you wish to download by typing the number:
""")

for d in data:
    print(f"""
    {d}""")

print(f"""
        
        0) exit
Пример #10
0
def get_app_configuration():
    try:
        # load configuration from yaml
        conf = benedict.from_yaml('configuration.yaml')
    except ValueError:
        raise Exception("Invalid yaml/yml file")
    except Exception:
        raise Exception("'configuration.yaml' file missing")

    host = conf['host'] if 'host' in conf else '0.0.0.0'
    port = conf['port'] if 'port' in conf else 80
    debug = bool(conf['debug'] if 'debug' in conf else False)

    # Get the webhook receiver path
    path = "/{}".format((conf['webhook-path']
                         if 'webhook-path' in conf else 'webhook').strip('/'))

    # Get the webhook receiver method
    method = conf['webhook-method'] if 'webhook-method' in conf else 'POST'
    # Convert method to array if not
    method = method if isinstance(method, list) else [method]
    # app name
    name = conf['app-name'] if 'app-name' in conf else __name__
    # get the secret key for incoming requests to match
    secret = conf['secret-key'] if 'secret-key' in conf else None
    # get the notification mediums
    mediums = conf[
        'notification-medium'] if 'notification-medium' in conf else 'slack'
    mediums = mediums if isinstance(mediums, list) else [mediums]

    available_mediums = {'slack': Slack}

    unsupported_medium = [
        item for item in mediums if item not in available_mediums.keys()
    ]

    app_env = conf['app-env'] if 'app-env' in conf else 'production'

    if len(unsupported_medium):
        raise Exception('Unsupported mediums: {}'.format(
            ", ".join(unsupported_medium)))

    slack_users = conf['users.slack'] if [
        'users', 'slack'
    ] in conf and conf['users.slack'] else {}
    # email_users = conf['users.email'] if ['users', 'email'] in conf and conf['users.email'] else {}

    custom_messages = conf['messages'] if 'messages' in conf else {}
    messages = {**DEFAULT_MESSAGES, **custom_messages}

    active_events = conf['listen-events'] if 'listen-events' in conf else None
    if not active_events or not hasattr(active_events, '__iter__'):
        active_events = (
            'opened',
            'commented',
            'assigned',
            'labeled',
            'review_requested',
            'review_request_removed',
            'approved',
            'changes_requested',
            'merged',
            'closed',
        )

    return {
        'app_env': app_env,
        'host': host,
        'port': port,
        'debug': debug,
        'name': name,
        'path': path,
        'methods': method,
        'secret': secret,
        'mediums': mediums,
        'available_mediums': available_mediums,
        'slack_users': slack_users,
        # 'email_users': email_users,
        'messages': messages,
        'slack_url': conf['slack-url'] if 'slack-url' in conf else '',
        'slack_channel':
        conf['slack-channel'] if 'slack-channel' in conf else 'random',
        'slack_username':
        conf['slack-username'] if 'slack-username' in conf else name,
        'slack_emoji':
        conf['slack-emoji'] if 'slack-emoji' in conf else ':gun:',
        'active_events': active_events,
    }
Пример #11
0
def read_config(filename):
    config_file = get_local_path(filename)
    print("Loading", config_file)
    return benedict.from_yaml(config_file)
Пример #12
0
def get_app_config(app_config="app.yaml"):
    app_cfg = get_config(app_config)
    print("Loading", app_cfg)
    return benedict.from_yaml(app_cfg)
Пример #13
0
from benedict import benedict

path = "/Volumes/MINE/CODE/SWIFT/FONTGEN/TEST.yaml"
font = benedict.from_yaml(path)  #load yaml

target = "Cwm fjord bank glyphs vext quiz"
fontFolder = font["all"]
original = fontFolder["text"]


def main(font, target, fontFolder, original, key):
    if not (key.endswith("-appendToStart") or key.endswith("-appendToEnd")
            or key.endswith("-reverse") or key.endswith("-appendAfterAll")
            or key.endswith("-appendBetween")
            or key.endswith("-appendToStartOfWord")
            or key.endswith("-appendToEndOfWord")
            or key.endswith("appendBetweenChar")
            or key.endswith("-appendAfterChar") or key.endswith("replace")):
        print(key)
        try:  #replace
            toReplace = fontFolder[fontName + "-replace"]
            normal = toReplace[0].split("Ϡ")
            to = toReplace[1].split("Ϡ")
            for n in range(len(normal)):
                target = target.replace(normal[n], to[n])
        except:
            pass

        try:  #appendBetweenChar
            toAppend = fontFolder[fontName + "-appendBetweenChar"]
#!/usr/bin/env python3
"""
Sample YAML extractor of query strings into .sqy
"""
import os
import re
import sys
from benedict import benedict
yaml_file = sys.argv[1]
yaml_dir = os.path.dirname(os.path.abspath(yaml_file))
yaml_dict = benedict.from_yaml(yaml_file)
for keypath in benedict.keypaths(yaml_dict):
    if re.match(r".*?\.query$", keypath):
        query_file = os.path.join(yaml_dir, keypath + '.sqy')
        print(query_file)
        with open(query_file, 'w') as file_object:
            file_object.write(yaml_dict[keypath])