Skip to content

Commit

Permalink
Fix #20, fix #21, fix #22 (#23)
Browse files Browse the repository at this point in the history
* Address #20 (tested on macOS)

* Address #21 (tested on macOS)

* Address #22 (tested on macOS)
  • Loading branch information
mwermelinger authored Aug 22, 2023
1 parent ff53a18 commit b0e7912
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ you select and copy them from this page and paste them into the command line.
5. Run the installation script:
- Windows: `.\install.ps1`
- Unix: `./install.sh`
6. Once the script has finished, remove it:
- Windows: `rm install.ps1`
- Unix: `rm install.sh`
7. Close the terminal.
6. Close the terminal.

You will have the following files in your M269 folder:
- the installation script in `install.ps1` or `install.sh`
- the list of M269 software in `requirements.txt`
- the style changes to Jupyter notebooks in `custom.css`
- the code checker (see Section 4 below) in `allowed.py` and `m269.json`

We recommend you do _not_ remove these files, so that you can re-install
the software, if needed.

## 3 Usage

Expand Down Expand Up @@ -160,6 +166,19 @@ If you want to remove the M269 styling of notebooks:
2. Delete all lines from the comment marking the start of M269-23J styling up to the comment ending it.
3. Save the file and close the editor.

## 6 Re-installing

If you haven't removed the installation files from your M269 folder,
you can re-install the software after uninstalling it,
e.g. to work again on your M269 notebooks. Do as follows:

1. Open a PowerShell (Windows) or a terminal (Unix).
2. Go to your M269 folder by entering `cd <M269 folder path>`, e.g. `cd ~/OU/m269-23j`.
3. Run the installation script with `.\install.ps1 .` (Windows) or `./install.sh .` (Unix).
Note the extra space and period after the command, compared to step 5 in Section 2.
(During re-installation, ignore messages saying that a file can't be copied onto itself.)
4. Close the terminal.

## Licence

The code and text in this repository are
Expand Down
26 changes: 13 additions & 13 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ $VENV = "$HOME\venvs\$COURSE"
function is-m269-folder {
param($path)
if (-not (Test-Path $path -PathType Container)) {
$folder = $path
$msg="doesn't exist or isn't a folder"
}
elseif (-not ($path -match "[Mm]269-23[Jj]$")) {
$msg="must be named m269-23j or M269-23J"
}
else
{
return
else {
$folder = Convert-Path $path
if (-not ((Get-Item $folder).Name -match "[Mm]269-23[Jj]")) {
$msg="must be named m269-23j or M269-23J"
}
else
{
return
}
}
Write-Host "$path can't be your M269 folder: it $msg."; Write-Host $DOC
Write-Host "$folder can't be your M269 folder: it $msg."; Write-Host $DOC
exit
}

Expand All @@ -51,9 +55,8 @@ if ($args.Length -gt 1) {
mkdir $HOME\.jupyter\custom -ErrorAction SilentlyContinue
if (Test-Path $HOME\.jupyter\custom\custom.css) {
Add-Content -Path $HOME\.jupyter\custom\custom.css -Value (Get-Content custom.css)
Remove-Item custom.css
} else {
Move-Item -Path custom.css -Destination $HOME\.jupyter\custom
Copy-Item -Path custom.css -Destination $HOME\.jupyter\custom
}
} else {
is-m269-folder $args[0]
Expand Down Expand Up @@ -84,9 +87,6 @@ Write-Host "Downloading and installing Python packages... (this will take long)"
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
deactivate
if ($args.Length -eq 0) {
Remove-Item requirements.txt
}

Write-Host "Adding shortcut commands to the PowerShell config file..."

Expand All @@ -98,7 +98,7 @@ function m269-23j {
$VENV\Scripts\Activate.ps1
}
function nb {
Start-process -NoNewWindow jupyter -ArgumentList "notebook $ESC$FOLDER$ESC"
Start-process -NoNewWindow jupyter -ArgumentList "notebook"
}
function allowed {
param(
Expand Down
24 changes: 11 additions & 13 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ fi
is_m269_folder () {
if [[ ! -d $1 ]] # single bracket would split path string on spaces
then
folder=$1
msg="doesn't exist or isn't a folder"
elif [[ $(basename "$1") != [Mm]269-23[Jj] ]]
then
msg="must be named m269-23j or M269-23J"
else
return
folder=$(cd "$1"; pwd)
if [[ $(basename "$folder") != [Mm]269-23[Jj] ]]
then
msg="must be named m269-23j or M269-23J"
else
return
fi
fi
echo "$1 can't be your M269 folder: it $msg." ; echo $DOC
echo "$folder can't be your M269 folder: it $msg." ; echo $DOC
exit 1
}

Expand All @@ -90,9 +94,8 @@ then
if [ -f ~/.jupyter/custom/$CSS ]
then
cat $CSS >> ~/.jupyter/custom/$CSS
rm $CSS
else
mv $CSS ~/.jupyter/custom
cp -a $CSS ~/.jupyter/custom
fi
else
is_m269_folder "$1"
Expand Down Expand Up @@ -126,17 +129,12 @@ pip install --upgrade pip
pip install -r $REQS
pip install pytype==2023.4.27 # install pytype only for Unix
deactivate
# if we're in the M269 folder, remove the no longer needed file
if [ $# -eq 0 ]
then
rm $REQS
fi
echo "Software has been installed."

echo "Adding shortcut commands to $shell's startup file..."

M269="cd \"$FOLDER\";source $VENV/bin/activate"
NB="jupyter notebook \"$FOLDER\"&"
NB="jupyter notebook &"
ALLOWED="python3.10 \"$FOLDER/allowed.py\" -c \"$FOLDER/m269.json\""

if [ $shell = "fish" ]
Expand Down

0 comments on commit b0e7912

Please sign in to comment.