Skip to content

Commit

Permalink
Check up on restrictions to signac view (#926)
Browse files Browse the repository at this point in the history
* Remove unnecessary restriction on view, test possibly bad characters

* test: Simplify view test logic

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor(linked views): simplify logic.

* docs(changelog): Add #926 to changelog

* fix(linked views): Fix previous commmit.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* test: Fix syntax errors in test_create_linked_view_with_slash_raises_error

---------

Co-authored-by: Brandon Butler <butlerbr@umich.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 19, 2023
1 parent d6b5aa6 commit 6b8e1a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
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

0 comments on commit 6b8e1a3

Please sign in to comment.