From 3eb05580828a114fe881ff03e31c1bbc9a5ad73d Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 7 Dec 2022 19:32:54 -0800 Subject: [PATCH 1/8] Rename config to _config. --- signac/{config.py => _config.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename signac/{config.py => _config.py} (100%) diff --git a/signac/config.py b/signac/_config.py similarity index 100% rename from signac/config.py rename to signac/_config.py From 6d6be0f7ffde08baf521b7194c1c4e30618ea437 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 7 Dec 2022 19:36:06 -0800 Subject: [PATCH 2/8] Fix import and uses in __main__. --- signac/__main__.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/signac/__main__.py b/signac/__main__.py index b18f54c8c..7211be8e0 100644 --- a/signac/__main__.py +++ b/signac/__main__.py @@ -29,7 +29,15 @@ else: READLINE = True -from . import config, get_project, init_project +from . import get_project, init_project +from ._config import ( + PROJECT_CONFIG_FN, + USER_CONFIG_FN, + _Config, + _load_config, + _locate_config_dir, + _read_config_file, +) from ._utility import _add_verbosity_argument, _print_err, _query_yes_no, _safe_relpath from ._vendor.configobj import Section, flatten_errors from .diff import diff_jobs @@ -663,12 +671,12 @@ def main_config_show(args): if args.local and args.globalcfg: raise ValueError("You can specify either -l/--local or -g/--global, not both.") elif args.local: - if os.path.isfile(config.PROJECT_CONFIG_FN): - cfg = config._read_config_file(config.PROJECT_CONFIG_FN) + if os.path.isfile(PROJECT_CONFIG_FN): + cfg = _read_config_file(PROJECT_CONFIG_FN) elif args.globalcfg: - cfg = config._read_config_file(config.USER_CONFIG_FN) + cfg = _read_config_file(USER_CONFIG_FN) else: - cfg = config._load_config(config._locate_config_dir(os.getcwd())) + cfg = _load_config(_locate_config_dir(os.getcwd())) if not cfg: if args.local: mode = "local" @@ -686,7 +694,7 @@ def main_config_show(args): if not isinstance(cfg, Section): print(cfg) else: - for line in config._Config(cfg).write(): + for line in _Config(cfg).write(): print(line) @@ -717,12 +725,12 @@ def main_config_verify(args): if args.local and args.globalcfg: raise ValueError("You can specify either -l/--local or -g/--global, not both.") elif args.local: - if os.path.isfile(config.PROJECT_CONFIG_FN): - cfg = config._read_config_file(config.PROJECT_CONFIG_FN) + if os.path.isfile(PROJECT_CONFIG_FN): + cfg = _read_config_file(PROJECT_CONFIG_FN) elif args.globalcfg: - cfg = config._read_config_file(config.USER_CONFIG_FN) + cfg = _read_config_file(USER_CONFIG_FN) else: - cfg = config._load_config(config._locate_config_dir(os.getcwd())) + cfg = _load_config(_locate_config_dir(os.getcwd())) if not cfg: if args.local: mode = "local" @@ -746,16 +754,16 @@ def main_config_set(args): if args.local and args.globalcfg: raise ValueError("You can specify either -l/--local or -g/--global, not both.") elif args.local: - if os.path.isfile(config.PROJECT_CONFIG_FN): - fn_config = config.PROJECT_CONFIG_FN + if os.path.isfile(PROJECT_CONFIG_FN): + fn_config = PROJECT_CONFIG_FN elif args.globalcfg: - fn_config = config.USER_CONFIG_FN + fn_config = USER_CONFIG_FN else: raise ValueError( "You need to specify either -l/--local or -g/--global " "to specify which configuration to modify." ) - cfg = config._read_config_file(fn_config) + cfg = _read_config_file(fn_config) keys = args.key.split(".") if len(args.value) == 0: raise ValueError("No value argument provided!") From e64feb7af2d3c13f3d58d72520f74e10791d3113 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 7 Dec 2022 19:39:41 -0800 Subject: [PATCH 3/8] Fix other uses in package. --- signac/migration/v1_to_v2.py | 9 ++++----- signac/project.py | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/signac/migration/v1_to_v2.py b/signac/migration/v1_to_v2.py index e2da1e526..224c1d587 100644 --- a/signac/migration/v1_to_v2.py +++ b/signac/migration/v1_to_v2.py @@ -15,11 +15,10 @@ import os -from signac._synced_collections.backends.collection_json import BufferedJSONAttrDict -from signac._vendor import configobj -from signac.config import _get_project_config_fn -from signac.project import Project - +from .._config import _get_project_config_fn +from .._synced_collections.backends.collection_json import BufferedJSONAttrDict +from .._vendor import configobj +from ..project import Project from .v0_to_v1 import _load_config_v1 # A minimal v2 config. diff --git a/signac/project.py b/signac/project.py index fe43f5cb1..54c76bf9e 100644 --- a/signac/project.py +++ b/signac/project.py @@ -20,10 +20,7 @@ from tempfile import TemporaryDirectory from threading import RLock -from ._search_indexer import _SearchIndexer -from ._synced_collections.backends.collection_json import BufferedJSONAttrDict -from ._utility import _mkdir_p, _nested_dicts_to_dotted_keys, _split_and_print_progress -from .config import ( +from ._config import ( _Config, _get_project_config_fn, _load_config, @@ -31,6 +28,9 @@ _raise_if_older_schema, _read_config_file, ) +from ._search_indexer import _SearchIndexer +from ._synced_collections.backends.collection_json import BufferedJSONAttrDict +from ._utility import _mkdir_p, _nested_dicts_to_dotted_keys, _split_and_print_progress from .errors import ( DestinationExistsError, IncompatibleSchemaVersion, From ebab3d9b963b6a8f731e61e0c07ac7e330e8cad0 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 7 Dec 2022 19:49:21 -0800 Subject: [PATCH 4/8] Fix remaining minor tests. --- tests/test_job.py | 5 +++-- tests/test_project.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_job.py b/tests/test_job.py index 3979461f4..85df7de8c 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -12,7 +12,8 @@ import pytest -import signac.config +import signac +from signac._config import _load_config from signac.errors import ( DestinationExistsError, InvalidKeyError, @@ -64,7 +65,7 @@ def setUp(self, request): request.addfinalizer(self._tmp_dir.cleanup) self._tmp_pr = os.path.join(self._tmp_dir.name, "pr") os.mkdir(self._tmp_pr) - self.config = signac.config._load_config() + self.config = _load_config() self.project = self.project_class.init_project(path=self._tmp_pr) def tearDown(self): diff --git a/tests/test_project.py b/tests/test_project.py index e5c9cca63..42b860b37 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -22,7 +22,7 @@ from test_job import TestJobBase import signac -from signac.config import ( +from signac._config import ( PROJECT_CONFIG_FN, _get_project_config_fn, _load_config, From 2bdd3b6cd19ae24bd1c9b06b4214b7be7c19d81f Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 7 Dec 2022 19:51:57 -0800 Subject: [PATCH 5/8] Update test_shell.py. --- tests/test_shell.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test_shell.py b/tests/test_shell.py index 83fd1d374..073223e71 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -12,7 +12,7 @@ from test_project import _initialize_v1_project import signac -from signac import config +from signac._config import USER_CONFIG_FN, _Config, _load_config, _read_config_file # Skip linked view tests on Windows WINDOWS = sys.platform == "win32" @@ -743,18 +743,18 @@ def test_config_show(self): self.call("python -m signac init".split()) out = self.call("python -m signac config --local show".split()).strip() - cfg = config._read_config_file(".signac/config") - expected = config._Config(cfg).write() + cfg = _read_config_file(".signac/config") + expected = _Config(cfg).write() assert out.split(os.linesep) == expected out = self.call("python -m signac config show".split()).strip() - cfg = config._load_config() - expected = config._Config(cfg).write() + cfg = _load_config() + expected = _Config(cfg).write() assert out.split(os.linesep) == expected out = self.call("python -m signac config --global show".split()).strip() - cfg = config._read_config_file(config.USER_CONFIG_FN) - expected = config._Config(cfg).write() + cfg = _read_config_file(USER_CONFIG_FN) + expected = _Config(cfg).write() assert out.split(os.linesep) == expected def test_config_set(self): @@ -769,12 +769,12 @@ def test_config_set(self): assert "[x]" in cfg assert "y = z" in cfg - backup_config = os.path.exists(config.USER_CONFIG_FN) - global_config_path_backup = config.USER_CONFIG_FN + ".tmp" + backup_config = os.path.exists(USER_CONFIG_FN) + global_config_path_backup = USER_CONFIG_FN + ".tmp" try: # Make a backup of the global config if it exists if backup_config: - shutil.copy2(config.USER_CONFIG_FN, global_config_path_backup) + shutil.copy2(USER_CONFIG_FN, global_config_path_backup) # Test the global config CLI self.call("python -m signac config --global set b c".split()) @@ -785,9 +785,9 @@ def test_config_set(self): # Revert the global config to its previous state (or remove it if # it did not exist) if backup_config: - shutil.move(global_config_path_backup, config.USER_CONFIG_FN) + shutil.move(global_config_path_backup, USER_CONFIG_FN) else: - os.remove(config.USER_CONFIG_FN) + os.remove(USER_CONFIG_FN) def test_config_verify(self): # no config file From f94a2a7f1e77b73f17f3df708b4efad81f2c2c83 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 7 Dec 2022 19:56:22 -0800 Subject: [PATCH 6/8] Remove redundant leading underscores now that the modules are public. --- signac/__main__.py | 24 ++++++++++++------------ signac/_config.py | 28 ++++++++++++++-------------- signac/migration/v1_to_v2.py | 4 ++-- signac/project.py | 28 ++++++++++++++-------------- tests/test_job.py | 4 ++-- tests/test_project.py | 14 +++++++------- tests/test_shell.py | 14 +++++++------- 7 files changed, 58 insertions(+), 58 deletions(-) diff --git a/signac/__main__.py b/signac/__main__.py index 7211be8e0..dfec93468 100644 --- a/signac/__main__.py +++ b/signac/__main__.py @@ -33,10 +33,10 @@ from ._config import ( PROJECT_CONFIG_FN, USER_CONFIG_FN, - _Config, - _load_config, - _locate_config_dir, - _read_config_file, + Config, + load_config, + locate_config_dir, + read_config_file, ) from ._utility import _add_verbosity_argument, _print_err, _query_yes_no, _safe_relpath from ._vendor.configobj import Section, flatten_errors @@ -672,11 +672,11 @@ def main_config_show(args): raise ValueError("You can specify either -l/--local or -g/--global, not both.") elif args.local: if os.path.isfile(PROJECT_CONFIG_FN): - cfg = _read_config_file(PROJECT_CONFIG_FN) + cfg = read_config_file(PROJECT_CONFIG_FN) elif args.globalcfg: - cfg = _read_config_file(USER_CONFIG_FN) + cfg = read_config_file(USER_CONFIG_FN) else: - cfg = _load_config(_locate_config_dir(os.getcwd())) + cfg = load_config(locate_config_dir(os.getcwd())) if not cfg: if args.local: mode = "local" @@ -694,7 +694,7 @@ def main_config_show(args): if not isinstance(cfg, Section): print(cfg) else: - for line in _Config(cfg).write(): + for line in Config(cfg).write(): print(line) @@ -726,11 +726,11 @@ def main_config_verify(args): raise ValueError("You can specify either -l/--local or -g/--global, not both.") elif args.local: if os.path.isfile(PROJECT_CONFIG_FN): - cfg = _read_config_file(PROJECT_CONFIG_FN) + cfg = read_config_file(PROJECT_CONFIG_FN) elif args.globalcfg: - cfg = _read_config_file(USER_CONFIG_FN) + cfg = read_config_file(USER_CONFIG_FN) else: - cfg = _load_config(_locate_config_dir(os.getcwd())) + cfg = load_config(locate_config_dir(os.getcwd())) if not cfg: if args.local: mode = "local" @@ -763,7 +763,7 @@ def main_config_set(args): "You need to specify either -l/--local or -g/--global " "to specify which configuration to modify." ) - cfg = _read_config_file(fn_config) + cfg = read_config_file(fn_config) keys = args.key.split(".") if len(args.value) == 0: raise ValueError("No value argument provided!") diff --git a/signac/_config.py b/signac/_config.py index ead6e492f..a3ca12a3e 100644 --- a/signac/_config.py +++ b/signac/_config.py @@ -19,11 +19,11 @@ """ -def _get_project_config_fn(path): +def get_project_config_fn(path): return os.path.abspath(os.path.join(path, PROJECT_CONFIG_FN)) -def _raise_if_older_schema(root): +def raise_if_older_schema(root): """Raise if an older schema version is detected at the search path. Parameters @@ -59,7 +59,7 @@ def _raise_if_older_schema(root): pass -def _locate_config_dir(search_path): +def locate_config_dir(search_path): """Locates directory containing a signac configuration file in a directory hierarchy. Parameters @@ -75,7 +75,7 @@ def _locate_config_dir(search_path): orig_search_path = search_path search_path = os.path.abspath(search_path) while True: - if os.path.isfile(_get_project_config_fn(search_path)): + if os.path.isfile(get_project_config_fn(search_path)): return search_path if (up := os.path.dirname(search_path)) == search_path: break @@ -89,7 +89,7 @@ def _locate_config_dir(search_path): search_path = os.path.abspath(orig_search_path) while True: - _raise_if_older_schema(search_path) + raise_if_older_schema(search_path) if (up := os.path.dirname(search_path)) == search_path: logger.debug("Reached filesystem root, no config found.") return None @@ -97,7 +97,7 @@ def _locate_config_dir(search_path): search_path = up -class _Config(ConfigObj): +class Config(ConfigObj): """Manages configuration for a signac project.""" def verify(self, *, preserve_errors=False): @@ -105,10 +105,10 @@ def verify(self, *, preserve_errors=False): return super().validate(Validator(), preserve_errors=preserve_errors) -def _read_config_file(filename): +def read_config_file(filename): logger.debug(f"Reading config file '{filename}'.") try: - config = _Config(filename, configspec=_CFG.split("\n")) + config = Config(filename, configspec=_CFG.split("\n")) except (OSError, ConfigObjError) as error: raise ConfigError(f"Failed to read configuration file '{filename}':\n{error}") verification = config.verify() @@ -123,7 +123,7 @@ def _read_config_file(filename): return config -def _load_config(path=None): +def load_config(path=None): """Load configuration from a project directory. Parameters @@ -133,21 +133,21 @@ def _load_config(path=None): Returns -------- - :class:`_Config` + :class:`Config` The composite configuration including both project-local and global config data if requested. Note that because this config is a composite, modifications to the returned value will not be reflected in the files. """ if path is None: path = os.getcwd() - config = _Config(configspec=_CFG.split("\n")) + config = Config(configspec=_CFG.split("\n")) # Add in any global or user config files. For now this only finds user-specific # files, but it could be updated in the future to support e.g. system-wide config files. for fn in (USER_CONFIG_FN,): if os.path.isfile(fn): - config.merge(_read_config_file(fn)) + config.merge(read_config_file(fn)) - if os.path.isfile(_get_project_config_fn(path)): - config.merge(_read_config_file(_get_project_config_fn(path))) + if os.path.isfile(get_project_config_fn(path)): + config.merge(read_config_file(get_project_config_fn(path))) return config diff --git a/signac/migration/v1_to_v2.py b/signac/migration/v1_to_v2.py index 224c1d587..a56f4a83d 100644 --- a/signac/migration/v1_to_v2.py +++ b/signac/migration/v1_to_v2.py @@ -15,7 +15,7 @@ import os -from .._config import _get_project_config_fn +from .._config import get_project_config_fn from .._synced_collections.backends.collection_json import BufferedJSONAttrDict from .._vendor import configobj from ..project import Project @@ -74,7 +74,7 @@ def _migrate_v1_to_v2(root_directory): # Move signac.rc to .signac/config v1_fn = os.path.join(root_directory, "signac.rc") - v2_fn = _get_project_config_fn(root_directory) + v2_fn = get_project_config_fn(root_directory) os.mkdir(os.path.dirname(v2_fn)) os.replace(v1_fn, v2_fn) diff --git a/signac/project.py b/signac/project.py index 54c76bf9e..dfadee08d 100644 --- a/signac/project.py +++ b/signac/project.py @@ -21,12 +21,12 @@ from threading import RLock from ._config import ( - _Config, - _get_project_config_fn, - _load_config, - _locate_config_dir, - _raise_if_older_schema, - _read_config_file, + Config, + get_project_config_fn, + load_config, + locate_config_dir, + raise_if_older_schema, + read_config_file, ) from ._search_indexer import _SearchIndexer from ._synced_collections.backends.collection_json import BufferedJSONAttrDict @@ -50,7 +50,7 @@ JOB_ID_REGEX = re.compile(f"[a-f0-9]{{{JOB_ID_LENGTH}}}") -class _ProjectConfig(_Config): +class _ProjectConfig(Config): r"""Extends the project config to make it immutable. Parameters @@ -104,15 +104,15 @@ class Project: def __init__(self, path=None): if path is None: path = os.getcwd() - if not os.path.isfile(_get_project_config_fn(path)): - _raise_if_older_schema(path) + if not os.path.isfile(get_project_config_fn(path)): + raise_if_older_schema(path) raise LookupError( f"Unable to find project at path '{os.path.abspath(path)}'." ) # Project constructor does not search upward, so the provided path must # be a project directory. - config = _load_config(path) + config = load_config(path) self._config = _ProjectConfig(config) self._lock = RLock() @@ -1454,9 +1454,9 @@ def init_project(cls, path=None): try: project = cls.get_project(path=path, search=False) except LookupError: - fn_config = _get_project_config_fn(path) + fn_config = get_project_config_fn(path) _mkdir_p(os.path.dirname(fn_config)) - config = _read_config_file(fn_config) + config = read_config_file(fn_config) config["schema_version"] = SCHEMA_VERSION config.write() project = cls.get_project(path=path) @@ -1499,10 +1499,10 @@ def get_project(cls, path=None, search=True, **kwargs): ) old_path = path - if not search and not os.path.isfile(_get_project_config_fn(path)): + if not search and not os.path.isfile(get_project_config_fn(path)): path = None else: - path = _locate_config_dir(path) + path = locate_config_dir(path) if not path: raise LookupError( diff --git a/tests/test_job.py b/tests/test_job.py index 85df7de8c..3568b440b 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -13,7 +13,7 @@ import pytest import signac -from signac._config import _load_config +from signac._config import load_config from signac.errors import ( DestinationExistsError, InvalidKeyError, @@ -65,7 +65,7 @@ def setUp(self, request): request.addfinalizer(self._tmp_dir.cleanup) self._tmp_pr = os.path.join(self._tmp_dir.name, "pr") os.mkdir(self._tmp_pr) - self.config = _load_config() + self.config = load_config() self.project = self.project_class.init_project(path=self._tmp_pr) def tearDown(self): diff --git a/tests/test_project.py b/tests/test_project.py index 42b860b37..fb0005aeb 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -24,9 +24,9 @@ import signac from signac._config import ( PROJECT_CONFIG_FN, - _get_project_config_fn, - _load_config, - _read_config_file, + get_project_config_fn, + load_config, + read_config_file, ) from signac.errors import ( DestinationExistsError, @@ -2291,7 +2291,7 @@ def test_project_schema_versions(self): assert version.parse(self.project.config["schema_version"]) < version.parse( impossibly_high_schema_version ) - config = _read_config_file(_get_project_config_fn(self.project.path)) + config = read_config_file(get_project_config_fn(self.project.path)) config["schema_version"] = impossibly_high_schema_version config.write() with pytest.raises(IncompatibleSchemaVersion): @@ -2366,7 +2366,7 @@ def test_project_schema_version_migration( # If no schema version is present in the config it is equivalent to # version 0, so we test both explicit and implicit versions. - config = _read_config_file(cfg_fn) + config = read_config_file(cfg_fn) if implicit_version: del config["schema_version"] assert "schema_version" not in config @@ -2383,7 +2383,7 @@ def test_project_schema_version_migration( err = io.StringIO() with redirect_stderr(err): apply_migrations(dirname) - config = _load_config(dirname) + config = load_config(dirname) assert config["schema_version"] == "2" project = signac.get_project(path=dirname) assert project.config["schema_version"] == "2" @@ -2441,7 +2441,7 @@ def setUp_base_h5Store(self, request): request.addfinalizer(self._tmp_dir.cleanup) self._tmp_pr = os.path.join(self._tmp_dir.name, "pr") os.mkdir(self._tmp_pr) - self.config = _load_config() + self.config = load_config() self.project = self.project_class.init_project(path=self._tmp_pr) self._fn_store = os.path.join(self._tmp_dir.name, "signac_data.h5") diff --git a/tests/test_shell.py b/tests/test_shell.py index 073223e71..d766ee78a 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -12,7 +12,7 @@ from test_project import _initialize_v1_project import signac -from signac._config import USER_CONFIG_FN, _Config, _load_config, _read_config_file +from signac._config import USER_CONFIG_FN, Config, load_config, read_config_file # Skip linked view tests on Windows WINDOWS = sys.platform == "win32" @@ -743,18 +743,18 @@ def test_config_show(self): self.call("python -m signac init".split()) out = self.call("python -m signac config --local show".split()).strip() - cfg = _read_config_file(".signac/config") - expected = _Config(cfg).write() + cfg = read_config_file(".signac/config") + expected = Config(cfg).write() assert out.split(os.linesep) == expected out = self.call("python -m signac config show".split()).strip() - cfg = _load_config() - expected = _Config(cfg).write() + cfg = load_config() + expected = Config(cfg).write() assert out.split(os.linesep) == expected out = self.call("python -m signac config --global show".split()).strip() - cfg = _read_config_file(USER_CONFIG_FN) - expected = _Config(cfg).write() + cfg = read_config_file(USER_CONFIG_FN) + expected = Config(cfg).write() assert out.split(os.linesep) == expected def test_config_set(self): From 5db52551464dd20990efb6ebc68cd3db7fc0120a Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 7 Dec 2022 20:22:11 -0800 Subject: [PATCH 7/8] Update changelog. --- changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 9baa08f3d..24e74b2b0 100644 --- a/changelog.txt +++ b/changelog.txt @@ -54,7 +54,7 @@ Removed - The ability to pass indexes to various ``Project`` methods (#599). - The following ``JobsCursor`` methods: ``groupbydoc``, ``next`` (#601, #604). - The ``Project.config`` property is no longer mutable. Use the command line ``$ signac config`` to modify configuration (#608, #246, #244). - - The following config related functions: ``get_config``, ``load_config``, ``read_config_file``, ``search_standard_dirs`` (#674, #753, #789, #847). + - The config module and all its functions, all of which have been made private (#674, #753, #789, #847, #877). - ``Project`` subclasses can no longer define a ``Job`` subclass to use (#588, #693). - The ``Collection`` class (#664, #667, #683). - The ``project`` CLI subcommand (#752). From 6bbfd8675bbe7eff20e20380d21064e069806ec7 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Sun, 18 Dec 2022 10:58:27 -0800 Subject: [PATCH 8/8] Revert "Remove redundant leading underscores now that the modules are public." This reverts commit f94a2a7f1e77b73f17f3df708b4efad81f2c2c83. --- signac/__main__.py | 24 ++++++++++++------------ signac/_config.py | 28 ++++++++++++++-------------- signac/migration/v1_to_v2.py | 4 ++-- signac/project.py | 28 ++++++++++++++-------------- tests/test_job.py | 4 ++-- tests/test_project.py | 14 +++++++------- tests/test_shell.py | 14 +++++++------- 7 files changed, 58 insertions(+), 58 deletions(-) diff --git a/signac/__main__.py b/signac/__main__.py index dfec93468..7211be8e0 100644 --- a/signac/__main__.py +++ b/signac/__main__.py @@ -33,10 +33,10 @@ from ._config import ( PROJECT_CONFIG_FN, USER_CONFIG_FN, - Config, - load_config, - locate_config_dir, - read_config_file, + _Config, + _load_config, + _locate_config_dir, + _read_config_file, ) from ._utility import _add_verbosity_argument, _print_err, _query_yes_no, _safe_relpath from ._vendor.configobj import Section, flatten_errors @@ -672,11 +672,11 @@ def main_config_show(args): raise ValueError("You can specify either -l/--local or -g/--global, not both.") elif args.local: if os.path.isfile(PROJECT_CONFIG_FN): - cfg = read_config_file(PROJECT_CONFIG_FN) + cfg = _read_config_file(PROJECT_CONFIG_FN) elif args.globalcfg: - cfg = read_config_file(USER_CONFIG_FN) + cfg = _read_config_file(USER_CONFIG_FN) else: - cfg = load_config(locate_config_dir(os.getcwd())) + cfg = _load_config(_locate_config_dir(os.getcwd())) if not cfg: if args.local: mode = "local" @@ -694,7 +694,7 @@ def main_config_show(args): if not isinstance(cfg, Section): print(cfg) else: - for line in Config(cfg).write(): + for line in _Config(cfg).write(): print(line) @@ -726,11 +726,11 @@ def main_config_verify(args): raise ValueError("You can specify either -l/--local or -g/--global, not both.") elif args.local: if os.path.isfile(PROJECT_CONFIG_FN): - cfg = read_config_file(PROJECT_CONFIG_FN) + cfg = _read_config_file(PROJECT_CONFIG_FN) elif args.globalcfg: - cfg = read_config_file(USER_CONFIG_FN) + cfg = _read_config_file(USER_CONFIG_FN) else: - cfg = load_config(locate_config_dir(os.getcwd())) + cfg = _load_config(_locate_config_dir(os.getcwd())) if not cfg: if args.local: mode = "local" @@ -763,7 +763,7 @@ def main_config_set(args): "You need to specify either -l/--local or -g/--global " "to specify which configuration to modify." ) - cfg = read_config_file(fn_config) + cfg = _read_config_file(fn_config) keys = args.key.split(".") if len(args.value) == 0: raise ValueError("No value argument provided!") diff --git a/signac/_config.py b/signac/_config.py index a3ca12a3e..ead6e492f 100644 --- a/signac/_config.py +++ b/signac/_config.py @@ -19,11 +19,11 @@ """ -def get_project_config_fn(path): +def _get_project_config_fn(path): return os.path.abspath(os.path.join(path, PROJECT_CONFIG_FN)) -def raise_if_older_schema(root): +def _raise_if_older_schema(root): """Raise if an older schema version is detected at the search path. Parameters @@ -59,7 +59,7 @@ def raise_if_older_schema(root): pass -def locate_config_dir(search_path): +def _locate_config_dir(search_path): """Locates directory containing a signac configuration file in a directory hierarchy. Parameters @@ -75,7 +75,7 @@ def locate_config_dir(search_path): orig_search_path = search_path search_path = os.path.abspath(search_path) while True: - if os.path.isfile(get_project_config_fn(search_path)): + if os.path.isfile(_get_project_config_fn(search_path)): return search_path if (up := os.path.dirname(search_path)) == search_path: break @@ -89,7 +89,7 @@ def locate_config_dir(search_path): search_path = os.path.abspath(orig_search_path) while True: - raise_if_older_schema(search_path) + _raise_if_older_schema(search_path) if (up := os.path.dirname(search_path)) == search_path: logger.debug("Reached filesystem root, no config found.") return None @@ -97,7 +97,7 @@ def locate_config_dir(search_path): search_path = up -class Config(ConfigObj): +class _Config(ConfigObj): """Manages configuration for a signac project.""" def verify(self, *, preserve_errors=False): @@ -105,10 +105,10 @@ def verify(self, *, preserve_errors=False): return super().validate(Validator(), preserve_errors=preserve_errors) -def read_config_file(filename): +def _read_config_file(filename): logger.debug(f"Reading config file '{filename}'.") try: - config = Config(filename, configspec=_CFG.split("\n")) + config = _Config(filename, configspec=_CFG.split("\n")) except (OSError, ConfigObjError) as error: raise ConfigError(f"Failed to read configuration file '{filename}':\n{error}") verification = config.verify() @@ -123,7 +123,7 @@ def read_config_file(filename): return config -def load_config(path=None): +def _load_config(path=None): """Load configuration from a project directory. Parameters @@ -133,21 +133,21 @@ def load_config(path=None): Returns -------- - :class:`Config` + :class:`_Config` The composite configuration including both project-local and global config data if requested. Note that because this config is a composite, modifications to the returned value will not be reflected in the files. """ if path is None: path = os.getcwd() - config = Config(configspec=_CFG.split("\n")) + config = _Config(configspec=_CFG.split("\n")) # Add in any global or user config files. For now this only finds user-specific # files, but it could be updated in the future to support e.g. system-wide config files. for fn in (USER_CONFIG_FN,): if os.path.isfile(fn): - config.merge(read_config_file(fn)) + config.merge(_read_config_file(fn)) - if os.path.isfile(get_project_config_fn(path)): - config.merge(read_config_file(get_project_config_fn(path))) + if os.path.isfile(_get_project_config_fn(path)): + config.merge(_read_config_file(_get_project_config_fn(path))) return config diff --git a/signac/migration/v1_to_v2.py b/signac/migration/v1_to_v2.py index a56f4a83d..224c1d587 100644 --- a/signac/migration/v1_to_v2.py +++ b/signac/migration/v1_to_v2.py @@ -15,7 +15,7 @@ import os -from .._config import get_project_config_fn +from .._config import _get_project_config_fn from .._synced_collections.backends.collection_json import BufferedJSONAttrDict from .._vendor import configobj from ..project import Project @@ -74,7 +74,7 @@ def _migrate_v1_to_v2(root_directory): # Move signac.rc to .signac/config v1_fn = os.path.join(root_directory, "signac.rc") - v2_fn = get_project_config_fn(root_directory) + v2_fn = _get_project_config_fn(root_directory) os.mkdir(os.path.dirname(v2_fn)) os.replace(v1_fn, v2_fn) diff --git a/signac/project.py b/signac/project.py index dfadee08d..54c76bf9e 100644 --- a/signac/project.py +++ b/signac/project.py @@ -21,12 +21,12 @@ from threading import RLock from ._config import ( - Config, - get_project_config_fn, - load_config, - locate_config_dir, - raise_if_older_schema, - read_config_file, + _Config, + _get_project_config_fn, + _load_config, + _locate_config_dir, + _raise_if_older_schema, + _read_config_file, ) from ._search_indexer import _SearchIndexer from ._synced_collections.backends.collection_json import BufferedJSONAttrDict @@ -50,7 +50,7 @@ JOB_ID_REGEX = re.compile(f"[a-f0-9]{{{JOB_ID_LENGTH}}}") -class _ProjectConfig(Config): +class _ProjectConfig(_Config): r"""Extends the project config to make it immutable. Parameters @@ -104,15 +104,15 @@ class Project: def __init__(self, path=None): if path is None: path = os.getcwd() - if not os.path.isfile(get_project_config_fn(path)): - raise_if_older_schema(path) + if not os.path.isfile(_get_project_config_fn(path)): + _raise_if_older_schema(path) raise LookupError( f"Unable to find project at path '{os.path.abspath(path)}'." ) # Project constructor does not search upward, so the provided path must # be a project directory. - config = load_config(path) + config = _load_config(path) self._config = _ProjectConfig(config) self._lock = RLock() @@ -1454,9 +1454,9 @@ def init_project(cls, path=None): try: project = cls.get_project(path=path, search=False) except LookupError: - fn_config = get_project_config_fn(path) + fn_config = _get_project_config_fn(path) _mkdir_p(os.path.dirname(fn_config)) - config = read_config_file(fn_config) + config = _read_config_file(fn_config) config["schema_version"] = SCHEMA_VERSION config.write() project = cls.get_project(path=path) @@ -1499,10 +1499,10 @@ def get_project(cls, path=None, search=True, **kwargs): ) old_path = path - if not search and not os.path.isfile(get_project_config_fn(path)): + if not search and not os.path.isfile(_get_project_config_fn(path)): path = None else: - path = locate_config_dir(path) + path = _locate_config_dir(path) if not path: raise LookupError( diff --git a/tests/test_job.py b/tests/test_job.py index 3568b440b..85df7de8c 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -13,7 +13,7 @@ import pytest import signac -from signac._config import load_config +from signac._config import _load_config from signac.errors import ( DestinationExistsError, InvalidKeyError, @@ -65,7 +65,7 @@ def setUp(self, request): request.addfinalizer(self._tmp_dir.cleanup) self._tmp_pr = os.path.join(self._tmp_dir.name, "pr") os.mkdir(self._tmp_pr) - self.config = load_config() + self.config = _load_config() self.project = self.project_class.init_project(path=self._tmp_pr) def tearDown(self): diff --git a/tests/test_project.py b/tests/test_project.py index fb0005aeb..42b860b37 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -24,9 +24,9 @@ import signac from signac._config import ( PROJECT_CONFIG_FN, - get_project_config_fn, - load_config, - read_config_file, + _get_project_config_fn, + _load_config, + _read_config_file, ) from signac.errors import ( DestinationExistsError, @@ -2291,7 +2291,7 @@ def test_project_schema_versions(self): assert version.parse(self.project.config["schema_version"]) < version.parse( impossibly_high_schema_version ) - config = read_config_file(get_project_config_fn(self.project.path)) + config = _read_config_file(_get_project_config_fn(self.project.path)) config["schema_version"] = impossibly_high_schema_version config.write() with pytest.raises(IncompatibleSchemaVersion): @@ -2366,7 +2366,7 @@ def test_project_schema_version_migration( # If no schema version is present in the config it is equivalent to # version 0, so we test both explicit and implicit versions. - config = read_config_file(cfg_fn) + config = _read_config_file(cfg_fn) if implicit_version: del config["schema_version"] assert "schema_version" not in config @@ -2383,7 +2383,7 @@ def test_project_schema_version_migration( err = io.StringIO() with redirect_stderr(err): apply_migrations(dirname) - config = load_config(dirname) + config = _load_config(dirname) assert config["schema_version"] == "2" project = signac.get_project(path=dirname) assert project.config["schema_version"] == "2" @@ -2441,7 +2441,7 @@ def setUp_base_h5Store(self, request): request.addfinalizer(self._tmp_dir.cleanup) self._tmp_pr = os.path.join(self._tmp_dir.name, "pr") os.mkdir(self._tmp_pr) - self.config = load_config() + self.config = _load_config() self.project = self.project_class.init_project(path=self._tmp_pr) self._fn_store = os.path.join(self._tmp_dir.name, "signac_data.h5") diff --git a/tests/test_shell.py b/tests/test_shell.py index d766ee78a..073223e71 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -12,7 +12,7 @@ from test_project import _initialize_v1_project import signac -from signac._config import USER_CONFIG_FN, Config, load_config, read_config_file +from signac._config import USER_CONFIG_FN, _Config, _load_config, _read_config_file # Skip linked view tests on Windows WINDOWS = sys.platform == "win32" @@ -743,18 +743,18 @@ def test_config_show(self): self.call("python -m signac init".split()) out = self.call("python -m signac config --local show".split()).strip() - cfg = read_config_file(".signac/config") - expected = Config(cfg).write() + cfg = _read_config_file(".signac/config") + expected = _Config(cfg).write() assert out.split(os.linesep) == expected out = self.call("python -m signac config show".split()).strip() - cfg = load_config() - expected = Config(cfg).write() + cfg = _load_config() + expected = _Config(cfg).write() assert out.split(os.linesep) == expected out = self.call("python -m signac config --global show".split()).strip() - cfg = read_config_file(USER_CONFIG_FN) - expected = Config(cfg).write() + cfg = _read_config_file(USER_CONFIG_FN) + expected = _Config(cfg).write() assert out.split(os.linesep) == expected def test_config_set(self):