Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit db11e7e2 authored by gsell's avatar gsell
Browse files

Merge branch '148-modmanage-code-cleanup-and-polishing' into 'master'

Resolve "modmanage: code cleanup and polishing"

Closes #148

See merge request !119
parents a8273143 56b4a05b
No related branches found
No related tags found
1 merge request!119Resolve "modmanage: code cleanup and polishing"
...@@ -171,40 +171,6 @@ sync_module() { ...@@ -171,40 +171,6 @@ sync_module() {
} }
##############################################################################
#
# Sync the Pmodules configuration and templates
#
# Arguments:
# $1: source prefix of Pmodule environment
# $2: target prefix of Pmodule environment
#
sync_config() {
src="$1/${PMODULES_CONFIG_DIR}/"
dst="$2/${PMODULES_CONFIG_DIR}/"
${rsync} --links --perms \
"${src}"/profile.{bash,csh,zsh} "${dst}" || return $?
${rsync} --links --perms \
"${src}"/profile.{bash,csh,zsh}-"${PMODULES_VERSION}" "${dst}" || return $?
${rsync} --links --perms \
"${src}/Pmodules.conf" "${dst}" || return $?
${rsync} --links --perms \
"${src}/modbuild.conf" "${dst}" || return $?
echo
}
##############################################################################
#
# Delete a module
#
# Arguments:
# $1: relative modulefile path
# $2: target prefix of Pmodule environment
#
delete_module() {
echo "Not implemented yet!"
}
############################################################################## ##############################################################################
# #
# initialize a new module environment # initialize a new module environment
...@@ -212,7 +178,7 @@ delete_module() { ...@@ -212,7 +178,7 @@ delete_module() {
# #
# #
Subcommands[init]='init' Subcommands[init]='init'
Options[init]='-o h -l src: -l user: -l help -l version:' Options[init]='-o \?hfy -l src: -l user: -l help -l force -l yes'
Help[init]=" Help[init]="
USAGE: USAGE:
modmanage init [switches] TARGET_DIR modmanage init [switches] TARGET_DIR
...@@ -224,7 +190,7 @@ SWITCHES: ...@@ -224,7 +190,7 @@ SWITCHES:
--user <USER> --user <USER>
If this scripts runs with root privileges, a user name If this scripts runs with root privileges, a user name
ore ID must be specified. ore ID must be specified.
--force --force|--yes|-f|-y
re-initialise an already existing Pmodule environment. re-initialise an already existing Pmodule environment.
" "
...@@ -238,7 +204,32 @@ subcommand_init() { ...@@ -238,7 +204,32 @@ subcommand_init() {
Error: the module environment you are going to use as source has not been Error: the module environment you are going to use as source has not been
initialized properly!" initialized properly!"
} }
#.....................................................................
#
# Sync the Pmodules configuration and templates
#
# Arguments:
# $1: source prefix of Pmodule environment
# $2: target prefix of Pmodule environment
#
sync_config() {
src="$1/${PMODULES_CONFIG_DIR}/"
dst="$2/${PMODULES_CONFIG_DIR}/"
${rsync} --links --perms \
"${src}"/profile.{bash,csh,zsh} "${dst}" \
|| return $?
${rsync} --links --perms \
"${src}"/profile.{bash,csh,zsh}-"${PMODULES_VERSION}" "${dst}" \
|| return $?
${rsync} --links --perms \
"${src}/Pmodules.conf" "${dst}" \
|| return $?
${rsync} --links --perms \
"${src}/modbuild.conf" "${dst}" \
|| return $?
}
local target_root=() local target_root=()
local user='' local user=''
while (($# > 0)); do while (($# > 0)); do
...@@ -246,7 +237,7 @@ initialized properly!" ...@@ -246,7 +237,7 @@ initialized properly!"
-h | -H | -\? | --help | -help ) -h | -H | -\? | --help | -help )
print_help "${subcommand}" print_help "${subcommand}"
;; ;;
--force | -f ) --force | --yes | -f | -y )
force='yes' force='yes'
;; ;;
--user | --user=* ) --user | --user=* )
...@@ -290,22 +281,20 @@ initialized properly!" ...@@ -290,22 +281,20 @@ initialized properly!"
check_env || \ check_env || \
std::die 1 "Giving up..." std::die 1 "Giving up..."
echo " echo "Creating a minimal Pmodule environment from the environment at"
Attempting to create a minimal module environment from the echo " ${PMODULES_ROOT}"
environment at '${PMODULES_ROOT}' echo "in"
" echo " ${target_root}"
echo "Initializing target directory '${target_root}' ..."
echo
if [[ -d "${target_root}" ]] && [[ ${force} == no ]]; then if [[ -d "${target_root}" ]] && [[ ${force} == no ]]; then
echo "Warning: ${target_root} already exists." echo "Warning: ${target_root} already exists."
std::get_YN_answer "Do you really want to re-run the initialization? (y/N) " || \ std::get_YN_answer \
std::die 1 "Abort ..." "Do you really want to re-run the initialization? (y/N) " \
|| std::die 1 "Abort ..."
fi fi
force='yes' force='yes'
echo "Creating target directory '${target_root}'..." echo "Creating target directory '${target_root}'..."
${mkdir} -p "${target_root}" || \ ${mkdir} -p "${target_root}" || \
std::die 1 "Error: make directory failed!" std::die 1 "Error: make directory failed!"
echo
echo "Syncing configuration ..." echo "Syncing configuration ..."
sync_config "${src_root}" \ sync_config "${src_root}" \
...@@ -317,7 +306,6 @@ environment at '${PMODULES_ROOT}' ...@@ -317,7 +306,6 @@ environment at '${PMODULES_ROOT}'
"${src_root}" \ "${src_root}" \
"${target_root}" || \ "${target_root}" || \
std::die 1 "Error: sync Pmodules failed!" std::die 1 "Error: sync Pmodules failed!"
echo
for d in "${src_root}"/*/${PMODULES_MODULEFILES_DIR}; do for d in "${src_root}"/*/${PMODULES_MODULEFILES_DIR}; do
${mkdir} -p "${target_root}/${d#${src_root}/}" ${mkdir} -p "${target_root}/${d#${src_root}/}"
...@@ -404,7 +392,7 @@ subcommand_install() { ...@@ -404,7 +392,7 @@ subcommand_install() {
# to MODULEPATH. # to MODULEPATH.
# #
# The dependency files do not convey the information whether # The dependency files do not convey the information whether
# loading a module extends MODULEPATH or not. All we need to # loading a module extends MODULEPATH or not. What we need to
# know is # know is
# 1) does loading a specific module extends MODULEPATH? # 1) does loading a specific module extends MODULEPATH?
# 2) if yes: what is the hierarchical group? # 2) if yes: what is the hierarchical group?
...@@ -414,20 +402,39 @@ subcommand_install() { ...@@ -414,20 +402,39 @@ subcommand_install() {
# in the hierarchical group 'Compiler' to MODULEPATH, we # in the hierarchical group 'Compiler' to MODULEPATH, we
# know that this directory is # know that this directory is
# <pmodules_root>/Compiler/modulefiles/gcc/10.3.0 # <pmodules_root>/Compiler/modulefiles/gcc/10.3.0
local fname='' #
local -i n # This information we store in the dictionary 'group_map'.
local -a parts # For concinience reasons we store the string 'src_root/group'.
while read fname; do # So, 'group_map' maps
std::split_relpath parts "${fname}" n # module/version -> src_root/group
# We are only interested in groups adding something to #
# the modulepath. # Example:
(( n >= 6 )) || continue # group_map[gcc/10.3.0]="${src_root}/Compiler"
local key="${parts[-4]}/${parts[-3]}" #
[[ -z "${group_map[${key}]}" ]] || continue local group=''
group_map[${key}]="${src_root}/${parts[0]}" for group in "${!GroupDepths[@]}"; do
done < <({ cd "${src_root}" && \ (( ${GroupDepths[${group}]} > 0 )) || continue
${find} */"${PMODULES_MODULEFILES_DIR}" \ local fname=''
\( -type l -o -type f \) \! -name ".*"; } 2>/dev/null ) while read fname; do
local -a parts=()
std::split_relpath parts "${fname}"
if (( ${#parts[@]} - 2 != ${GroupDepths[${group}]} )); then
std::warn "error in source group ${group}:"
std::warn "modulefile: ${fname}"
continue
fi
if [[ ${#parts[@]} < 4 ]]; then
echo "${group} ${parts[@]}"
fi
local key="${parts[-4]}/${parts[-3]}"
[[ -z "${group_map[${key}]}" ]] || continue
group_map[${key}]="${src_root}/${group}"
done < <(${find} -L "${src_root}/${group}/${PMODULES_MODULEFILES_DIR}" \
\( -type l -o -type f \) \
\! -name ".*" \
-printf "%P\n" \
)
done
} }
#...................................................................... #......................................................................
...@@ -439,7 +446,7 @@ subcommand_install() { ...@@ -439,7 +446,7 @@ subcommand_install() {
# #
# Notes: # Notes:
# Following variables from the enclosing function are used: # Following variables from the enclosing function are used:
# modulepath (might be changed) # modulepath
# group_map (read-only) # group_map (read-only)
# #
resolve_dependencies () { resolve_dependencies () {
...@@ -447,9 +454,9 @@ subcommand_install() { ...@@ -447,9 +454,9 @@ subcommand_install() {
local -- prefix=$(get_module_prefix "${modulefile}") local -- prefix=$(get_module_prefix "${modulefile}")
local -a rdeps=() local -a rdeps=()
local rdeps_file="${prefix}/.dependencies" local -- rdeps_file="${prefix}/.dependencies"
local -a ideps=() local -a ideps=()
local ideps_file="${prefix}/.install_dependencies" local -- ideps_file="${prefix}/.install_dependencies"
if [[ -r "${rdeps_file}" ]]; then if [[ -r "${rdeps_file}" ]]; then
mapfile -t rdeps < <(grep -v '^ *#' "${rdeps_file}" ) mapfile -t rdeps < <(grep -v '^ *#' "${rdeps_file}" )
...@@ -471,9 +478,10 @@ subcommand_install() { ...@@ -471,9 +478,10 @@ subcommand_install() {
local rel_modulename="${modulename#${src_root}/}" local rel_modulename="${modulename#${src_root}/}"
dependencies_to_install[${rel_modulename}]='.' dependencies_to_install[${rel_modulename}]='.'
resolve_dependencies "${modulename}" resolve_dependencies "${modulename}"
if [[ -n ${group_map[${dep}]} ]]; then [[ -v group_map[${dep}] ]] || continue
modulepath+=( "${group_map[${dep}]}/${rel_modulename##+([!/])/}" ) local dir="${group_map[${dep}]}" # = ${src_root}/<group>
fi dir+="/${rel_modulename##+([!/])/}" # += rel.name with group removed
modulepath+=( "${dir}" )
done done
} }
...@@ -491,21 +499,28 @@ subcommand_install() { ...@@ -491,21 +499,28 @@ subcommand_install() {
# modules_to_install (read-only) # modules_to_install (read-only)
# dependencies_to_install (read-only) # dependencies_to_install (read-only)
# #
print_modules() {
print_modules_to_install() {
local modulefile local modulefile
local parts for modulefile in "$@"; do
std::info "The following modules will be installed/updated:" local -a parts
for modulefile in "${!modules_to_install[@]}"; do
std::split_relpath parts "${modulefile}" std::split_relpath parts "${modulefile}"
std::info " ${parts[-2]}/${parts[-1]}" local s=''
if (( ${#parts[@]} >= 6 )); then
s="(${parts[2]}/${parts[3]}"
for ((i = 4; i < ${#parts[@]}-2; i+=2)); do
s+=" ${parts[i]}/${parts[i+1]}"
done
s+=')'
fi
std::info "%-20s %s" "${parts[-2]}/${parts[-1]}" "$s"
done 2>&1 | sort done 2>&1 | sort
}
print_modules_to_install() {
std::info "The following modules will be installed/updated:"
print_modules "${!modules_to_install[@]}"
if (( ${#dependencies_to_install[@]} > 0 )); then if (( ${#dependencies_to_install[@]} > 0 )); then
std::info "\nThe following dependencies will be installed/updated:" std::info "\nThe following dependencies will be installed/updated:"
for modulefile in "${!dependencies_to_install[@]}"; do print_modules "${!dependencies_to_install[@]}"
std::split_relpath parts "${modulefile}"
std::info " ${parts[-2]}/${parts[-1]}"
done 2>&1 | sort
fi fi
std::info "" std::info ""
std::get_YN_answer "Do you want to continue? [n] " || \ std::get_YN_answer "Do you want to continue? [n] " || \
...@@ -522,19 +537,19 @@ subcommand_install() { ...@@ -522,19 +537,19 @@ subcommand_install() {
force='yes' force='yes'
;; ;;
--src | --src=*) --src | --src=*)
if [[ $1 == --src=* ]]; then if [[ $1 == --src ]]; then
src_root="${1#--*=}"
else
src_root="$2" src_root="$2"
shift shift
else
src_root="${1#--*=}"
fi fi
;; ;;
--target | --target=*) --target | --target=*)
if [[ $1 == --target=* ]]; then if [[ $1 == --target ]]; then
target_root="${1#--*=}"
else
target_root="$2" target_root="$2"
shift shift
else
target_root="${1#--*=}"
fi fi
;; ;;
--with | --with=* ) --with | --with=* )
...@@ -542,7 +557,7 @@ subcommand_install() { ...@@ -542,7 +557,7 @@ subcommand_install() {
with+=( "$2" ) with+=( "$2" )
shift shift
else else
with+=( "${1/--with=}" ) with+=( "${1#--*=}" )
fi fi
;; ;;
-- ) -- )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment