From 23072b4ea267387c70254ac95c6600051471c9a0 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Wed, 14 Apr 2021 21:23:02 +0200 Subject: [PATCH 1/3] reverse item filter --- igniter/bootstrap_repos.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/igniter/bootstrap_repos.py b/igniter/bootstrap_repos.py index f624b96125..c03b30d59a 100644 --- a/igniter/bootstrap_repos.py +++ b/igniter/bootstrap_repos.py @@ -223,7 +223,7 @@ class BootstrapRepos: otherwise `None`. registry (OpenPypeSettingsRegistry): OpenPype registry object. zip_filter (list): List of files to exclude from zip - openpype_filter (list): list of top level directories not to + openpype_filter (list): list of top level directories to include in zip in OpenPype repository. """ @@ -246,7 +246,8 @@ class BootstrapRepos: self.registry = OpenPypeSettingsRegistry() self.zip_filter = [".pyc", "__pycache__"] self.openpype_filter = [ - "build", "docs", "tests", "tools", "venv", "coverage" + "igniter", "openpype", "repos", "schema", "LICENSE", + "CHANGELOG.md" ] self._message = message @@ -506,7 +507,7 @@ class BootstrapRepos: except ValueError: pass - if is_inside: + if not is_inside: continue processed_path = file From 4fe35c671a55ef1b0fef9dd6a4bbb1dace8980c4 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Fri, 30 Apr 2021 18:34:14 +0200 Subject: [PATCH 2/3] more strict filter --- igniter/bootstrap_repos.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/igniter/bootstrap_repos.py b/igniter/bootstrap_repos.py index b4989fb9bf..f4bb4d57d3 100644 --- a/igniter/bootstrap_repos.py +++ b/igniter/bootstrap_repos.py @@ -246,8 +246,7 @@ class BootstrapRepos: self.registry = OpenPypeSettingsRegistry() self.zip_filter = [".pyc", "__pycache__"] self.openpype_filter = [ - "igniter", "openpype", "repos", "schema", "LICENSE", - "CHANGELOG.md" + "openpype", "repos", "schema", "LICENSE" ] self._message = message @@ -424,18 +423,13 @@ class BootstrapRepos: """ frozen_root = Path(sys.executable).parent - # from frozen code we need igniter, openpype, schema vendor - openpype_list = self._filter_dir( - frozen_root / "openpype", self.zip_filter) - openpype_list += self._filter_dir( - frozen_root / "igniter", self.zip_filter) - openpype_list += self._filter_dir( - frozen_root / "repos", self.zip_filter) - openpype_list += self._filter_dir( - frozen_root / "schema", self.zip_filter) - openpype_list += self._filter_dir( - frozen_root / "vendor", self.zip_filter) - openpype_list.append(frozen_root / "LICENSE") + openpype_list = [] + for f in self.openpype_filter: + if (frozen_root / f).is_dir(): + openpype_list += self._filter_dir( + frozen_root / f, self.zip_filter) + else: + openpype_list.append(frozen_root / f) version = self.get_version(frozen_root) @@ -478,9 +472,6 @@ class BootstrapRepos: openpype_path (Path): Path to OpenPype sources. """ - openpype_list = [] - openpype_inc = 0 - # get filtered list of file in Pype repository openpype_list = self._filter_dir(openpype_path, self.zip_filter) openpype_files = len(openpype_list) @@ -576,7 +567,7 @@ class BootstrapRepos: """ sys.path.insert(0, directory.as_posix()) - directory = directory / "repos" + directory /= "repos" if not directory.exists() and not directory.is_dir(): raise ValueError("directory is invalid") @@ -682,7 +673,7 @@ class BootstrapRepos: openpype_path = None # try to get OpenPype path from mongo. if location.startswith("mongodb"): - pype_path = get_openpype_path_from_db(location) + openpype_path = get_openpype_path_from_db(location) if not openpype_path: self._print("cannot find OPENPYPE_PATH in settings.") return None @@ -809,7 +800,7 @@ class BootstrapRepos: """Install OpenPype version to user data directory. Args: - oepnpype_version (OpenPypeVersion): OpenPype version to install. + openpype_version (OpenPypeVersion): OpenPype version to install. force (bool, optional): Force overwrite existing version. Returns: From ee43e3af3426dc46076bdaae6db74269fe0cb974 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Mon, 3 May 2021 12:48:14 +0200 Subject: [PATCH 3/3] generate zip doesn't need to run openpype --- igniter/bootstrap_repos.py | 10 +++++- openpype/cli.py | 11 ------- openpype/pype_commands.py | 23 ------------- tools/create_zip.ps1 | 37 ++++++--------------- tools/create_zip.py | 66 ++++++++++++++++++++++++++++++++++++++ tools/create_zip.sh | 4 ++- 6 files changed, 87 insertions(+), 64 deletions(-) create mode 100644 tools/create_zip.py diff --git a/igniter/bootstrap_repos.py b/igniter/bootstrap_repos.py index f4bb4d57d3..8fbb580e8f 100644 --- a/igniter/bootstrap_repos.py +++ b/igniter/bootstrap_repos.py @@ -473,7 +473,15 @@ class BootstrapRepos: """ # get filtered list of file in Pype repository - openpype_list = self._filter_dir(openpype_path, self.zip_filter) + # openpype_list = self._filter_dir(openpype_path, self.zip_filter) + openpype_list = [] + for f in self.openpype_filter: + if (openpype_path / f).is_dir(): + openpype_list += self._filter_dir( + openpype_path / f, self.zip_filter) + else: + openpype_list.append(openpype_path / f) + openpype_files = len(openpype_list) openpype_inc = 98.0 / float(openpype_files) diff --git a/openpype/cli.py b/openpype/cli.py index c6da88cbc1..9c49825721 100644 --- a/openpype/cli.py +++ b/openpype/cli.py @@ -224,17 +224,6 @@ def launch(app, project, asset, task, PypeCommands().run_application(app, project, asset, task, tools, arguments) -@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) - - @main.command( context_settings=dict( ignore_unknown_options=True, diff --git a/openpype/pype_commands.py b/openpype/pype_commands.py index a2d97429d3..981cca82dc 100644 --- a/openpype/pype_commands.py +++ b/openpype/pype_commands.py @@ -119,26 +119,3 @@ 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.create_version_from_live_code() - if not repo_file: - print("!!! Error while creating zip file.") - exit(1) - - print(f">>> Created {repo_file}") diff --git a/tools/create_zip.ps1 b/tools/create_zip.ps1 index d18806c40b..05db640e5b 100644 --- a/tools/create_zip.ps1 +++ b/tools/create_zip.ps1 @@ -64,34 +64,15 @@ if (-not $openpype_version) { } 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 "Cleaning cache files ... " -NoNewline +Get-ChildItem $openpype_root -Filter "*.pyc" -Force -Recurse | Remove-Item -Force +Get-ChildItem $openpype_root -Filter "*.pyo" -Force -Recurse | Remove-Item -Force +Get-ChildItem $openpype_root -Filter "__pycache__" -Force -Recurse | Remove-Item -Force -Recurse +Write-Host "OK" -ForegroundColor green Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Generating zip from current sources ..." -Write-Host "... " -NoNewline -ForegroundColor Magenta -Write-Host "arguments: " -NoNewline -ForegroundColor Gray -Write-Host $ARGS -ForegroundColor White -& poetry run python "$($openpype_root)\start.py" generate-zip $ARGS -Set-Location -Path $current_dir \ No newline at end of file +$env:PYTHONPATH="$($openpype_root);$($env:PYTHONPATH)" +$env:OPENPYPE_ROOT="$($openpype_root)" +& poetry run python "$($openpype_root)\tools\create_zip.py" $ARGS +Set-Location -Path $current_dir diff --git a/tools/create_zip.py b/tools/create_zip.py new file mode 100644 index 0000000000..32a4d27e8b --- /dev/null +++ b/tools/create_zip.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +"""Create OpenPype version from live sources.""" +from igniter import bootstrap_repos +import click +import enlighten +import blessed +from pathlib2 import Path + + +term = blessed.Terminal() +manager = enlighten.get_manager() +last_increment = 0 + + +@click.group(invoke_without_command=True) +@click.option("--path", required=False, + help="path where to put version", + type=click.Path(exists=True)) +def main(path): + # create zip file + + progress_bar = enlighten.Counter( + total=100, desc="OpenPype ZIP", units="%", color="green") + + def progress(inc: int): + """Progress handler.""" + global last_increment + progress_bar.update(incr=inc - last_increment) + last_increment = inc + + bs = bootstrap_repos.BootstrapRepos(progress_callback=progress) + if path: + out_path = Path(path) + bs.data_dir = out_path.parent + + _print(f"Creating zip in {bs.data_dir} ...") + repo_file = bs.create_version_from_live_code() + if not repo_file: + _print("Error while creating zip file.", 1) + exit(1) + + _print(f"Created {repo_file}") + + +def _print(msg: str, message_type: int = 0) -> None: + """Print message to console. + + Args: + msg (str): message to print + message_type (int): type of message (0 info, 1 error, 2 note) + + """ + if message_type == 0: + header = term.aquamarine3(">>> ") + elif message_type == 1: + header = term.orangered2("!!! ") + elif message_type == 2: + header = term.tan1("... ") + else: + header = term.darkolivegreen3("--- ") + + print("{}{}".format(header, msg)) + + +if __name__ == "__main__": + main() diff --git a/tools/create_zip.sh b/tools/create_zip.sh index 6e7f792f1d..f02eb9987c 100755 --- a/tools/create_zip.sh +++ b/tools/create_zip.sh @@ -123,7 +123,9 @@ main () { pushd "$openpype_root" > /dev/null || return > /dev/null echo -e "${BIGreen}>>>${RST} Generating zip from current sources ..." - poetry run python3 "$openpype_root/start.py" generate-zip "$@" + PYTHONPATH="$openpype_root:$PYTHONPATH" + OPENPYPE_ROOT="$openpype_root" + poetry run python3 "$openpype_root/tools/create_zip.py" "$@" } main "$@"