-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Skip module
in the symlinks
#511
Changes from all commits
496a305
2661e03
6c0802e
2ea12ac
f469cb7
c671723
f7bf019
896673b
94cf358
df82913
069010b
daf78d7
5496b00
7265c95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
|
||
from datetime import datetime | ||
import os | ||
from pathlib import Path | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
@@ -114,6 +113,7 @@ def _uninstall(self, module_dir, name, force=False): | |
msg = "%s, and all content below it? " % name | ||
if not utils.confirm_uninstall(msg, force): | ||
return | ||
self._cleanup_symlink(module_dir) | ||
self._cleanup(module_dir) | ||
logger.info("%s and all subdirectories have been removed." % name) | ||
else: | ||
|
@@ -183,7 +183,15 @@ def get_symlink_path(self, module_dir): | |
""" | ||
if not self.settings.symlink_base: | ||
return | ||
return os.path.join(self.settings.symlink_base, *module_dir.split(os.sep)[-2:]) | ||
|
||
symlink_base_name = os.path.join(self.settings.symlink_base, *module_dir.split(os.sep)[-2:]) | ||
|
||
# With Lmod and default_version==True, the symlinks points to module.lua itself, | ||
# and its name needs to end with `.lua` too | ||
if self.module_extension == "lua" and self.settings.default_version == True: | ||
return symlink_base_name + ".lua" | ||
else: | ||
return symlink_base_name | ||
|
||
def create_symlink(self, module_dir): | ||
""" | ||
|
@@ -192,33 +200,39 @@ def create_symlink(self, module_dir): | |
symlink_path = self.get_symlink_path(module_dir) | ||
if os.path.exists(symlink_path): | ||
os.unlink(symlink_path) | ||
logger.info("Creating link %s -> %s" % (module_dir, symlink_path)) | ||
symlink_dir = os.path.dirname(symlink_path) | ||
|
||
# If the parent directory doesn't exist, make it | ||
if not os.path.exists(symlink_dir): | ||
utils.mkdirp([symlink_dir]) | ||
|
||
# With Lmod, default_version==False can't be made to work with symlinks at the module.lua level | ||
if self.module_extension == "lua" and self.settings.default_version == False: | ||
symlink_target = module_dir | ||
else: | ||
symlink_target = os.path.join(module_dir, self.modulefile) | ||
logger.info("Creating link %s -> %s" % (symlink_target, symlink_path)) | ||
|
||
# Create the symbolic link! | ||
os.symlink(module_dir, symlink_path) | ||
os.symlink(symlink_target, symlink_path) | ||
|
||
# If we don't have a version file in root, create it | ||
if self.module_extension != "tcl" and self.settings.default_version == True: | ||
version_file = os.path.join(os.path.dirname(symlink_path), ".version") | ||
if not os.path.exists(version_file): | ||
Path(version_file).touch() | ||
# Create .version | ||
self.write_version_file(os.path.dirname(symlink_path)) | ||
|
||
def check_symlink(self, module_dir): | ||
def check_symlink(self, module_dir, force=False): | ||
""" | ||
Given an install command, if --symlink-tree is provided make | ||
sure we don't already have this symlink in the tree. | ||
""" | ||
# Get the symlink path - does it exist? | ||
symlink_path = self.get_symlink_path(module_dir) | ||
if os.path.exists(symlink_path) and not utils.confirm_action( | ||
"%s already exists, are you sure you want to overwrite?" % symlink_path | ||
): | ||
sys.exit(0) | ||
if os.path.exists(symlink_path): | ||
if force: | ||
logger.info("Overwriting %s, as requested" % module_dir) | ||
elif not utils.confirm_action( | ||
"%s already exists, are you sure you want to overwrite" % symlink_path | ||
): | ||
sys.exit(0) | ||
|
||
def _cleanup_symlink(self, module_dir): | ||
""" | ||
|
@@ -343,7 +357,24 @@ def check(self, module_name): | |
config = self._load_container(module_name.rsplit(":", 1)[0]) | ||
return self.container.check(module_name, config) | ||
|
||
def install(self, name, tag=None, symlink=False, **kwargs): | ||
def write_version_file(self, version_dir): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this section old from before? I guess we need to merge the version changes before this one! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because I had done a merge of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes - let's update this PR with the changes in current main and then I can give another review! |
||
""" | ||
Create the .version file, if there is a template for it. | ||
|
||
Note that we don't actually change the content of the template: | ||
it is copied as is. | ||
""" | ||
version_template = 'default_version.' + self.module_extension | ||
if not self.settings.default_version: | ||
version_template = 'no_' + version_template | ||
template_file = os.path.join(here, "templates", version_template) | ||
if os.path.exists(template_file): | ||
version_file = os.path.join(version_dir, ".version") | ||
if not os.path.exists(version_file): | ||
version_content = shpc.utils.read_file(template_file) | ||
shpc.utils.write_file(version_file, version_content) | ||
|
||
def install(self, name, tag=None, symlink=None, force=False, **kwargs): | ||
""" | ||
Given a unique resource identifier, install a recipe. | ||
|
||
|
@@ -372,20 +403,18 @@ def install(self, name, tag=None, symlink=False, **kwargs): | |
subfolder = os.path.join(uri, tag.name) | ||
container_dir = self.container.container_dir(subfolder) | ||
|
||
# Global override to arg | ||
symlink = self.settings.symlink_tree is True or symlink | ||
# Default to global setting | ||
if symlink is None: | ||
symlink = self.settings.symlink_tree | ||
|
||
if symlink: | ||
# Cut out early if symlink desired and already exists | ||
self.check_symlink(module_dir) | ||
self.check_symlink(module_dir, force) | ||
shpc.utils.mkdirp([module_dir, container_dir]) | ||
|
||
# Add a .version file to indicate the level of versioning (not for tcl) | ||
if self.module_extension != "tcl" and self.settings.default_version == True: | ||
version_dir = os.path.join(self.settings.module_base, uri) | ||
version_file = os.path.join(version_dir, ".version") | ||
if not os.path.exists(version_file): | ||
Path(version_file).touch() | ||
version_dir = os.path.join(self.settings.module_base, uri) | ||
self.write_version_file(version_dir) | ||
|
||
# For Singularity this is a path, podman is a uri. If None is returned | ||
# there was an error and we cleanup | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#%Module | ||
set ModulesVersion "please_specify_a_version_number" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this is neat I’ve never seen it before! So if —symlink-tree is set, the None is True and this overrides the default False of no symlink tree (should that be None too)? And then if no symlink tree is True the None is ignored? What happens if both flags are provided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should use store_const here to make the three cases more clear? https://stackoverflow.com/a/34750557
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works as it is: None if no option given, and True / False for
--symlink-tree
/--no-symlink-tree
If both are given, the last one wins
A matter of choice :) I find
store_true
andstore_false
very explicit :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I’m cool with that :)
will probably finish review tomorrow - I want to look everything over once more with a clear head, and I’m rather tired and still a bit on edge from the day. So stay tuned for tomorrow! I think the default version PR looks great (and can update the PR here) so probably I’ll merge that one first.
goodnight from the inferno! lol