Skip to content

Commit

Permalink
swancustomenvironments: New option for NXCals
Browse files Browse the repository at this point in the history
When NXCals flag is specified, installs sparkconnector, sparkmonitor and nxcals for accpy environments
  • Loading branch information
rodrigo-sobral authored and etejedor committed Oct 15, 2024
1 parent bd8e5b4 commit 00e76c4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ eval "${ACTIVATE_ENV_CMD}"

# Install packages in the environment and the same ipykernel that the Jupyter server uses
_log "Installing packages from ${REQ_PATH}..."
pip install -r "${REQ_PATH}" "ipykernel==${IPYKERNEL_VERSION}" | tee -a ${LOG_FILE}
pip install -r "${REQ_PATH}" "ipykernel==${IPYKERNEL_VERSION}" ${SPARKCONNECTOR} ${SPARKMONITOR} ${NXCALS} | tee -a ${LOG_FILE}
14 changes: 13 additions & 1 deletion SwanCustomEnvironments/swancustomenvironments/scripts/makenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ define_repo_path() {

# Function for printing the help page
print_help() {
_log "Usage: makenv --repo REPOSITORY --repo_type TYPE --builder BUILDER --builder_version VERSION [--help/-h]"
_log "Usage: makenv --repo REPOSITORY --repo_type TYPE --builder BUILDER --builder_version VERSION --nxcals [--help/-h]"
_log "Options:"
_log " --repo REPOSITORY Path or http link for a public repository"
_log " --repo_type TYPE Type of repository (git or eos)"
_log " --builder BUILDER Builder to create the environment"
_log " --builder_version VERSION Version of the builder to use (optional)"
_log " --nxcals Install NXCALS package and Spark extensions in the environment (optional)"
_log " -h, --help Print this help page"
}

Expand Down Expand Up @@ -101,6 +102,10 @@ while [ $# -gt 0 ]; do
shift
shift
;;
--nxcals)
INSTALL_NXCALS=true
shift
;;
--help|-h)
print_help
exit 0
Expand Down Expand Up @@ -177,6 +182,13 @@ ENV_PATH="/home/$USER/${ENV_NAME}"
REQ_PATH="${REPO_PATH}/requirements.txt"
IPYKERNEL_VERSION=$(python -c "import ipykernel; print(ipykernel.__version__)")

# Libraries need to be installed and not linked, due to their dependencies
if [ -n "${INSTALL_NXCALS}" ]; then
SPARKCONNECTOR="sparkconnector==$(python3 -c 'import sparkconnector; print(sparkconnector.__version__)')"
SPARKMONITOR="sparkmonitor==$(python3 -c 'import sparkmonitor; print(sparkmonitor.__version__)')"
NXCALS="nxcals"
fi

# Check if requirements.txt exists in the repository
if [ ! -f "${REQ_PATH}" ]; then
_log "ERROR: Requirements file not found (${REQ_PATH})."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ def get(self):
repo_type (str): The type of repository (git or eos).
builder (str): The builder used for creating the environment.
builder_version (str): The version of the specified builder.
nxcals (bool): Whether to include NXCALS and Spark extensions in the environment.
"""
self.set_header("Content-Type", "text/event-stream")

repository = self.get_query_argument("repo", default="")
repo_type = self.get_query_argument("repo_type", default="")
builder = self.get_query_argument("builder", default="")
builder_version = self.get_query_argument("builder_version", default="")
nxcals = self.get_query_argument("nxcals", default="")

arguments = ["--repo", repository, "--repo_type", repo_type, "--builder", builder]
if builder_version:
arguments.extend(("--builder_version", builder_version))
if nxcals:
arguments.append("--nxcals")

makenv_process = subprocess.Popen([self.makenv_path, *arguments], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ <h2 id="modal-title" style="text-align: left;"></h2>
var builder = urlParams.get('builder') || "";
var builder_version = urlParams.get('builder_version') || "";
var file = `/${urlParams.get('file') || ""}`;
var nxcals = urlParams.get('nxcals') || "";

// Environment creation elements
var outputBox = document.getElementById('output-box');
Expand Down Expand Up @@ -242,7 +243,7 @@ <h2 id="modal-title" style="text-align: left;"></h2>
}


fetch(`${base_url}api/customenvs?repo=${encodeURIComponent(repository)}&repo_type=${encodeURIComponent(repo_type)}&builder=${encodeURIComponent(builder)}&builder_version=${encodeURIComponent(builder_version)}`, {
fetch(`${base_url}api/customenvs?repo=${encodeURIComponent(repository)}&repo_type=${encodeURIComponent(repo_type)}&builder=${encodeURIComponent(builder)}&builder_version=${encodeURIComponent(builder_version)}&nxcals=${encodeURIComponent(nxcals)}`, {
method: 'GET',
headers: get_jh_auth_header(),
})
Expand Down

0 comments on commit 00e76c4

Please sign in to comment.