Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes the config module internal #877

Merged
merged 8 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
36 changes: 22 additions & 14 deletions signac/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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)


Expand Down Expand Up @@ -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"
Expand All @@ -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!")
Expand Down
File renamed without changes.
9 changes: 4 additions & 5 deletions signac/migration/v1_to_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions signac/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
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,
_locate_config_dir,
_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,
Expand Down
5 changes: 3 additions & 2 deletions tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

import pytest

import signac.config
import signac
from signac._config import _load_config
from signac.errors import (
DestinationExistsError,
InvalidKeyError,
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions tests/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand All @@ -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())
Expand All @@ -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
Expand Down