Skip to content

Merge SwanProjects into a monorepo #209

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions SwanProjects/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[bumpversion]
current_version = 0.1.0
commit = True
tag = True
tag_name = SwanProjects/v{new_version}
message = SwanProjects v{new_version}

[bumpversion:file:package.json]

5 changes: 5 additions & 0 deletions SwanProjects/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
coverage
**/*.d.ts
tests
39 changes: 39 additions & 0 deletions SwanProjects/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/naming-convention': [
'error',
{
'selector': 'interface',
'format': ['PascalCase'],
'custom': {
'regex': '^I[A-Z]',
'match': true
}
}
],
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/quotes': [
'error',
'single',
{ avoidEscape: true, allowTemplateLiterals: false }
],
curly: ['error', 'all'],
eqeqeq: 'error',
'prefer-arrow-callback': 'error'
}
};
1 change: 1 addition & 0 deletions SwanProjects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
swanprojects/labextensions
5 changes: 5 additions & 0 deletions SwanProjects/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
**/node_modules
**/lib
**/package.json
swanterminal
5 changes: 5 additions & 0 deletions SwanProjects/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid"
}
661 changes: 661 additions & 0 deletions SwanProjects/LICENSE

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions SwanProjects/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
include LICENSE
include README.md
include pyproject.toml
recursive-include jupyter-config *.json

include swanprojects/kernelmanager/resources/*
include swanprojects/stacks/*/*
include swanprojects/static/index.html
include package.json
include install.json
include ts*.json
include yarn.lock

graft swanprojects/labextensions

# Javascript files
graft src
graft style
prune **/node_modules
prune lib
prune binder

# Patterns to exclude from any directory
global-exclude *~
global-exclude *.pyc
global-exclude *.pyo
global-exclude .git
global-exclude .ipynb_checkpoints
34 changes: 34 additions & 0 deletions SwanProjects/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SwanProjects

Server and Lab extension that provides:
* In the backend, the endpoints to:
* Create and edit projects
* Get project information
* Get software stack information
* A customized Kernel Spec Manager to handle kernel metadata
* In the Lab extension:
* React dialogs to create and edit projects
* LabIcons required for the dialogs

## Requirements

JupyterLab~=3.0 and SwanContents

## Install

Install the package and the lab extension:

```bash
pip install swanprojects
```

To replace the default Jupyter Contents Manager and Kernel Spec Manager in the JupyterLab Notebook configuration (i.e in `jupyter_notebook_config.py`), set the following:

```python
c.NotebookApp.contents_manager_class = 'swancontents.filemanager.swanfilemanager.SwanFileManager'
c.NotebookApp.kernel_spec_manager_class = 'swanprojects.kernelmanager.kernelspecmanager.SwanKernelSpecManager'
c.KernelSpecManager.ensure_native_kernel = False

c.SwanConfig.stacks_path=path_to_stacks_folder
c.SwanConfig.kernel_resources=path_to_native_kernel_resources
```
50 changes: 50 additions & 0 deletions SwanProjects/bin/swan_bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash -i
#Author [email protected] 2021
###
# This is called from the extension SwanTerminal and it requires the project path and stacks path as arguments.
# The project path is used to read the .swanproject file and the stacks path is required to load the proper enviroment.
# When the bash session is started we modify the prompt indicating in which project the terminal is located.
# Additionally, the bash session runs completely isolated from other possible environments,
# so we need to define some basic environment variables such as:
#
# * HOME with path to the user home
# * PATH with default paths for the system
# * OAUTH2_TOKEN required by EOS storage
#
# swan_env will load the other variables from the stack, inside the isolated enviroment.
###

clear
if ! [ -x "$(command -v jq)" ]; then
echo 'Error: jq is not installed.' >&2
sleep 60
exit 1
fi
if [[ $# -gt 1 ]] ; then
PROJECT_PATH=$1
PROJECT_NAME=`IFS='/'; ARR=($PROJECT_PATH);echo "${ARR[-1]}"`
PROJECT_FILE="$PROJECT_PATH/.swanproject"

STACKS_PATH="$2"

if [ -d "$PROJECT_PATH" ]
then
STACK=`jq '.stack' "$PROJECT_FILE"`
RELEASE=`jq '.release' "$PROJECT_FILE"`
PLATFORM=`jq '.platform' "$PROJECT_FILE"`
USER_SCRIPT="$PROJECT_PATH/.userscript"
echo "Loading $RELEASE with plafortm $PLATFORM "
# FIXME: this have to be removed when environment isolation is not needed anymore, it's only temporary
env -i HOME=$HOME \
OAUTH2_TOKEN=$OAUTH2_TOKEN \
PROJECT="$PROJECT_NAME" \
PROJECT_PATH="$PROJECT_PATH" PS1="$PS1" \
bash -c "swan_env \"$PROJECT_PATH\" \"$STACKS_PATH\" \"$PROJECT_PATH\" bash --rcfile <(echo 'PS1=\"($PROJECT_NAME) $PS1 \"') "
else
echo "Error: project $PROJECT_PATH doesn't exist" >&2
# JupyterLab closes the terminal window immediately after the process ends
# this sleep is to allow the user to see the message
sleep 60
exit 1
fi
fi
92 changes: 92 additions & 0 deletions SwanProjects/bin/swan_env
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash
#Author [email protected] 2021
###
# This script allows to execute code inside the project environment.
#
# The parameters are:
# * Project name: Name of the project.
# * Cwd: Current working directory, where the command will be executed.
# * Command: command to execute inside the project environment.
#
#
# With the project name we search the project located at $HOME/SWAN_projects/
# reading the configuration to load the environment and the bash script provided by the user.
#
# This script is called from SwanKernelSpecManager to start the kernel and from swan_bash to start a bash session inside the project environment.
##
PARAMETERS=("$@")
# Check if jq is installed
if ! [ -x "$(command -v jq)" ]; then
echo 'Error: jq is not installed.' >&2
# JupyterLab closes the terminal window immediately after the process ends
# this sleep is to allow the user to see the message
sleep 60
exit 1
fi

# Check arguments
if [[ $# -lt 3 ]] ; then
echo 'Error: project name, cwd and commands required.' >&2
echo 'Format is: swan_env myproject cwd command command_options' >&2
echo 'Example: swan_env myproject . python --version (shows version for the python inside the project environment)' >&2
# JupyterLab closes the terminal window immediately after the process ends
# this sleep is to allow the user to see the message
sleep 60
exit 1
fi

###
# In the next block I make the path to the project to read the information from .swanproject file such as
# stack, release and platform.
# I also create the path to use bash user script to source it.
###
PROJECT_PATH=$1
PROJECT_NAME=`IFS='/'; ARR=($PROJECT_PATH);echo "${ARR[-1]}"`
PROJECT_FILE="$PROJECT_PATH/.swanproject"
STACK=`jq -r '.stack' "$PROJECT_FILE"`
RELEASE=`jq -r '.release' "$PROJECT_FILE"`
PLATFORM=`jq -r '.platform' "$PROJECT_FILE"`
USER_SCRIPT="$PROJECT_PATH/.userscript"

# Path to the stack where the setup.sh for this project is located.
# The available stacks are provided in the extension with --SwanProjects.stacks_path
STACKS_PATH="$2"
STACK_PATH="$STACKS_PATH/$STACK"
STACK_SETUP="$STACK_PATH/setup.sh"

# Working directory parameter
CWD="$3"
i=2

for j in $(seq 0 1 $((i)));do
unset PARAMETERS[$j]
done
# After project name and working directory the remaining option passed to the script is the command to be execute inside the environment.
COMMAND=${PARAMETERS[@]}

if [ ! -d $STACK_PATH ]; then
echo "Error sourcing the environment, the stack $STACK was not found in stacks path $STACKS_PATH" >&2
echo "project $PROJECT_NAME can not be loeaded." >&2
exit 1
fi

if [ -f $STACK_SETUP ]; then
. $STACK_SETUP
else
echo "Error loading stack setup.sh on $STACK_SETUP, file doesn't exists." >&2
exit 1
fi

# The next variables allow the user to know in the environment basic information about the project such as stack, name and path.
export SWAN_STACK="$RELEASE($PLATFORM)"
export SWAN_PROJECT_NAME=$PROJECT_NAME
export SWAN_PROJECT_PATH=$PROJECT_PATH

if [ "$USER_SCRIPT" != "" ] && [ -f "$USER_SCRIPT" ]; then
. "${USER_SCRIPT}"
fi

# The command is executed inside the $CWD folder.
# if the command produces output it will be there.
cd "$CWD"
$COMMAND
Loading