Skip to content

Commit

Permalink
Update v2 migration logic. (#856)
Browse files Browse the repository at this point in the history
* Standardize upgrade command message.

* Fix issue with input prompt disappearing.

* Use _mkdir_p, os.path.join.

* Don't use _mkdir_p. Raise if .signac already exists.

* Update signac/common/config.py

Co-authored-by: Vyas Ramasubramani <vyas.ramasubramani@gmail.com>
  • Loading branch information
bdice and vyasr committed Nov 7, 2022
1 parent 9a49385 commit c6c0b48
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
20 changes: 10 additions & 10 deletions signac/contrib/migration/v1_to_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def _migrate_v1_to_v2(root_directory):
"""Migrate from schema version 1 to version 2."""
# Load the v1 config.
cfg = _load_config_v1(root_directory)
fn_doc = os.path.join(root_directory, Project.FN_DOCUMENT)
doc = BufferedJSONAttrDict(filename=fn_doc, write_concern=True)

# Try to migrate a custom workspace directory if one exists.
current_workspace_name = cfg.get("workspace_dir")
Expand All @@ -66,8 +64,12 @@ def _migrate_v1_to_v2(root_directory):
os.replace(current_workspace, new_workspace)
del cfg["workspace_dir"]

# Delete project name from config and store in project doc.
doc["signac_project_name"] = cfg["project"]
# Delete project name from config and store in project doc if non-default.
# For default names, no modifications to the project document should be made.
if cfg["project"] != "None":
fn_doc = os.path.join(root_directory, Project.FN_DOCUMENT)
doc = BufferedJSONAttrDict(filename=fn_doc, write_concern=True)
doc["signac_project_name"] = cfg["project"]
del cfg["project"]
cfg.write()

Expand All @@ -79,12 +81,10 @@ def _migrate_v1_to_v2(root_directory):

# 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")
),
".signac_shell_history": os.path.join(".signac", "shell_history"),
".signac_sp_cache.json.gz": os.path.join(".signac", "statepoint_cache.json.gz"),
}
for src, dst in files_to_move.items():
src = os.sep.join((root_directory, src))
src = os.path.join(root_directory, src)
if os.path.isfile(src):
os.replace(src, os.sep.join((root_directory, dst)))
os.replace(src, os.path.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 @@ -232,7 +232,7 @@ def _check_schema_compatibility(self):
elif config_schema_version < schema_version:
raise IncompatibleSchemaVersion(
"The signac schema version used by this project is '{}', but signac {} "
"requires schema version '{}'. Please use '$ signac migrate' to "
"requires schema version '{}'. Please use 'python -m signac migrate' to "
"irreversibly migrate this project's schema to the supported "
"version.".format(config_schema_version, __version__, schema_version)
)
Expand Down
5 changes: 2 additions & 3 deletions signac/contrib/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ def _query_yes_no(question, default="yes"): # pragma: no cover
raise ValueError("invalid default answer: '%s'" % default)

while True:
sys.stdout.write(question + prompt)
choice = input().lower()
choice = input(question + prompt).lower()
if default is not None and choice == "":
return valid[default]
elif choice in valid:
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n').\n")
print("Please respond with 'yes' or 'no' (or 'y' or 'n').")


def _add_verbosity_argument(parser, default=0):
Expand Down

0 comments on commit c6c0b48

Please sign in to comment.