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

Check up on restrictions to signac view #926

Merged
merged 9 commits into from
Jul 19, 2023
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ The **signac** package follows `semantic versioning <https://semver.org/>`_.
Version 2
=========

[2.2.0] -- 2023-xx-xx
---------------------

Changed
+++++++

- linked views now can contain spaces and other characters except directory separators (#926).

[2.1.0] -- 2023-07-12
---------------------

Expand Down
14 changes: 4 additions & 10 deletions signac/linked_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_linked_view(project, prefix=None, job_ids=None, path=None):
Linked views cannot be created on Windows because
symbolic links are not supported by the platform.
RuntimeError
When state points contain one of ``[os.sep, " ", "*"]``.
When state points contain ``os.sep``.

"""
from .import_export import _check_directory_structure_validity, _make_path_function
Expand All @@ -64,19 +64,13 @@ def create_linked_view(project, prefix=None, job_ids=None, path=None):
key_list = [k for job in jobs for k in job.statepoint().keys()]
value_list = [v for job in jobs for v in job.statepoint().values()]
item_list = key_list + value_list
bad_chars = [os.sep, " ", "*"]
bad_items = [
item
for item in item_list
for char in bad_chars
if isinstance(item, str) and char in item
]
bad_items = [item for item in item_list if isinstance(item, str) and os.sep in item]

if any(bad_items):
err_msg = " ".join(
[
f"In order to use view, state points should not contain {bad_chars}:",
*bad_items,
f"In order to use view, state points should not contain {os.sep}:",
str(set(bad_items)),
]
)
raise RuntimeError(err_msg)
Expand Down
17 changes: 13 additions & 4 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2038,13 +2038,22 @@ def test_create_linked_view_heterogeneous_schema_problematic(self):

@pytest.mark.skipif(WINDOWS, reason="Linked views unsupported on Windows.")
def test_create_linked_view_with_slash_raises_error(self):
bad_chars = [os.sep, " ", "*"]
statepoints = [{f"a{i}b": 0, "b": f"bad{i}val"} for i in bad_chars]
statepoint = {"b": f"bad{os.sep}val"}
view_prefix = os.path.join(self._tmp_pr, "view")
self.project.open_job(statepoint).init()
with pytest.raises(RuntimeError):
self.project.create_linked_view(prefix=view_prefix)

@pytest.mark.skipif(WINDOWS, reason="Linked views unsupported on Windows.")
def test_create_linked_view_weird_chars_in_file_name(self):
shell_escaped_chars = [" ", "*", "~"]
statepoints = [
{f"a{i}b": 0, "b": f"escaped{i}val"} for i in shell_escaped_chars
]
view_prefix = os.path.join(self._tmp_pr, "view")
for sp in statepoints:
self.project.open_job(sp).init()
with pytest.raises(RuntimeError):
self.project.create_linked_view(prefix=view_prefix)
self.project.create_linked_view(prefix=view_prefix)

@pytest.mark.skipif(WINDOWS, reason="Linked views unsupported on Windows.")
def test_create_linked_view_duplicate_paths(self):
Expand Down