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

Move internal signac files into .signac subdirectory #708

Merged
merged 3 commits into from
Mar 6, 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
4 changes: 3 additions & 1 deletion signac/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
)


SHELL_HISTORY_FN = os.sep.join((".signac", "shell_history"))

warnings.simplefilter("default")


Expand Down Expand Up @@ -864,7 +866,7 @@ def jobs():
else: # interactive
if READLINE:
if "PyPy" not in platform.python_implementation():
fn_hist = project.fn(".signac_shell_history")
fn_hist = project.fn(SHELL_HISTORY_FN)
try:
readline.read_history_file(fn_hist)
readline.set_history_length(1000)
Expand Down
14 changes: 13 additions & 1 deletion signac/contrib/migration/v1_to_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ def _migrate_v1_to_v2(root_directory):
v1_fn = os.path.join(root_directory, "signac.rc")
v2_fn = _get_project_config_fn(root_directory)
os.mkdir(os.path.dirname(v2_fn))
os.rename(v1_fn, v2_fn)
os.replace(v1_fn, v2_fn)

# Now move all other files.
files_to_move = {
".signac_shell_history": os.sep.join((".signac", "shell_history")),
".signac_sp_cache.json.gz": os.sep.join(
(".signac", "statepoint_cache.json.gz")
),
}
for src, dst in files_to_move.items():
os.replace(
os.sep.join((root_directory, src)), os.sep.join((root_directory, dst))
)
2 changes: 1 addition & 1 deletion signac/contrib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Project:
KEY_DATA = "signac_data"
"The project's datastore key."

FN_CACHE = ".signac_sp_cache.json.gz"
FN_CACHE = os.sep.join((".signac", "statepoint_cache.json.gz"))
"The default filename for the state point cache file."

_use_pandas_for_html_repr = True # toggle use of pandas for html repr
Expand Down
21 changes: 21 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2017 The Regents of the University of Michigan
# All rights reserved.
# This software is licensed under the BSD 3-Clause License.
import gzip
import io
import itertools
import json
Expand Down Expand Up @@ -35,6 +36,7 @@
StatepointParsingError,
WorkspaceError,
)
from signac.contrib.hashing import calc_id
from signac.contrib.linked_view import _find_all_links
from signac.contrib.project import JobsCursor, Project # noqa: F401
from signac.contrib.schema import ProjectSchema
Expand Down Expand Up @@ -2480,6 +2482,7 @@ def test_project_schema_version_migration(self, implicit_version):
from signac.contrib.migration import apply_migrations

with TemporaryDirectory() as dirname:
# Create v1 config file.
cfg_fn = os.path.join(dirname, "signac.rc")
with open(cfg_fn, "w") as f:
f.write(
Expand All @@ -2491,13 +2494,29 @@ def test_project_schema_version_migration(self, implicit_version):
)
)

# Create a shell history file.
history_fn = os.path.join(dirname, ".signac_shell_history")
with open(history_fn, "w") as f:
f.write("print(project)")

# Create a statepoint cache. Note that this cache does not
# correspond to actual statepoints since we don't currently have
# any in this project, but that's fine for migration testing.
history_fn = os.path.join(dirname, ".signac_sp_cache.json.gz")
sp = {"a": 1}
with gzip.open(history_fn, "wb") as f:
f.write(json.dumps({calc_id(sp): sp}).encode())

# 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)
if implicit_version:
del config["schema_version"]
assert "schema_version" not in config
else:
assert config["schema_version"] == "0"
config.write()

err = io.StringIO()
with redirect_stderr(err):
apply_migrations(dirname)
Expand All @@ -2509,6 +2528,8 @@ def test_project_schema_version_migration(self, implicit_version):
assert "0 to 1" in err.getvalue()
assert "1 to 2" in err.getvalue()
assert os.path.isfile(project.fn(PROJECT_CONFIG_FN))
assert os.path.isfile(project.fn(os.sep.join((".signac", "shell_history"))))
assert os.path.isfile(project.fn(Project.FN_CACHE))


class TestProjectPickling(TestProjectBase):
Expand Down