You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scripts/activateCondaEnvironment.sh
+20-14Lines changed: 20 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,33 @@
1
1
#!/usr/bin/env bash
2
2
3
-
# Activates the Conda (Python package manager) environment "codegraph" with all packages needed to execute the Jupyter Notebooks.
3
+
# Activates the Conda (Python package manager) environment "codegraph" with all packages needed to run the included Jupyter Notebooks and Python scripts.
4
4
5
5
# Note: This script uses the conda environment defined in CODEGRAPH_CONDA_ENVIRONMENT (defaults to "codegraph").
6
-
# If the environment hadn't been created yet, it will use "conda-environment.yml" from the root directory
7
-
# in the same directory as the given jupyter notebook ipynb file
8
-
# to create the environment.
6
+
# If the environment hadn't been created yet, it will use "conda-environment.yml" from the root directory to create the environment.
9
7
10
8
# Requires operatingSystemFunctions.sh
11
9
12
10
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
13
11
set -o errexit -o pipefail
14
12
13
+
PREPARE_CONDA_ENVIRONMENT=${PREPARE_CONDA_ENVIRONMENT:-"true"}# Wether to prepare a Python environment with Conda if needed (default, "true") or use an already prepared Conda environment ("false")
14
+
15
+
if [ "${PREPARE_CONDA_ENVIRONMENT}"="false" ];then
16
+
echo"activateCondaEnvironment: Skipping activation. An already activated environment and installed dependencies are expected (PREPARE_CONDA_ENVIRONMENT=false)."
17
+
# "return" needs to be used here instead of "exit".
18
+
# This script is included in another script by using "source".
19
+
# "exit" would end the main script, "return" just ends this sub script.
20
+
return 0
21
+
fi
22
+
23
+
if [ "${USE_VIRTUAL_PYTHON_ENVIRONMENT_VENV}"="true" ];then
24
+
echo"activateCondaEnvironment: Skipping activation. venv will be used instead of conda (USE_VIRTUAL_PYTHON_ENVIRONMENT_VENV=true)."
25
+
# "return" needs to be used here instead of "exit".
26
+
# This script is included in another script by using "source".
27
+
# "exit" would end the main script, "return" just ends this sub script.
28
+
return 0
29
+
fi
30
+
15
31
## Get this "scripts" directory if not already set
16
32
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
17
33
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
PREPARE_CONDA_ENVIRONMENT=${PREPARE_CONDA_ENVIRONMENT:-"true"}# Wether to prepare a Python environment with Conda if needed (default, "true") or use an already prepared Conda environment ("false")
41
-
42
-
if [ "${PREPARE_CONDA_ENVIRONMENT}"="false" ];then
43
-
echo"activateCondaEnvironment: Skipping activation. ${PREPARE_CONDA_ENVIRONMENT} is set to false."
44
-
# "return" needs to be used here instead of "exit".
45
-
# This script is included in another script by using "source".
46
-
# "exit" would end the main script, "return" just ends this sub script.
47
-
return 0
48
-
fi
49
-
50
56
# Include operation system function to for example detect Windows.
# Activates the .venv environment (Python build-in virtual environments) with all packages necessary to run the included Jupyter Notebooks and Python scripts.
4
+
5
+
# Note: If the environment hadn't been created yet, it will use "requirements.txt" from the root directory to create the environment.
6
+
7
+
# Requires operatingSystemFunctions.sh
8
+
9
+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
10
+
set -o errexit -o pipefail
11
+
12
+
exit_failed() {
13
+
case"$0"in
14
+
*/sh) return 1 ;; # Script is sourced
15
+
*) exit 1 ;; # Script is executed directly
16
+
esac
17
+
}
18
+
19
+
exit_successful() {
20
+
case"$0"in
21
+
*/sh) return 0 ;; # Script is sourced
22
+
*) exit 0 ;; # Script is executed directly
23
+
esac
24
+
}
25
+
26
+
USE_VIRTUAL_PYTHON_ENVIRONMENT_VENV=${USE_VIRTUAL_PYTHON_ENVIRONMENT_VENV:-"false"}# Use "venv" for virtual Python environments ("true") or use an already prepared (e.g. conda) environment (default, "false").
27
+
28
+
if [ "${USE_VIRTUAL_PYTHON_ENVIRONMENT_VENV}"="false" ];then
29
+
echo"activatePythonEnvironment: Skipping activation. An already activated environment and installed dependencies are expected e.g. by using conda (USE_VIRTUAL_PYTHON_ENVIRONMENT_VENV=false)."
30
+
# "return" needs to be used here instead of "exit".
31
+
# This script is included in another script by using "source".
32
+
# "exit" would end the main script, "return" just ends this sub script.
33
+
exit_successful
34
+
fi
35
+
36
+
## Get this "scripts" directory if not already set
37
+
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
38
+
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
39
+
# This way non-standard tools like readlink aren't needed.
40
+
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}# Repository directory containing the shell scripts
0 commit comments