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

[FIX]: Attempt creation of symlink on Windows and handle exceptions. #958

Merged
merged 9 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changed
+++++++

- linked views now can contain spaces and other characters except directory separators (#926).
- linked views now can be created on Windows, if 'Developer mode' is enabled (#430).

[2.1.0] -- 2023-07-12
---------------------
Expand Down
4 changes: 4 additions & 0 deletions contributors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,8 @@ contributors:
family-names: Kadar
given-names: Alain
affiliation: "University of Michigan"
-
family-names: Stoimenov
given-names: Boyko
affiliation: "JTEKT Corp."
...
37 changes: 26 additions & 11 deletions signac/linked_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,15 @@ def create_linked_view(project, prefix=None, job_ids=None, path=None):
Raises
------
OSError
Linked views cannot be created on Windows because
symbolic links are not supported by the platform.
If symbolic links are not enabled on Windows,
linked views cannot be created.

RuntimeError
When state points contain ``os.sep``.

"""
from .import_export import _check_directory_structure_validity, _make_path_function

# Windows does not support the creation of symbolic links.
if sys.platform == "win32":
raise OSError(
"signac cannot create linked views on Windows, because "
"symbolic links are not supported by the platform."
)

if prefix is None:
prefix = "view"

Expand Down Expand Up @@ -85,8 +79,29 @@ def create_linked_view(project, prefix=None, job_ids=None, path=None):
for job in project.find_jobs():
links["./job"] = job.path
assert len(links) < 2
_check_directory_structure_validity(links.keys())
_update_view(prefix, links)

# Updating the view will fail on Windows, if symlinks are not enabled.
# Before re-raising the exception, print a helpful message for the expected error.
try:
_check_directory_structure_validity(links.keys())
_update_view(prefix, links)
except OSError as err:
if (sys.platform == "win32") & (err.winerror == 1314):
bdice marked this conversation as resolved.
Show resolved Hide resolved
print("-----------------------------------------------------------------")
print(err.strerror)
print(" ")
print("You likely don't have permission to create Windows symlinks.")
print("To enable the creation of symlinks on Windows you need")
print("to enable 'Developer mode' (requires administrative rights).")
print(" ")
print("To enable 'Developer mode':")
print(" 1. Go to 'Settings'.")
print(" 2. In the search bar type 'Use developer features'")
print(" 3. Enable the item 'Developer mode'.")
print("The details for Home edition and between Windows versions may vary.")
print("-----------------------------------------------------------------")
print(" ")
bdice marked this conversation as resolved.
Show resolved Hide resolved
raise err.with_traceback(sys.exc_info()[2])

return links

Expand Down