Example #1
0
File: logger.py Project: jzuhone/yt
def _runtime_configuration(ytcfg: YTConfig) -> None:
    # only run this at the end of yt.__init__, after yt.config.ytcfg was instanciated

    global _original_emitter, _yt_sh

    if ytcfg.get("yt", "stdout_stream_logging"):
        stream = sys.stdout
    else:
        stream = sys.stderr

    _level = min(max(ytcfg.get("yt", "log_level"), 0), 50)

    if ytcfg.get("yt", "suppress_stream_logging"):
        disable_stream_logging()
    else:
        _yt_sh = logging.StreamHandler(stream=stream)
        # create formatter and add it to the handlers
        formatter = logging.Formatter(ufstring)
        _yt_sh.setFormatter(formatter)
        # add the handler to the logger
        ytLogger.addHandler(_yt_sh)
        ytLogger.setLevel(_level)
        ytLogger.propagate = False

        _original_emitter = _yt_sh.emit

        if ytcfg.get("yt", "colored_logs"):
            colorize_logging()
Example #2
0
def _setup_ramses_particle_families(ytcfg: YTConfig) -> None:
    if not ytcfg.has_section("ramses-families"):
        return
    for key in particle_families.keys():
        val = ytcfg.get("ramses-families", key, callback=None)
        if val is not None:
            mylog.info("Changing family %s from %s to %s", key,
                       particle_families[key], val)
            particle_families[key] = val
Example #3
0
 def setUpClass(cls):
     cls.xdg_config_home = os.environ.get("XDG_CONFIG_HOME")
     cls.tmpdir = tempfile.mkdtemp()
     os.mkdir(os.path.join(cls.tmpdir, "yt"))
     os.environ["XDG_CONFIG_HOME"] = cls.tmpdir
     with open(YTConfig.get_global_config_file(), mode="w") as fh:
         fh.write(_DUMMY_CFG_TOML)
     cls.plugin_path = os.path.join(config_dir(), ytcfg.get("yt", "plugin_filename"))
     with open(cls.plugin_path, mode="w") as fh:
         fh.write(TEST_PLUGIN_FILE)
Example #4
0
    def testConfigCommands(self):
        def remove_spaces_and_breaks(s):
            return "".join(s.split())

        self.assertFalse(os.path.exists(YTConfig.get_global_config_file()))

        info = self._runYTConfig(["--help"])
        self.assertEqual(info["rc"], 0)
        self.assertEqual(info["stderr"], "")
        self.assertIn(
            remove_spaces_and_breaks("Get and set configuration values for yt"),
            remove_spaces_and_breaks(info["stdout"]),
        )

        info = self._runYTConfig(["list"])
        self.assertEqual(info["rc"], 0)
        self.assertEqual(info["stdout"], "")

        self._testKeyValue("internals.parallel", True, True)
        self._testKeyValue(
            "test_data_dir", "~/yt-data", os.path.expanduser("~/yt-data")
        )
        self._testKeyValue(
            "test_data_dir", "$HOME/yt-data", os.path.expandvars("$HOME/yt-data")
        )

        with self.assertRaises(KeyError):
            self._runYTConfig(["get", "yt", "foo"])

        # Check TypeErrors are raised when changing the type of an entry
        self._testKeyTypeError("foo.bar", "test", 10, expect_error=True)
        self._testKeyTypeError("foo.bar", "test", False, expect_error=True)

        # Check no type error are raised when *not* changing the type
        self._testKeyTypeError("foo.bar", 10, 20, expect_error=False)
        self._testKeyTypeError("foo.bar", "foo", "bar", expect_error=False)
Example #5
0
        parallel=False,
        strict_requires=False,
        global_parallel_rank=0,
        global_parallel_size=1,
        topcomm_parallel_rank=0,
        topcomm_parallel_size=1,
        command_line=False,
    ),
)


# For backward compatibility, do not use these vars internally in yt
CONFIG_DIR = config_dir()


_global_config_file = YTConfig.get_global_config_file()
_local_config_file = YTConfig.get_local_config_file()

# Load the config
ytcfg = YTConfig()
ytcfg.update(ytcfg_defaults, metadata={"source": "defaults"})

# Try loading the local config first, otherwise fall back to global config
if os.path.exists(_local_config_file):
    ytcfg.read(_local_config_file)
elif os.path.exists(_global_config_file):
    ytcfg.read(_global_config_file)


def _setup_postinit_configuration():
    """This is meant to be run last in yt.__init__"""
Example #6
0
 def setUp(self):
     super().setUp()
     with open(YTConfig.get_local_config_file(), mode="w") as f:
         f.writelines("[yt]\n")
     with open(YTConfig.get_global_config_file(), mode="w") as f:
         f.writelines("[yt]\n")
Example #7
0
 def tearDown(self):
     if os.path.exists(YTConfig.get_global_config_file()):
         os.remove(YTConfig.get_global_config_file())
     super().tearDown()