Closed mwermelinger closed 1 year ago
The Windows script is done, apart from creating aliases like the Unix script. I believe the script must do:
$PROFILE.CurrentUserCurrentHost
exists; if not, create it. (That file is the equivalent of ~/.bashrc
. Any functions and aliases defined by it can be typed into the PowerShell prompt.)function m269-23j {
cd $FOLDER
$VENV\Scripts\Activate.ps1
}
function nb {
Start-Job jupyter notebook $FOLDER
}
function allowed {
python $FOLDER\allowed.py -c $FOLDER\m269.json
}
where variables $FOLDER
and $VENV
have been defined in the install.ps1
script.
Unfortunately I got into syntax problems with the above in PowerShell 5.1: something about only accepting one argument or whatever. I couldn't figure out what the problem was. I also tried Set-Alias
instead of defining functions, but couldn't get it to work. Furthermore, I don't know how the allowed
function can pass any remaining arguments to the python allowed.py ...
command, so that the user can type allowed TMA01\23J_TMA01.ipynb
, for example.
Someone knowledgeable in PowerShell thus needs to do this. Maybe one has to assume PowerShell Core 6.0+, but then the instructions must tell students to enter $PSVersionTable
to find out the version and how to install PowerShell Core.
I have had some success by adding the following to install.ps1
. (VirtualBox, Windows 10 Home, PowerShell 5.1)
Write-Host "Adding shortcut commands to the PowerShell config file..."
$CONFIG_FILE = $Profile.CurrentUserCurrentHost
$ALIASES = @"
function m269-23j {
cd $FOLDER
$VENV\Scripts\Activate.ps1
}
function nb {
jupyter notebook $FOLDER
}
function allowed {
param(
[string]`$FilePath
)
python $FOLDER\allowed.py -c $FOLDER\m269.json `$FilePath
}
"@
# Check if the config file exists
if (-not (Test-Path -Path $CONFIG_FILE)) {
# File doesn't exist, create it
New-Item -Path $CONFIG_FILE -ItemType File -Force
}
# Append aliases to the file
Add-Content -Path $CONFIG_FILE -Value $ALIASES -NoNewline
I could not get the Start-Job
command to work in the nb
alias/function, so have just left it off for now.
Instead of requiring WSL to then reuse the bash script, it's easier for Windows users to have their own batch or PowerShell script to install the software directly in Windows. The script would be similar in functionality to the bash script:
requirements.txt
exists; if not, stop with an error message.<M269 folder>/venv
where the M269 folder is the script's argument.requirements.txt
, deactivate the environment.requirements.txt
and be separately installed by the bash scriptcustom.css
to the right place.allowed.py
andm269.json
to the M269 folder.Finally, the script should create an easy way for the user to activate the environment, launch the notebooks and use
allowed
. The bash script does this by creating aliases in the startup shell files.In Windows, one possibility is for the installation script to put another a script (let's call it
m269-23j.ps1
) in the M269 folder. When double-clicked, that script opens a command prompt,cd
s to the M269 folder, activates the environment and uses theSet-Alias
cmdlet to create aliasesnb
andallowed
like the bash script.As I'm not a Windows user, I don't know if this is feasible or whether there's a better way to do it.