diff --git a/README.md b/README.md index 4ad52c7e36..d206a2b73b 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,106 @@ -# Pype -## Introduction +Pype +==== -Multi-platform open-source pipeline built around the [Avalon](https://getavalon.github.io/) platform, expanding it with extra features and integrations. Pype connects asset database, project management and time tracking into a single modular system. It has tight integration with [ftrack](https://www.ftrack.com/en/), but it can also run independently. +Introduction +------------ + +Multi-platform open-source pipeline built around the [Avalon](https://getavalon.github.io/) platform, +expanding it with extra features and integrations. Pype connects asset database, project management +and time tracking into a single modular system. It has tight integration +with [ftrack](https://www.ftrack.com/en/), but it can also run independently. To get all the key information about the project, go to [PYPE.club](http://pype.club) -## Hardware requirements +Requirements +------------ +Pype will run on most typical hardware configurations commonly found in studios around the world. +It is installed on artist computer and can take up 3Gb of space depending on number of versions +and other dependencies. -Pype should be installed centrally on a fast network storage with at least read access right for all workstations and users in the Studio. Full Deplyoyment with all dependencies and both Development and Production branches installed takes about 1GB of data, however to ensure smooth updates and general working comfort, we recommend allocating at least at least 4GB of storage dedicated to PYPE deployment. +For well functioning [ftrack](https://www.ftrack.com/en/) event server, we recommend a +linux virtual server with [Ubuntu](https://ubuntu.com/) or [CentosOS](https://www.centos.org/). +CPU and RAM allocation need differ based on the studio size, but a 2GB of RAM, with a +dual core CPU and around 4GB of storage should suffice. -For well functioning [ftrack](https://www.ftrack.com/en/) event server, we recommend a linux virtual server with [Ubuntu](https://ubuntu.com/) or [CentosOS](https://www.centos.org/). CPU and RAM allocation need differ based on the studio size, but a 2GB of RAM, with a dual core CPU and around 4GB of storage should suffice. +Pype needs running [mongodb](https://www.mongodb.com/) server with good connectivity as it is +heavily used by Pype. Depending on project size and number of artists working connection speed and +latency influence performance experienced by artists. If remote working is required, this mongodb +server must be accessible from Internet or cloud solution can be used. Reasonable backup plan +or high availability options are recommended. -## Building Pype +Building Pype +------------- ### Windows You will need [Python 3.7 and newer](https://www.python.org/downloads/) and [git](https://git-scm.com/downloads). +More tools might be needed for installing dependencies (for example for **OpenTimelineIO**) - mostly +development tools like [CMake](https://cmake.org/) and [Visual Studio](https://visualstudio.microsoft.com/cs/downloads/) Clone repository: ```sh git clone --recurse-submodules git@github.com:pypeclub/pype.git ``` -Run PowerShell script `build.ps1`. It will create *venv*, install all -required dependencies and build Pype. After it is finished, you will find -Pype in `build` folder. +#### To build Pype: -You might need more tools for installing dependencies (for example for **OpenTimelineIO**) - mostly -development tools like [CMake](https://cmake.org/) and [Visual Studio](https://visualstudio.microsoft.com/cs/downloads/) +1) Run `.\tools\create_env.ps1` to create virtual environment in `.\venv` +2) Run `.\tools\build.ps1` to build pype executables in `.\build\` + +To create distributable Pype versions, run `./tools/create_zip.ps1` - that will +create zip file with name `pype-vx.x.x.zip` parsed from current pype repository and +copy it to user data dir, or you can specify `--path /path/to/zip` to force it there. + +You can then point **Igniter** - Pype setup tool - to directory containing this zip and +it will install it on current computer. Pype is build using [CX_Freeze](https://cx-freeze.readthedocs.io/en/latest) to freeze itself and all dependencies. + +Running Pype +------------ + +Pype can by executed either from live sources (this repository) or from +*"frozen code"* - executables that can be build using steps described above. + +If Pype is executed from live sources, it will use Pype version included in them. If +it is executed from frozen code it will try to find latest Pype version installed locally +on current computer and if it is not found, it will ask for its location. On that location +pype can be either in directories or zip files. Pype will try to find latest version and +install it to user data directory (on Windows to `%LOCALAPPDATA%\pypeclub\pype`). + +### From sources +Pype can be run directly from sources by activating virtual environment: +```powershell +.\venv\Scripts\Activate.ps1 +``` +and running: +```powershell +python start.py tray +``` +This will use current Pype version with sources. You can override this with `--use-version=x.x.x` and +then Pype will try to find locally installed specified version (present in user data directory). + +### From frozen code + +You need to build Pype first. This will produce two executables - `pype.exe` and `pype_console.exe`. +First one will act as GUI application and will not create console (useful in production environments). +The second one will create console and will write output there - useful for headless application and +debugging purposes. If you need pype version installed, just run `./tools/create_zip.ps1` without +arguments and it will create zip file that pype can use. + + +Building documentation +---------------------- + +Top build API documentation, run `.\tools\make_docs.ps1`. It will create html documentation +from current sources in `.\docs\build`. + +**Note that it needs existing virtual environment.** + +Running tests +------------- + +To run tests, execute `.\tools\run_tests.ps1`. + +**Note that it needs existing virtual environment.** \ No newline at end of file diff --git a/igniter/bootstrap_repos.py b/igniter/bootstrap_repos.py index 04d119bf1f..ba4a21d5d7 100644 --- a/igniter/bootstrap_repos.py +++ b/igniter/bootstrap_repos.py @@ -743,3 +743,29 @@ class BootstrapRepos: def _print(self, message, error=False): if self._message: self._message.emit(message, error) + + def extract_pype(self, version: PypeVersion): + if not version.path: + raise ValueError( + f"version {version} is not associated with any file") + + destination = self.data_dir / version.path.stem + if destination.exists(): + try: + destination.unlink() + except OSError as e: + msg = f"!!! Cannot remove already existing {destination}" + self._log.error(msg) + self._log.error(e.strerror) + self._print(msg, True) + self._print(e.strerror, True) + return + + destination.mkdir(parents=True) + + # extract zip there + self._print("Extracting zip to destination ...") + with ZipFile(version.path, "r") as zip_ref: + zip_ref.extractall(destination) + + self._print(f"Installed as {version.path.stem}") diff --git a/igniter/install_dialog.py b/igniter/install_dialog.py index 404f1b2320..74d9435815 100644 --- a/igniter/install_dialog.py +++ b/igniter/install_dialog.py @@ -19,7 +19,7 @@ class InstallDialog(QtWidgets.QDialog): def __init__(self, parent=None): super(InstallDialog, self).__init__(parent) - self._mongo_url = "" + self._mongo_url = os.getenv("PYPE_MONGO", "") self.setWindowTitle("Pype - Configure Pype repository path") self._icon_path = os.path.join( @@ -154,6 +154,9 @@ class InstallDialog(QtWidgets.QDialog): def get_mongo_url(self): return self.parent().mongo_url + def set_mongo_url(self, mongo: str): + self._mongo_input.setText(mongo) + def set_valid(self): self._mongo_input.setStyleSheet( """ @@ -175,6 +178,8 @@ class InstallDialog(QtWidgets.QDialog): ) self._mongo = MongoWidget(self) + if self._mongo_url: + self._mongo.set_mongo_url(self._mongo_url) # Bottom button bar # -------------------------------------------------------------------- diff --git a/igniter/install_thread.py b/igniter/install_thread.py index bb4ab1c9dd..37232bb88e 100644 --- a/igniter/install_thread.py +++ b/igniter/install_thread.py @@ -74,7 +74,7 @@ class InstallThread(QThread): self.message.emit( f"Detecting installed Pype versions in {bs.data_dir}", False) - detected = bs.find_pype() + detected = bs.find_pype(include_zips=True) if detected: if PypeVersion(version=local_version) < detected[-1]: @@ -83,6 +83,8 @@ class InstallThread(QThread): f"then currently running {local_version}" ), False) self.message.emit("Skipping Pype install ...", False) + if detected[-1].path.suffix.lower() == ".zip": + bs.extract_pype(detected[-1]) return if PypeVersion(version=local_version) == detected[-1]: @@ -91,6 +93,8 @@ class InstallThread(QThread): f"currently running {local_version}" ), False) self.message.emit("Skipping Pype install ...", False) + if detected[-1].path.suffix.lower() == ".zip": + bs.extract_pype(detected[-1]) return self.message.emit(( diff --git a/pype/cli.py b/pype/cli.py index 9d66ff988a..93858f15d0 100644 --- a/pype/cli.py +++ b/pype/cli.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- """Package for handling pype command line arguments.""" import os + +import click + # import sys from .pype_commands import PypeCommands -import click @click.group(invoke_without_command=True) @@ -258,3 +260,14 @@ def launch(app, project, asset, task, def validate_config(): """Validate all json configuration files for errors.""" PypeCommands().validate_jsons() + + +@main.command() +@click.option("-p", "--path", help="Path to zip file", default=None) +def generate_zip(path): + """Generate Pype zip from current sources. + + If PATH is not provided, it will create zip file in user data dir. + + """ + PypeCommands().generate_zip(path) diff --git a/pype/pype_commands.py b/pype/pype_commands.py index 36e5ac639f..7c2f83a562 100644 --- a/pype/pype_commands.py +++ b/pype/pype_commands.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- """Implementation of Pype commands.""" import os -import subprocess import sys +from pathlib import Path + from pype.lib import PypeLogger @@ -61,3 +62,30 @@ class PypeCommands: def validate_jsons(self): pass + + @staticmethod + def generate_zip(out_path: str): + """Generate zip file from current sources. + + Args: + out_path (str): Path to generated zip file. + + """ + from igniter import bootstrap_repos + + # create zip file + + + bs = bootstrap_repos.BootstrapRepos() + if out_path: + out_path = Path(out_path) + bs.data_dir = out_path.parent + + print(f">>> Creating zip in {bs.data_dir} ...") + repo_file = bs.install_live_repos() + if not repo_file: + print("!!! Error while creating zip file.") + exit(1) + + print(f">>> Created {repo_file}") + diff --git a/requirements.txt b/requirements.txt index 5164159842..8320b586c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ git+https://github.com/pypeclub/acre.git -aiohttp aiohttp_json_rpc appdirs arrow diff --git a/tests/igniter/test_bootstrap_repos.py b/tests/igniter/test_bootstrap_repos.py index db6890f13b..c0ce1be012 100644 --- a/tests/igniter/test_bootstrap_repos.py +++ b/tests/igniter/test_bootstrap_repos.py @@ -138,11 +138,9 @@ def test_install_live_repos(fix_bootstrap, printer): rf = fix_bootstrap.install_live_repos() sep = os.path.sep expected_paths = [ - f"{rf}{sep}acre", f"{rf}{sep}avalon-core", f"{rf}{sep}avalon-unreal-integration", f"{rf}{sep}maya-look-assigner", - f"{rf}{sep}pyblish-base", f"{rf}{sep}pype" ] printer("testing zip creation") diff --git a/tools/build.ps1 b/tools/build.ps1 index 146fe9a904..a233281585 100644 --- a/tools/build.ps1 +++ b/tools/build.ps1 @@ -13,6 +13,38 @@ PS> .\build.ps1 #> +function Start-Progress { + param([ScriptBlock]$code) + $scroll = "/-\|/-\|" + $idx = 0 + $job = Invoke-Command -ComputerName $env:ComputerName -ScriptBlock { $code } -AsJob + + $origpos = $host.UI.RawUI.CursorPosition + + # $origpos.Y -= 1 + + while (($job.State -eq "Running") -and ($job.State -ne "NotStarted")) + { + $host.UI.RawUI.CursorPosition = $origpos + Write-Host $scroll[$idx] -NoNewline + $idx++ + if ($idx -ge $scroll.Length) + { + $idx = 0 + } + Start-Sleep -Milliseconds 100 + } + # It's over - clear the activity indicator. + $host.UI.RawUI.CursorPosition = $origpos + Write-Host ' ' + <# + .SYNOPSIS + Display spinner for running job + .PARAMETER code + Job to display spinner for + #> +} + function Exit-WithCode($exitcode) { # Only exit this host process if it's a child of another PowerShell parent process... @@ -23,7 +55,17 @@ function Exit-WithCode($exitcode) { exit $exitcode } -$art = @' +function Show-PSWarning() { + if ($PSVersionTable.PSVersion.Major -lt 7) { + Write-Host "!!! " -NoNewline -ForegroundColor Red + Write-Host "You are using old version of PowerShell. $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)" + Write-Host "Please update to at least 7.0 - " -NoNewline -ForegroundColor Gray + Write-Host "https://github.com/PowerShell/PowerShell/releases" -ForegroundColor White + Exit-WithCode 1 + } +} + +$art = @" ____________ @@ -34,10 +76,13 @@ $art = @' \ \____\ \ \_____\ \__\\__\\__\ \/____/ \/_____/ . PYPE Club . -'@ +"@ Write-Host $art -ForegroundColor DarkGreen +# Enable if PS 7.x is needed. +# Show-PSWarning + $current_dir = Get-Location $script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent $pype_root = (Get-Item $script_dir).parent.FullName @@ -68,10 +113,10 @@ if (-not (Get-Command "python" -ErrorAction SilentlyContinue)) { Write-Host "!!! Python not detected" -ForegroundColor red Exit-WithCode 1 } -$version_command = @' +$version_command = @" import sys print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1])) -'@ +"@ $p = & python -c $version_command $env:PYTHON_VERSION = $p @@ -86,9 +131,7 @@ if(($matches[1] -lt 3) -or ($matches[2] -lt 7)) { Exit-WithCode 1 } Write-Host "OK [ $p ]" -ForegroundColor green -Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Creating virtual env ..." -& python -m venv "$($pype_root)\venv" + Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Entering venv ..." try { @@ -96,13 +139,18 @@ try { } catch { Write-Host "!!! Failed to activate" -ForegroundColor red - Write-Host $_.Exception.Message - Exit-WithCode 1 + Write-Host ">>> " -NoNewline -ForegroundColor green + Write-Host "Trying to create env ..." + & "$($script_dir)\create_env.ps1" + try { + . ("$($pype_root)\venv\Scripts\Activate.ps1") + } + catch { + Write-Host "!!! Failed to activate" -ForegroundColor red + Write-Host $_.Exception.Message + Exit-WithCode 1 + } } -Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Installing packages to new venv ..." -& python -m pip install -U pip -& pip install -r ("$($pype_root)\requirements.txt") Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Cleaning cache files ... " -NoNewline @@ -112,7 +160,19 @@ Write-Host "OK" -ForegroundColor green Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Building Pype ..." -Set-Location -Path $pype_root -& python setup.py build +$out = & python setup.py build 2>&1 + +Set-Content -Path "$($pype_root)\build\build.log" -Value $out + +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "deactivating venv ..." deactivate + +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "restoring current directory" Set-Location -Path $current_dir + +Write-Host "*** " -NoNewline -ForegroundColor Cyan +Write-Host "All done. You will find Pype and build log in " -NoNewLine +Write-Host "'.\build'" -NoNewline -ForegroundColor Green +Write-Host " directory." diff --git a/tools/create_env.ps1 b/tools/create_env.ps1 index c5afbe12b2..7354ee72ed 100644 --- a/tools/create_env.ps1 +++ b/tools/create_env.ps1 @@ -21,22 +21,21 @@ function Exit-WithCode($exitcode) { exit $exitcode } + + +function Show-PSWarning() { + if ($PSVersionTable.PSVersion.Major -lt 7) { + Write-Host "!!! " -NoNewline -ForegroundColor Red + Write-Host "You are using old version of PowerShell. $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)" + Write-Host "Please update to at least 7.0 - " -NoNewline -ForegroundColor Gray + Write-Host "https://github.com/PowerShell/PowerShell/releases" -ForegroundColor White + Exit-WithCode 1 + } +} $current_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent $pype_root = (Get-Item $current_dir).parent.FullName -if ($PSVersionTable.PSVersion.Major -lt 7) { - Write-Host "!!! " -NoNewline -ForegroundColor Red - Write-Host "You are using old version of PowerShell. $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)" - Write-Host "Please update to at least 7.0 - https://github.com/PowerShell/PowerShell/releases" - Exit-WithCode 1 -} - -$arguments=$ARGS -if($arguments -eq "--skip-venv") { - $skip_venv=$true -} - -$art = @' +$art = @" ____________ @@ -47,10 +46,13 @@ $art = @' \ \____\ \ \_____\ \__\\__\\__\ \/____/ \/_____/ . PYPE Club . -'@ +"@ Write-Host $art -ForegroundColor DarkGreen +# Enable if PS 7.x is needed. +# Show-PSWarning + $version_file = Get-Content -Path "$($pype_root)\pype\version.py" $result = [regex]::Matches($version_file, '__version__ = "(?\d+\.\d+.\d+)"') $pype_version = $result[0].Groups['version'].Value @@ -85,42 +87,30 @@ if(($matches[1] -lt 3) -or ($matches[2] -lt 7)) { } Write-Host "OK [ $p ]" -ForegroundColor green +Write-Host "--- " -NoNewline -ForegroundColor yellow +Write-Host "Cleaning venv directory ..." +Remove-Item -Recurse -Force "$($pype_root)\venv\*" -if ($skip_venv -ne $true) { - Write-Host ">>> " -NoNewline -ForegroundColor green - Write-Host "Creating virtual env ..." - & python -m venv venv - Write-Host ">>> " -NoNewline -ForegroundColor green - Write-Host "Entering venv ..." - try { - . (".\venv\Scripts\Activate.ps1") - } - catch { - Write-Host "!!! Failed to activate" -ForegroundColor red - Write-Host $_.Exception.Message - Exit-WithCode 1 - } - Write-Host ">>> " -NoNewline -ForegroundColor green - Write-Host "Updating pip ..." - & python -m pip install --upgrade pip - - Write-Host ">>> " -NoNewline -ForegroundColor green - Write-Host "Installing packages to new venv ..." - & pip install -r .\requirements.txt -} else { - Write-Host "*** " -NoNewline -ForegroundColor yellow - Write-Host "Skipping creaton of venv ..." - Write-Host ">>> " -NoNewline -ForegroundColor green - Write-Host "Entering venv ..." - try { - . (".\venv\Scripts\Activate.ps1") - } - catch { - Write-Host "!!! Failed to activate" -ForegroundColor red - Write-Host $_.Exception.Message - Exit-WithCode 1 - } +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Creating virtual env ..." +& python -m venv venv +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Entering venv ..." +try { + . (".\venv\Scripts\Activate.ps1") } +catch { + Write-Host "!!! Failed to activate" -ForegroundColor red + Write-Host $_.Exception.Message + Exit-WithCode 1 +} +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Updating pip ..." +& python -m pip install --upgrade pip + +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Installing packages to new venv ..." +& pip install -r "$($pype_root)\requirements.txt" Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Cleaning cache files ... " -NoNewline @@ -128,21 +118,6 @@ Get-ChildItem "$($pype_root)" -Filter "*.pyc" -Force -Recurse | Remove-Item -For Get-ChildItem "$($pype_root)" -Filter "__pycache__" -Force -Recurse | Remove-Item -Force -Recurse Write-Host "OK" -ForegroundColor green -# store original PYTHONPATH Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Storing original PYTHONPATH ... " -NoNewline -$original_pythonpath = $env:PYTHONPATH -Write-Host "OK" -ForegroundColor green -$new_pythonpath = Get-ChildItem -Directory -Path .\ | Microsoft.PowerShell.Utility\Join-String -Property FullName -DoubleQuote -Separator ';' -$env:PYTHONPATH = $env:PYTHONPATH + ";" + $new_pythonpath -Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Adding repos to PYTHONPATH ..." - -Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Building Pype ..." -& python setup.py build -Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Restoring original PYTHONPATH ... " -NoNewline -$env:PYTHONPATH = $original_pythonpath -Write-Host "OK" -ForegroundColor green +Write-Host "Deactivating venv ..." deactivate diff --git a/tools/create_zip.ps1 b/tools/create_zip.ps1 new file mode 100644 index 0000000000..b2d0319534 --- /dev/null +++ b/tools/create_zip.ps1 @@ -0,0 +1,106 @@ +<# +.SYNOPSIS + Helper script create virtual env. + +.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> .\build.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 + $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 Show-PSWarning() { + if ($PSVersionTable.PSVersion.Major -lt 7) { + Write-Host "!!! " -NoNewline -ForegroundColor Red + Write-Host "You are using old version of PowerShell. $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)" + Write-Host "Please update to at least 7.0 - " -NoNewline -ForegroundColor Gray + Write-Host "https://github.com/PowerShell/PowerShell/releases" -ForegroundColor White + Exit-WithCode 1 + } +} +$current_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent +$pype_root = (Get-Item $current_dir).parent.FullName + +$art = @" + + + ____________ + /\ ___ \ + \ \ \/_\ \ + \ \ _____/ ______ ___ ___ ___ + \ \ \___/ /\ \ \ \\ \\ \ + \ \____\ \ \_____\ \__\\__\\__\ + \/____/ \/_____/ . PYPE Club . + +"@ + +Write-Host $art -ForegroundColor DarkGreen + +# Enable if PS 7.x is needed. +# Show-PSWarning + +$version_file = Get-Content -Path "$($pype_root)\pype\version.py" +$result = [regex]::Matches($version_file, '__version__ = "(?\d+\.\d+.\d+)"') +$pype_version = $result[0].Groups['version'].Value +if (-not $pype_version) { + Write-Host "!!! " -ForegroundColor yellow -NoNewline + Write-Host "Cannot determine Pype version." + Exit-WithCode 1 +} + +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Detecting host Python ... " -NoNewline +if (-not (Get-Command "python" -ErrorAction SilentlyContinue)) { + Write-Host "!!! Python not detected" -ForegroundColor red + Exit-WithCode 1 +} +$version_command = @' +import sys +print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1])) +'@ + +$p = & python -c $version_command +$env:PYTHON_VERSION = $p +$m = $p -match '(\d+)\.(\d+)' +if(-not $m) { + Write-Host "!!! Cannot determine version" -ForegroundColor red + Exit-WithCode 1 +} +# We are supporting python 3.6 and up +if(($matches[1] -lt 3) -or ($matches[2] -lt 7)) { + Write-Host "FAILED Version [ $p ] is old and unsupported" -ForegroundColor red + Exit-WithCode 1 +} +Write-Host "OK [ $p ]" -ForegroundColor green + +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Entering venv ..." +try { + . (".\venv\Scripts\Activate.ps1") +} +catch { + Write-Host "!!! Failed to activate" -ForegroundColor red + Write-Host $_.Exception.Message + Exit-WithCode 1 +} +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Generating zip from current sources ..." +& python "$($pype_root)\start.py" generate-zip $ARGS + +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Deactivating venv ..." +deactivate diff --git a/tools/make_docs.ps1 b/tools/make_docs.ps1 index 30032d41a6..951cab4c8e 100644 --- a/tools/make_docs.ps1 +++ b/tools/make_docs.ps1 @@ -17,7 +17,7 @@ $current_dir = Get-Location $script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent $pype_root = (Get-Item $script_dir).parent.FullName -$art = @' +$art = @" ____________ @@ -28,7 +28,7 @@ $art = @' \ \____\ \ \_____\ \__\\__\\__\ \/____/ \/_____/ . PYPE Club . -'@ +"@ Write-Host $art -ForegroundColor DarkGreen diff --git a/tools/run_mongo.ps1 b/tools/run_mongo.ps1 index 6cc5674a8e..45d4679940 100644 --- a/tools/run_mongo.ps1 +++ b/tools/run_mongo.ps1 @@ -3,4 +3,5 @@ $pype_root = (Get-Item $script_dir).parent.FullName & "$($pype_root)\venv\Scripts\Activate.ps1" -python "$($pype_root)\pype.py" mongodb +python "$($pype_root)\start.py" mongodb +deactivate diff --git a/tools/run_settings.ps1 b/tools/run_settings.ps1 index fde2087da7..64d35a4b81 100644 --- a/tools/run_settings.ps1 +++ b/tools/run_settings.ps1 @@ -3,4 +3,5 @@ $pype_root = (Get-Item $script_dir).parent.FullName & "$($pype_root)\venv\Scripts\Activate.ps1" -python "$($pype_root)\pype.py" settings --dev +python "$($pype_root)\start.py" settings --dev +deactivate \ No newline at end of file diff --git a/tools/run_tests.bat b/tools/run_tests.bat deleted file mode 100644 index 48ccf9e7cc..0000000000 --- a/tools/run_tests.bat +++ /dev/null @@ -1,2 +0,0 @@ -set PYTHONPATH=".;%PYTHONPATH%" -pytest -x --capture=sys --print -W ignore::DeprecationWarning ./tests diff --git a/build.ps1 b/tools/run_tests.ps1 similarity index 51% rename from build.ps1 rename to tools/run_tests.ps1 index 782b3c8f20..498a3c3d7d 100644 --- a/build.ps1 +++ b/tools/run_tests.ps1 @@ -1,18 +1,3 @@ -<# -.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> .\build.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 @@ -22,19 +7,16 @@ function Exit-WithCode($exitcode) { exit $exitcode } -if ($PSVersionTable.PSVersion.Major -lt 7) { - Write-Host "!!! " -NoNewline -ForegroundColor Red - Write-Host "You are using old version of PowerShell. $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)" - Write-Host "Please update to at least 7.0 - https://github.com/PowerShell/PowerShell/releases" - Exit-WithCode 1 +function Show-PSWarning() { + if ($PSVersionTable.PSVersion.Major -lt 7) { + Write-Host "!!! " -NoNewline -ForegroundColor Red + Write-Host "You are using old version of PowerShell. $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)" + Write-Host "Please update to at least 7.0 - " -NoNewline -ForegroundColor Gray + Write-Host "https://github.com/PowerShell/PowerShell/releases" -ForegroundColor White + Exit-WithCode 1 + } } - -$arguments=$ARGS -if($arguments -eq "--skip-venv") { - $skip_venv=$true -} - -$art = @' +$art = @" ____________ @@ -45,11 +27,20 @@ $art = @' \ \____\ \ \_____\ \__\\__\\__\ \/____/ \/_____/ . PYPE Club . -'@ +"@ Write-Host $art -ForegroundColor DarkGreen -$version_file = Get-Content -Path ".\pype\version.py" +# Enable if PS 7.x is needed. +# Show-PSWarning + +$current_dir = Get-Location +$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent +$pype_root = (Get-Item $script_dir).parent.FullName + +Set-Location -Path $pype_root + +$version_file = Get-Content -Path "$($pype_root)\pype\version.py" $result = [regex]::Matches($version_file, '__version__ = "(?\d+\.\d+.\d+)"') $pype_version = $result[0].Groups['version'].Value if (-not $pype_version) { @@ -61,7 +52,7 @@ if (-not $pype_version) { Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Building Pype [ " -NoNewline -ForegroundColor white Write-host $pype_version -NoNewline -ForegroundColor green -Write-Host " ]..." -ForegroundColor white +Write-Host " ] ..." -ForegroundColor white Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Detecting host Python ... " -NoNewline @@ -69,10 +60,10 @@ if (-not (Get-Command "python" -ErrorAction SilentlyContinue)) { Write-Host "!!! Python not detected" -ForegroundColor red Exit-WithCode 1 } -$version_command = @' +$version_command = @" import sys print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1])) -'@ +"@ $p = & python -c $version_command $env:PYTHON_VERSION = $p @@ -88,64 +79,48 @@ if(($matches[1] -lt 3) -or ($matches[2] -lt 7)) { } Write-Host "OK [ $p ]" -ForegroundColor green - -if ($skip_venv -ne $true) { - Write-Host ">>> " -NoNewline -ForegroundColor green - Write-Host "Creating virtual env ..." - & python -m venv venv - Write-Host ">>> " -NoNewline -ForegroundColor green - Write-Host "Entering venv ..." - try { - . (".\venv\Scripts\Activate.ps1") - } - catch { +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Entering venv ..." +try { + . ("$($pype_root)\venv\Scripts\Activate.ps1") +} +catch { + Write-Host "!!! Failed to activate" -ForegroundColor red + Write-Host ">>> " -NoNewline -ForegroundColor green + Write-Host "Trying to create env ..." + & "$($script_dir)\create_env.ps1" + try { + . ("$($pype_root)\venv\Scripts\Activate.ps1") + } + catch { Write-Host "!!! Failed to activate" -ForegroundColor red Write-Host $_.Exception.Message Exit-WithCode 1 - } - Write-Host ">>> " -NoNewline -ForegroundColor green - Write-Host "Updating pip ..." - & python -m pip install --upgrade pip - - Write-Host ">>> " -NoNewline -ForegroundColor green - Write-Host "Installing packages to new venv ..." - & pip install -r .\requirements.txt -} else { - Write-Host "*** " -NoNewline -ForegroundColor yellow - Write-Host "Skipping creaton of venv ..." - Write-Host ">>> " -NoNewline -ForegroundColor green - Write-Host "Entering venv ..." - try { - . (".\venv\Scripts\Activate.ps1") - } - catch { - Write-Host "!!! Failed to activate" -ForegroundColor red - Write-Host $_.Exception.Message - Exit-WithCode 1 - } + } } Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Cleaning cache files ... " -NoNewline -Get-ChildItem . -Filter "*.pyc" -Force -Recurse | Remove-Item -Force -Get-ChildItem . -Filter "__pycache__" -Force -Recurse | Remove-Item -Force -Recurse +Get-ChildItem $pype_root -Filter "*.pyc" -Force -Recurse | Remove-Item -Force +Get-ChildItem $pype_root -Filter "__pycache__" -Force -Recurse | Remove-Item -Force -Recurse Write-Host "OK" -ForegroundColor green -# store original PYTHONPATH Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Storing original PYTHONPATH ... " -NoNewline +Write-Host "Testing Pype ..." $original_pythonpath = $env:PYTHONPATH -Write-Host "OK" -ForegroundColor green -$new_pythonpath = Get-ChildItem -Directory -Path .\ | Microsoft.PowerShell.Utility\Join-String -Property FullName -DoubleQuote -Separator ';' -$env:PYTHONPATH = $env:PYTHONPATH + ";" + $new_pythonpath +$env:PYTHONPATH="$($pype_root);$($env:PYTHONPATH)" +pytest -x --capture=sys --print -W ignore::DeprecationWarning "$($pype_root)/tests" +$env:PYTHONPATH = $original_pythonpath Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Adding repos to PYTHONPATH ..." +Write-Host "deactivating venv ..." +deactivate Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Building Pype ..." -& python setup.py build -Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Restoring original PYTHONPATH ... " -NoNewline -$env:PYTHONPATH = $original_pythonpath -Write-Host "OK" -ForegroundColor green -deactivate +Write-Host "restoring current directory" +Set-Location -Path $current_dir + + + + + + diff --git a/tools/run_tray.ps1 b/tools/run_tray.ps1 index 41ada4219e..f794f85929 100644 --- a/tools/run_tray.ps1 +++ b/tools/run_tray.ps1 @@ -3,4 +3,5 @@ $pype_root = (Get-Item $script_dir).parent.FullName & "$($pype_root)\venv\Scripts\Activate.ps1" -python "$($pype_root)\pype.py" tray --debug +python "$($pype_root)\start.py" tray --debug +deactivate