Skip to content

Commit 0fe376a

Browse files
committed
Merge SwanProjects, SwanTerminal, SwanLauncher, SwanFileBrowser into single package
1 parent d5bcd59 commit 0fe376a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+34253
-0
lines changed

SwanProjects/.bumpversion.cfg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[bumpversion]
2+
current_version = 0.1.0
3+
commit = True
4+
tag = True
5+
tag_name = SwanProjects/v{new_version}
6+
message = SwanProjects v{new_version}
7+
8+
[bumpversion:file:package.json]
9+

SwanProjects/.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
coverage
4+
**/*.d.ts
5+
tests

SwanProjects/.eslintrc.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
extends: [
3+
'eslint:recommended',
4+
'plugin:@typescript-eslint/eslint-recommended',
5+
'plugin:@typescript-eslint/recommended',
6+
'plugin:prettier/recommended'
7+
],
8+
parser: '@typescript-eslint/parser',
9+
parserOptions: {
10+
project: 'tsconfig.json',
11+
sourceType: 'module'
12+
},
13+
plugins: ['@typescript-eslint'],
14+
rules: {
15+
'@typescript-eslint/naming-convention': [
16+
'error',
17+
{
18+
'selector': 'interface',
19+
'format': ['PascalCase'],
20+
'custom': {
21+
'regex': '^I[A-Z]',
22+
'match': true
23+
}
24+
}
25+
],
26+
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
27+
'@typescript-eslint/no-explicit-any': 'off',
28+
'@typescript-eslint/no-namespace': 'off',
29+
'@typescript-eslint/no-use-before-define': 'off',
30+
'@typescript-eslint/quotes': [
31+
'error',
32+
'single',
33+
{ avoidEscape: true, allowTemplateLiterals: false }
34+
],
35+
curly: ['error', 'all'],
36+
eqeqeq: 'error',
37+
'prefer-arrow-callback': 'error'
38+
}
39+
};

SwanProjects/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
swanprojects/labextensions

SwanProjects/.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
**/node_modules
3+
**/lib
4+
**/package.json
5+
swanterminal

SwanProjects/.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "none",
4+
"arrowParens": "avoid"
5+
}

SwanProjects/LICENSE

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

SwanProjects/MANIFEST.in

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
include LICENSE
2+
include README.md
3+
include pyproject.toml
4+
recursive-include jupyter-config *.json
5+
6+
include swanprojects/kernelmanager/resources/*
7+
include swanprojects/stacks/*/*
8+
include swanprojects/static/index.html
9+
include package.json
10+
include install.json
11+
include ts*.json
12+
include yarn.lock
13+
14+
graft swanprojects/labextensions
15+
16+
# Javascript files
17+
graft src
18+
graft style
19+
prune **/node_modules
20+
prune lib
21+
prune binder
22+
23+
# Patterns to exclude from any directory
24+
global-exclude *~
25+
global-exclude *.pyc
26+
global-exclude *.pyo
27+
global-exclude .git
28+
global-exclude .ipynb_checkpoints

SwanProjects/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SwanProjects
2+
3+
Server and Lab extension that provides:
4+
* In the backend, the endpoints to:
5+
* Create and edit projects
6+
* Get project information
7+
* Get software stack information
8+
* A customized Kernel Spec Manager to handle kernel metadata
9+
* In the Lab extension:
10+
* React dialogs to create and edit projects
11+
* LabIcons required for the dialogs
12+
13+
## Requirements
14+
15+
JupyterLab~=3.0 and SwanContents
16+
17+
## Install
18+
19+
Install the package and the lab extension:
20+
21+
```bash
22+
pip install swanprojects
23+
```
24+
25+
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:
26+
27+
```python
28+
c.NotebookApp.contents_manager_class = 'swancontents.filemanager.swanfilemanager.SwanFileManager'
29+
c.NotebookApp.kernel_spec_manager_class = 'swanprojects.kernelmanager.kernelspecmanager.SwanKernelSpecManager'
30+
c.KernelSpecManager.ensure_native_kernel = False
31+
32+
c.SwanConfig.stacks_path=path_to_stacks_folder
33+
c.SwanConfig.kernel_resources=path_to_native_kernel_resources
34+
```

SwanProjects/bin/swan_bash

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash -i
2+
#Author [email protected] 2021
3+
###
4+
# This is called from the extension SwanTerminal and it requires the project path and stacks path as arguments.
5+
# The project path is used to read the .swanproject file and the stacks path is required to load the proper enviroment.
6+
# When the bash session is started we modify the prompt indicating in which project the terminal is located.
7+
# Additionally, the bash session runs completely isolated from other possible environments,
8+
# so we need to define some basic environment variables such as:
9+
#
10+
# * HOME with path to the user home
11+
# * PATH with default paths for the system
12+
# * OAUTH2_TOKEN required by EOS storage
13+
#
14+
# swan_env will load the other variables from the stack, inside the isolated enviroment.
15+
###
16+
17+
clear
18+
if ! [ -x "$(command -v jq)" ]; then
19+
echo 'Error: jq is not installed.' >&2
20+
sleep 60
21+
exit 1
22+
fi
23+
if [[ $# -gt 1 ]] ; then
24+
PROJECT_PATH=$1
25+
PROJECT_NAME=`IFS='/'; ARR=($PROJECT_PATH);echo "${ARR[-1]}"`
26+
PROJECT_FILE="$PROJECT_PATH/.swanproject"
27+
28+
STACKS_PATH="$2"
29+
30+
if [ -d "$PROJECT_PATH" ]
31+
then
32+
STACK=`jq '.stack' "$PROJECT_FILE"`
33+
RELEASE=`jq '.release' "$PROJECT_FILE"`
34+
PLATFORM=`jq '.platform' "$PROJECT_FILE"`
35+
USER_SCRIPT="$PROJECT_PATH/.userscript"
36+
echo "Loading $RELEASE with plafortm $PLATFORM "
37+
# FIXME: this have to be removed when environment isolation is not needed anymore, it's only temporary
38+
env -i HOME=$HOME \
39+
OAUTH2_TOKEN=$OAUTH2_TOKEN \
40+
PROJECT="$PROJECT_NAME" \
41+
PROJECT_PATH="$PROJECT_PATH" PS1="$PS1" \
42+
bash -c "swan_env \"$PROJECT_PATH\" \"$STACKS_PATH\" \"$PROJECT_PATH\" bash --rcfile <(echo 'PS1=\"($PROJECT_NAME) $PS1 \"') "
43+
else
44+
echo "Error: project $PROJECT_PATH doesn't exist" >&2
45+
# JupyterLab closes the terminal window immediately after the process ends
46+
# this sleep is to allow the user to see the message
47+
sleep 60
48+
exit 1
49+
fi
50+
fi

SwanProjects/bin/swan_env

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
#Author [email protected] 2021
3+
###
4+
# This script allows to execute code inside the project environment.
5+
#
6+
# The parameters are:
7+
# * Project name: Name of the project.
8+
# * Cwd: Current working directory, where the command will be executed.
9+
# * Command: command to execute inside the project environment.
10+
#
11+
#
12+
# With the project name we search the project located at $HOME/SWAN_projects/
13+
# reading the configuration to load the environment and the bash script provided by the user.
14+
#
15+
# This script is called from SwanKernelSpecManager to start the kernel and from swan_bash to start a bash session inside the project environment.
16+
##
17+
PARAMETERS=("$@")
18+
# Check if jq is installed
19+
if ! [ -x "$(command -v jq)" ]; then
20+
echo 'Error: jq is not installed.' >&2
21+
# JupyterLab closes the terminal window immediately after the process ends
22+
# this sleep is to allow the user to see the message
23+
sleep 60
24+
exit 1
25+
fi
26+
27+
# Check arguments
28+
if [[ $# -lt 3 ]] ; then
29+
echo 'Error: project name, cwd and commands required.' >&2
30+
echo 'Format is: swan_env myproject cwd command command_options' >&2
31+
echo 'Example: swan_env myproject . python --version (shows version for the python inside the project environment)' >&2
32+
# JupyterLab closes the terminal window immediately after the process ends
33+
# this sleep is to allow the user to see the message
34+
sleep 60
35+
exit 1
36+
fi
37+
38+
###
39+
# In the next block I make the path to the project to read the information from .swanproject file such as
40+
# stack, release and platform.
41+
# I also create the path to use bash user script to source it.
42+
###
43+
PROJECT_PATH=$1
44+
PROJECT_NAME=`IFS='/'; ARR=($PROJECT_PATH);echo "${ARR[-1]}"`
45+
PROJECT_FILE="$PROJECT_PATH/.swanproject"
46+
STACK=`jq -r '.stack' "$PROJECT_FILE"`
47+
RELEASE=`jq -r '.release' "$PROJECT_FILE"`
48+
PLATFORM=`jq -r '.platform' "$PROJECT_FILE"`
49+
USER_SCRIPT="$PROJECT_PATH/.userscript"
50+
51+
# Path to the stack where the setup.sh for this project is located.
52+
# The available stacks are provided in the extension with --SwanProjects.stacks_path
53+
STACKS_PATH="$2"
54+
STACK_PATH="$STACKS_PATH/$STACK"
55+
STACK_SETUP="$STACK_PATH/setup.sh"
56+
57+
# Working directory parameter
58+
CWD="$3"
59+
i=2
60+
61+
for j in $(seq 0 1 $((i)));do
62+
unset PARAMETERS[$j]
63+
done
64+
# After project name and working directory the remaining option passed to the script is the command to be execute inside the environment.
65+
COMMAND=${PARAMETERS[@]}
66+
67+
if [ ! -d $STACK_PATH ]; then
68+
echo "Error sourcing the environment, the stack $STACK was not found in stacks path $STACKS_PATH" >&2
69+
echo "project $PROJECT_NAME can not be loeaded." >&2
70+
exit 1
71+
fi
72+
73+
if [ -f $STACK_SETUP ]; then
74+
. $STACK_SETUP
75+
else
76+
echo "Error loading stack setup.sh on $STACK_SETUP, file doesn't exists." >&2
77+
exit 1
78+
fi
79+
80+
# The next variables allow the user to know in the environment basic information about the project such as stack, name and path.
81+
export SWAN_STACK="$RELEASE($PLATFORM)"
82+
export SWAN_PROJECT_NAME=$PROJECT_NAME
83+
export SWAN_PROJECT_PATH=$PROJECT_PATH
84+
85+
if [ "$USER_SCRIPT" != "" ] && [ -f "$USER_SCRIPT" ]; then
86+
. "${USER_SCRIPT}"
87+
fi
88+
89+
# The command is executed inside the $CWD folder.
90+
# if the command produces output it will be there.
91+
cd "$CWD"
92+
$COMMAND

0 commit comments

Comments
 (0)