proper python environments

This commit is contained in:
Ondrej Samohel 2021-01-19 19:32:04 +01:00 committed by Ondřej Samohel
parent f7d943bec7
commit 8df840995e
No known key found for this signature in database
GPG key ID: 02376E18990A97C6
42 changed files with 302 additions and 81 deletions

View file

@ -175,6 +175,14 @@ Write-Host "OK" -ForegroundColor green
Write-Host ">>> " -NoNewline -ForegroundColor green
Write-Host "Building Pype ..."
$out = & python setup.py build 2>&1
if ($LASTEXITCODE -ne 0)
{
Write-Host "!!! " -NoNewLine -ForegroundColor Red
Write-Host "Build failed. Check the log: " -NoNewline
Write-Host ".\build\build.log" -ForegroundColor Yellow
deactivate
Exit-WithCode $LASTEXITCODE
}
Set-Content -Path "$($pype_root)\build\build.log" -Value $out
& python -B "$($pype_root)\tools\build_dependencies.py"

View file

@ -88,7 +88,10 @@ elif sys.platform == "win32":
build_dir = Path(os.path.dirname(__file__)).parent / "build" / build_dir
_print(f"Using build at {build_dir}", 2)
assert build_dir.exists(), "Build directory doesn't exist"
if not build_dir.exists():
_print("Build directory doesn't exist", 1)
_print("Probably freezing of code failed. Check ./build/build.log", 3)
sys.exit(1)
deps_dir = build_dir / "dependencies"

View file

@ -9,7 +9,7 @@
.EXAMPLE
PS> .\build.ps1
PS> .\create_env.ps1
#>

View file

@ -1,6 +1,6 @@
<#
.SYNOPSIS
Helper script create virtual env.
Helper script create distributable Pype zip.
.DESCRIPTION
This script will detect Python installation, create venv and install
@ -9,7 +9,7 @@
.EXAMPLE
PS> .\build.ps1
PS> .\create_zip.ps1
#>

View file

@ -1,7 +1,91 @@
<#
.SYNOPSIS
Helper script to run mongodb.
.DESCRIPTION
This script will detect mongodb, add it to the PATH and launch it on specified port and db location.
.EXAMPLE
PS> .\run_mongo.ps1
#>
$art = @"
____________
/\ ___ \
\ \ \/_\ \
\ \ _____/ ______ ___ ___ ___
\ \ \___/ /\ \ \ \\ \\ \
\ \____\ \ \_____\ \__\\__\\__\
\/____/ \/_____/ . PYPE Club .
"@
Write-Host $art -ForegroundColor DarkGreen
function Exit-WithCode($exitcode) {
# Only exit this host process if it's a child of another PowerShell parent process...
$parentPID = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId=$PID" | Select-Object -Property ParentProcessId).ParentProcessId
$parentProcName = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId=$parentPID" | Select-Object -Property Name).Name
if ('powershell.exe' -eq $parentProcName) { $host.SetShouldExit($exitcode) }
exit $exitcode
}
function Find-Mongo {
Write-Host ">>> " -NoNewLine -ForegroundColor Green
Write-Host "Detecting MongoDB ... " -NoNewline
if (-not (Get-Command "mongod" -ErrorAction SilentlyContinue)) {
if(Test-Path 'C:\Program Files\MongoDB\Server\*\bin\mongod.exe' -PathType Leaf) {
# we have mongo server installed on standard Windows location
# so we can inject it to the PATH. We'll use latest version available.
$mongoVersions = Get-ChildItem -Directory 'C:\Program Files\MongoDB\Server' | Sort-Object -Property {$_.Name -as [int]}
if(Test-Path "C:\Program Files\MongoDB\Server\$($mongoVersions[-1])\bin\mongod.exe" -PathType Leaf) {
$env:PATH="$($env:PATH);C:\Program Files\MongoDB\Server\$($mongoVersions[-1])\bin\"
Write-Host "OK" -ForegroundColor Green
Write-Host " - auto-added from [ " -NoNewline
Write-Host "C:\Program Files\MongoDB\Server\$($mongoVersions[-1])\bin\" -NoNewLine -ForegroundColor Cyan
Write-Host " ]"
} else {
Write-Host "FAILED " -NoNewLine -ForegroundColor Red
Write-Host "MongoDB not detected" -ForegroundColor Yellow
Write-Host "Tried to find it on standard location [ " -NoNewline -ForegroundColor Gray
Write-Host "C:\Program Files\MongoDB\Server\$($mongoVersions[-1])\bin\" -NoNewline -ForegroundColor White
Write-Host " ] but failed." -ForegroundColor Gray
Exit-WithCode 1
}
} else {
Write-Host "FAILED " -NoNewLine -ForegroundColor Red
Write-Host "MongoDB not detected in PATH" -ForegroundColor Yellow
Exit-WithCode 1
}
} else {
Write-Host "OK" -ForegroundColor Green
}
<#
.SYNOPSIS
Function to detect mongod in path.
.DESCRIPTION
This will test presence of mongod in PATH. If it's not there, it will try
to find it in default install location. It support different mongo versions
(using latest if found). When mongod is found, path to it is added to PATH
#>
}
$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$pype_root = (Get-Item $script_dir).parent.FullName
& "$($pype_root)\venv\Scripts\Activate.ps1"
# mongodb port
$port = 2707
python "$($pype_root)\start.py" mongodb
deactivate
# path to database
$dbpath = (Get-Item $pype_root).parent.FullName + "\mongo_db_data"
Find-Mongo
$mongo = Get-Command "mongod" | Select-Object -ExpandProperty Definition
Start-Process -FilePath $mongo "--dbpath $($dbpath) --port $($port)"

View file

@ -1,3 +1,16 @@
<#
.SYNOPSIS
Helper script to Pype Settings UI
.DESCRIPTION
This script will run Pype and open Settings UI.
.EXAMPLE
PS> .\run_settings.ps1
#>
$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$pype_root = (Get-Item $script_dir).parent.FullName

View file

@ -1,3 +1,18 @@
<#
.SYNOPSIS
Helper script to build Pype.
.DESCRIPTION
This script will detect Python installation, create venv and install
all necessary packages from `requirements.txt` needed by Pype to be
included during application freeze on Windows.
.EXAMPLE
PS> .\run_test.ps1
#>
function Exit-WithCode($exitcode) {
# Only exit this host process if it's a child of another PowerShell parent process...
$parentPID = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId=$PID" | Select-Object -Property ParentProcessId).ParentProcessId

View file

@ -1,3 +1,15 @@
<#
.SYNOPSIS
Helper script Pype Tray.
.DESCRIPTION
.EXAMPLE
PS> .\run_tray.ps1
#>
$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$pype_root = (Get-Item $script_dir).parent.FullName