Merge pull request #1349 from pypeclub/fix/igniter-reverse-filter-for-openpype-version

This commit is contained in:
Milan Kolar 2021-05-03 16:03:01 +02:00 committed by GitHub
commit 66024d44b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 100 additions and 85 deletions

View file

@ -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,7 @@ class BootstrapRepos:
self.registry = OpenPypeSettingsRegistry()
self.zip_filter = [".pyc", "__pycache__"]
self.openpype_filter = [
"build", "docs", "tests", "tools", "venv", "coverage"
"openpype", "repos", "schema", "LICENSE"
]
self._message = message
@ -423,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)
@ -477,11 +472,16 @@ 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_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)
@ -506,7 +506,7 @@ class BootstrapRepos:
except ValueError:
pass
if is_inside:
if not is_inside:
continue
processed_path = file
@ -575,7 +575,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")
@ -681,7 +681,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
@ -808,7 +808,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:

View file

@ -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,

View file

@ -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}")

View file

@ -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
$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

66
tools/create_zip.py Normal file
View file

@ -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()

View file

@ -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 "$@"