Exemple #1
0
def load_multi_configs(file_args, cmd_args):
    """This method try to mimics the behavior of the sub_config. It currently
    only take one base and one main.

    Args:
      file_args:
      cmd_args:

    Returns:

    """
    cl_conf = load_command_line_config(cmd_args)

    if len(file_args) > 0:
        base_conf = file_args[0]

        loader = PyFileConfigLoader(base_conf)
        loader.load_config()

        for conf in file_args[1:]:
            # Since subconfig will be merged to and override the base.
            loader.load_subconfig(conf)

        all_conf = loader.config
        all_conf.merge(cl_conf)
        return all_conf
    else:
        return cl_conf
Exemple #2
0
def load_config():
    loader = PyFileConfigLoader(CONFIG_FILE_NAME, CONFIG_SEARCH_PATH)
    try:
        config = loader.load_config()
    except ConfigFileNotFound:
        config = Config()
    return config
Exemple #3
0
 def test_python(self):
     fd, fname = mkstemp('.py', prefix=u'μnïcø∂e')
     f = os.fdopen(fd, 'w')
     f.write(pyfile)
     f.close()
     # Unlink the file
     cl = PyFileConfigLoader(fname, log=log)
     config = cl.load_config()
     self._check_conf(config)
Exemple #4
0
 def load_config(self) -> None:
     """設定ファイルを読み込みパラメータを更新する."""
     p = Path(CONFIG_FILE)
     if p.exists():
         # 設定ファイルが存在すれば読み込む.
         loader = PyFileConfigLoader(str(p))
         c = loader.load_config()
         # 自身のパラメータを更新する.
         self.update_config(c)
Exemple #5
0
 def test_python(self):
     fd, fname = mkstemp('.py', prefix=u'μnïcø∂e')
     f = os.fdopen(fd, 'w')
     f.write(pyfile)
     f.close()
     # Unlink the file
     cl = PyFileConfigLoader(fname, log=log)
     config = cl.load_config()
     self._check_conf(config)
Exemple #6
0
 def test_python(self):
     fd, fname = mkstemp(".py")
     f = os.fdopen(fd, "w")
     f.write(pyfile)
     f.close()
     # Unlink the file
     cl = PyFileConfigLoader(fname, log=log)
     config = cl.load_config()
     self._check_conf(config)
Exemple #7
0
def get_config_from_file(path, content):
    # Write config file
    filename = 'config.py'
    config_file = path / filename
    config_file.write_text(content)

    # Load written file.
    loader = PyFileConfigLoader(filename, path=str(path))
    cfg = loader.load_config()
    return cfg
Exemple #8
0
def config_ipw(ipw):
    """Apply and then modify default settings of IPython Qt widget"""
    ipython_dir = get_ipython_dir()
    profile_dir = os.path.join(ipython_dir, 'profile_default')
    cl = PyFileConfigLoader('ipython_qtconsole_config.py', profile_dir)
    config = cl.load_config()
    ipw.config = config

    ipw.set_default_style(colors='Linux')
    ipw.font = QtGui.QFont('Lucida Console', 11) # 3rd arg can be e.g. QFont.Bold
    ipw.font.setFixedPitch(True)
Exemple #9
0
    def __init__(self) -> None:
        """コンストラクタ.

        - 外部設定ファイルが存在する場合は読込み、このクラスのプロパティを更新します.
        """
        p = Path.home() / ".myclock" / "config.py"
        if p.exists():
            # 設定ファイルが存在すれば読み込む.
            loader = PyFileConfigLoader(str(p))
            c = loader.load_config()
            # 自身のパラメータを更新する.
            self.update_config(c)
Exemple #10
0
def config_ipw(ipw):
    """Apply and then modify default settings of IPython Qt widget"""
    ipython_dir = get_ipython_dir()
    profile_dir = os.path.join(ipython_dir, 'profile_default')
    cl = PyFileConfigLoader('ipython_config.py', profile_dir)
    config = cl.load_config()
    ipw.config = config

    ipw.set_default_style(colors='Linux')
    ipw.font = QtGui.QFont('Lucida Console', 11) # 3rd arg can be e.g. QFont.Bold
    ipw.font.setFixedPitch(True)
    ipw.buffer_size = 100000 # number of scrollback lines to keep before truncation
Exemple #11
0
def config_ipw(ipw):
    """Apply and then modify default settings of IPython Qt widget"""
    ipython_dir = get_ipython_dir()
    profile_dir = os.path.join(ipython_dir, 'profile_default')
    cl = PyFileConfigLoader('ipython_config.py', profile_dir)
    config = cl.load_config()
    ipw.config = config

    ipw.set_default_style(colors='Linux')
    ipw.font = QtGui.QFont('Lucida Console',
                           11)  # 3rd arg can be e.g. QFont.Bold
    ipw.font.setFixedPitch(True)
    ipw.buffer_size = 100000  # number of scrollback lines to keep before truncation
Exemple #12
0
import os

from dotenv import load_dotenv

load_dotenv(os.getenv('IGIT_ENV_FILE'))
# from igit_debug.loggr import Loggr
from traitlets.config import Unicode, Configurable
from traitlets.config.loader import PyFileConfigLoader


class MyClass(Configurable):
    name = Unicode(u'defaultname', help="the name of the object").tag(config=True)
    raise_config_file_errors = True


IGIT_DIR = os.environ.get('IGIT_DIR')
cl = PyFileConfigLoader('igitconfig.py',
                        path=IGIT_DIR,
                        # log=Loggr()
                        )
cfg = cl.load_config()
myinst = MyClass(config=cfg)
print(f"{myinst = }")
print(f"{myinst.name = }")
Exemple #13
0
def get_config(filename='nbx_config.py'):
    config_dir = jupyter_config_dir()
    pyloader = PyFileConfigLoader(filename, path=config_dir)
    config = pyloader.load_config()
    return config
Exemple #14
0
def load_file_config(config_path):
    loader = PyFileConfigLoader(config_path)
    conf = loader.load_config()
    return conf