diff --git a/signac/__main__.py b/signac/__main__.py index 57e5639bc..d144291ef 100644 --- a/signac/__main__.py +++ b/signac/__main__.py @@ -93,6 +93,8 @@ ) +SHELL_HISTORY_FN = os.sep.join((".signac", "shell_history")) + warnings.simplefilter("default") @@ -861,7 +863,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) diff --git a/signac/contrib/migration/v1_to_v2.py b/signac/contrib/migration/v1_to_v2.py index 733682741..31eb02831 100644 --- a/signac/contrib/migration/v1_to_v2.py +++ b/signac/contrib/migration/v1_to_v2.py @@ -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)) + ) diff --git a/signac/contrib/project.py b/signac/contrib/project.py index 73d70d694..e1d741895 100644 --- a/signac/contrib/project.py +++ b/signac/contrib/project.py @@ -112,7 +112,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 diff --git a/tests/test_project.py b/tests/test_project.py index 4156a8f04..f6373e989 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -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 @@ -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 @@ -2473,6 +2475,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( @@ -2484,6 +2487,21 @@ 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"] @@ -2491,6 +2509,7 @@ def test_project_schema_version_migration(self, implicit_version): else: assert config["schema_version"] == "0" config.write() + err = io.StringIO() with redirect_stderr(err): apply_migrations(dirname) @@ -2502,6 +2521,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):