Skip to content

Commit

Permalink
Merge branch 'ynput:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnaavril authored Aug 6, 2024
2 parents b795e1f + 2f2db43 commit c7c3b06
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 70 deletions.
3 changes: 1 addition & 2 deletions common/ayon_common/connection/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def get_servers_info_data():
servers_info_path = _get_servers_path()
if not os.path.exists(servers_info_path):
dirpath = os.path.dirname(servers_info_path)
if not os.path.exists(dirpath):
os.makedirs(dirpath)
os.makedirs(dirpath, exist_ok=True)

return data

Expand Down
17 changes: 6 additions & 11 deletions common/ayon_common/distribution/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,7 @@ def error_detail(self):
return self._error_detail

def _pre_source_process(self):
download_dirpath = self.download_dirpath
if not os.path.isdir(download_dirpath):
os.makedirs(download_dirpath)
os.makedirs(self.download_dirpath, exist_ok=True)

def _receive_file(self, source_data, source_progress, downloader):
"""Receive source filepath using source data and downloader.
Expand Down Expand Up @@ -679,8 +677,8 @@ def _install_linux(self, filepath):
install_root = os.path.dirname(os.path.dirname(sys.executable))

self.log.info(f"Installing AYON launcher {filepath} into:\n{install_root}")
if not os.path.exists(install_root):
os.makedirs(install_root)

os.makedirs(install_root, exist_ok=True)

try:
extract_archive_file(filepath, install_root)
Expand Down Expand Up @@ -839,7 +837,7 @@ def _pre_source_process(self):
shutil.rmtree(unzip_dirpath)

# Create directory
os.makedirs(unzip_dirpath)
os.makedirs(unzip_dirpath, exist_ok=True)

def _post_source_process(
self, filepath, source_data, source_progress, downloader
Expand Down Expand Up @@ -1731,12 +1729,9 @@ def save_metadata_file(self, filepath, data):
Args:
filepath (str): Path to json file.
data (Union[Dict[str, Any], List[Any]]): Data to store into file.
"""
if not os.path.exists(filepath):
dirpath = os.path.dirname(filepath)
if not os.path.exists(dirpath):
os.makedirs(dirpath)
"""
os.makedirs(os.path.dirname(filepath), exist_ok=True)
with open(filepath, "w") as stream:
json.dump(data, stream, indent=4)

Expand Down
6 changes: 1 addition & 5 deletions common/ayon_common/distribution/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ def get_local_dir(*subdirs):
raise ValueError("Must fill dir_name if nothing else provided!")

local_dir = get_ayon_appdirs(*subdirs)
if not os.path.isdir(local_dir):
try:
os.makedirs(local_dir)
except Exception: # TODO fix exception
raise RuntimeError(f"Cannot create {local_dir}")
os.makedirs(local_dir, exist_ok=True)

return local_dir

Expand Down
10 changes: 3 additions & 7 deletions common/ayon_common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def get_local_site_id():
site_id = stream.read()

if not site_id:
folder_path = os.path.dirname(site_id_path)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
os.makedirs(os.path.dirname(site_id_path), exist_ok=True)
site_id = _create_local_site_id()
with open(site_id_path, "w") as stream:
stream.write(site_id)
Expand Down Expand Up @@ -177,12 +175,10 @@ def store_executables_info(info):
"""Store information about executables.
This will override existing information so use it wisely.
"""
"""
filepath = get_executables_info_filepath()
dirpath = os.path.dirname(filepath)
if not os.path.exists(dirpath):
os.makedirs(dirpath)
os.makedirs(os.path.dirname(filepath), exist_ok=True)

with open(filepath, "w") as stream:
json.dump(info, stream, indent=4)
Expand Down
43 changes: 20 additions & 23 deletions tools/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ realpath () {
}

repo_root=$(dirname $(dirname "$(realpath ${BASH_SOURCE[0]})"))
poetry_home_root="$repo_root/.poetry"

print_art() {
echo -e "${BGreen}"
Expand Down Expand Up @@ -136,18 +137,18 @@ detect_python () {

install_poetry () {
echo -e "${BIGreen}>>>${RST} Installing Poetry ..."
export POETRY_HOME="$repo_root/.poetry"
export POETRY_HOME=$poetry_home_root
command -v curl >/dev/null 2>&1 || { echo -e "${BIRed}!!!${RST}${BIYellow} Missing ${RST}${BIBlue}curl${BIYellow} command.${RST}"; return 1; }
curl -sSL https://install.python-poetry.org/ | python -

# Force poetry to use older urllib3 if OpenSSL has version < 1.1.1
local ssl_command
ssl_command="import ssl;print(1 if ssl.OPENSSL_VERSION_INFO < (1, 1, 1) else 0)"
local downgrade_urllib
downgrade_urllib="$("$POETRY_HOME/venv/bin/python" <<< ${ssl_command})"
if [ $downgrade_urllib -eq "1" ]; then
downgrade_urllib="$("$poetry_home_root/venv/bin/python" <<< ${ssl_command})"
if [ "$downgrade_urllib" -eq "1" ]; then
echo -e "${BIGreen}>>>${RST} Installing older urllib3 ..."
"$POETRY_HOME/venv/bin/python" -m pip install urllib3==1.26.16
"$poetry_home_root/venv/bin/python" -m pip install urllib3==1.26.16
fi
}

Expand All @@ -174,7 +175,7 @@ create_env () {
pushd "$repo_root" > /dev/null || return > /dev/null

echo -e "${BIGreen}>>>${RST} Reading Poetry ... \c"
if [ -f "$POETRY_HOME/bin/poetry" ]; then
if [ -f "$poetry_home_root/bin/poetry" ]; then
echo -e "${BIGreen}OK${RST}"
else
echo -e "${BIYellow}NOT FOUND${RST}"
Expand All @@ -187,7 +188,7 @@ create_env () {
echo -e "${BIGreen}>>>${RST} Installing dependencies ..."
fi

"$POETRY_HOME/bin/poetry" install --no-root $poetry_verbosity || { echo -e "${BIRed}!!!${RST} Poetry environment installation failed"; return 1; }
"$poetry_home_root/bin/poetry" install --no-root $poetry_verbosity || { echo -e "${BIRed}!!!${RST} Poetry environment installation failed"; return 1; }
if [ $? -ne 0 ] ; then
echo -e "${BIRed}!!!${RST} Virtual environment creation failed."
return 1
Expand All @@ -196,18 +197,18 @@ create_env () {
echo -e "${BIGreen}>>>${RST} Cleaning cache files ..."
clean_pyc

"$POETRY_HOME/bin/poetry" run python -m pip install --disable-pip-version-check --force-reinstall pip
"$poetry_home_root/bin/poetry" run python -m pip install --disable-pip-version-check --force-reinstall pip

if [ -d "$repo_root/.git" ]; then
echo -e "${BIGreen}>>>${RST} Installing pre-commit hooks ..."
"$POETRY_HOME/bin/poetry" run pre-commit install
"$poetry_home_root/bin/poetry" run pre-commit install
fi
}

install_runtime_dependencies () {
# Directories
echo -e "${BIGreen}>>>${RST} Reading Poetry ... \c"
if [ -f "$POETRY_HOME/bin/poetry" ]; then
if [ -f "$poetry_home_root/bin/poetry" ]; then
echo -e "${BIGreen}OK${RST}"
else
echo -e "${BIYellow}NOT FOUND${RST}"
Expand All @@ -218,7 +219,7 @@ install_runtime_dependencies () {
pushd "$repo_root" > /dev/null || return > /dev/null

echo -e "${BIGreen}>>>${RST} Installing runtime dependencies ..."
"$POETRY_HOME/bin/poetry" run python "$repo_root/tools/runtime_dependencies.py"
"$poetry_home_root/bin/poetry" run python "$repo_root/tools/runtime_dependencies.py"
}

# Main
Expand All @@ -239,7 +240,7 @@ build_ayon () {
clean_pyc

echo -e "${BIGreen}>>>${RST} Reading Poetry ... \c"
if [ -f "$POETRY_HOME/bin/poetry" ]; then
if [ -f "$poetry_home_root/bin/poetry" ]; then
echo -e "${BIGreen}OK${RST}"
else
echo -e "${BIYellow}NOT FOUND${RST}"
Expand All @@ -254,14 +255,14 @@ build_ayon () {
git submodule update --init --recursive || { echo -e "${BIRed}!!!${RST} Poetry installation failed"; return 1; }
fi
echo -e "${BIGreen}>>>${RST} Building ..."
"$POETRY_HOME/bin/poetry" run python -m pip --no-color freeze > "$repo_root/build/requirements.txt"
"$POETRY_HOME/bin/poetry" run python "$repo_root/tools/_venv_deps.py"
"$poetry_home_root/bin/poetry" run python -m pip --no-color freeze > "$repo_root/build/requirements.txt"
"$poetry_home_root/bin/poetry" run python "$repo_root/tools/_venv_deps.py"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
"$POETRY_HOME/bin/poetry" run python "$repo_root/setup.py" build &> "$repo_root/build/build.log" || { echo -e "${BIRed}------------------------------------------${RST}"; cat "$repo_root/build/build.log"; echo -e "${BIRed}------------------------------------------${RST}"; echo -e "${BIRed}!!!${RST} Build failed, see the build log."; return 1; }
"$poetry_home_root/bin/poetry" run python "$repo_root/setup.py" build &> "$repo_root/build/build.log" || { echo -e "${BIRed}------------------------------------------${RST}"; cat "$repo_root/build/build.log"; echo -e "${BIRed}------------------------------------------${RST}"; echo -e "${BIRed}!!!${RST} Build failed, see the build log."; return 1; }
elif [[ "$OSTYPE" == "darwin"* ]]; then
"$POETRY_HOME/bin/poetry" run python "$repo_root/setup.py" bdist_mac &> "$repo_root/build/build.log" || { echo -e "${BIRed}------------------------------------------${RST}"; cat "$repo_root/build/build.log"; echo -e "${BIRed}------------------------------------------${RST}"; echo -e "${BIRed}!!!${RST} Build failed, see the build log."; return 1; }
"$poetry_home_root/bin/poetry" run python "$repo_root/setup.py" bdist_mac &> "$repo_root/build/build.log" || { echo -e "${BIRed}------------------------------------------${RST}"; cat "$repo_root/build/build.log"; echo -e "${BIRed}------------------------------------------${RST}"; echo -e "${BIRed}!!!${RST} Build failed, see the build log."; return 1; }
fi
"$POETRY_HOME/bin/poetry" run python "$repo_root/tools/build_post_process.py" "build" || { echo -e "${BIRed}!!!>${RST} ${BIYellow}Failed to process dependencies${RST}"; return 1; }
"$poetry_home_root/bin/poetry" run python "$repo_root/tools/build_post_process.py" "build" || { echo -e "${BIRed}!!!>${RST} ${BIYellow}Failed to process dependencies${RST}"; return 1; }

if [[ "$OSTYPE" == "darwin"* ]]; then
macoscontents="$repo_root/build/AYON $ayon_version.app/Contents"
Expand Down Expand Up @@ -292,7 +293,7 @@ build_ayon () {
}

make_installer_raw() {
"$POETRY_HOME/bin/poetry" run python "$repo_root/tools/build_post_process.py" "make-installer" || { echo -e "${BIRed}!!!>${RST} ${BIYellow}Failed to create installer${RST}"; return 1; }
"$poetry_home_root/bin/poetry" run python "$repo_root/tools/build_post_process.py" "make-installer" || { echo -e "${BIRed}!!!>${RST} ${BIYellow}Failed to create installer${RST}"; return 1; }
}

make_installer() {
Expand All @@ -302,13 +303,13 @@ make_installer() {
}

installer_post_process() {
"$POETRY_HOME/bin/poetry" run python "$repo_root/tools/installer_post_process.py" "$@"
"$poetry_home_root/bin/poetry" run python "$repo_root/tools/installer_post_process.py" "$@"
}

run_from_code() {
pushd "$repo_root" > /dev/null || return > /dev/null
echo -e "${BIGreen}>>>${RST} Running AYON from code ..."
"$POETRY_HOME/bin/poetry" run python "$repo_root/start.py" "$@"
"$poetry_home_root/bin/poetry" run python "$repo_root/start.py" "$@"
}

create_container () {
Expand Down Expand Up @@ -413,10 +414,6 @@ main() {
exit $return_code
fi

if [[ -z $POETRY_HOME ]]; then
export POETRY_HOME="$repo_root/.poetry"
fi

# Use first argument, lower and keep only characters
function_name="$(echo "$1" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z]*//g')"

Expand Down
40 changes: 18 additions & 22 deletions tools/manage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ $current_dir = Get-Location
$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$repo_root = (Get-Item $script_dir).parent.FullName
$app_logo = "$repo_root/common/ayon_common/resources/AYON.png"
$poetry_home = "$repo_root\.poetry"

& git submodule update --init --recursive
# Install PSWriteColor to support colorized output to terminal
Expand Down Expand Up @@ -111,9 +112,8 @@ function Install-Poetry() {

}

$env:POETRY_HOME="$repo_root\.poetry"
$env:POETRY_VERSION="1.8.1"
(Invoke-WebRequest -Uri https://install.python-poetry.org/ -UseBasicParsing).Content | & $($python) -
$env:POETRY_HOME=$poetry_home
(Invoke-WebRequest -Uri https://install.python-poetry.org/ -UseBasicParsing).Content | & $($python) - --version 1.8.1
}


Expand Down Expand Up @@ -266,7 +266,7 @@ function Default-Func {

function Create-Env {
Write-Color -Text ">>> ", "Reading Poetry ... " -Color Green, Gray -NoNewline
if (-not (Test-Path -PathType Container -Path "$($env:POETRY_HOME)\bin")) {
if (-not (Test-Path -PathType Container -Path "$poetry_home\bin")) {
Write-Color -Text "NOT FOUND" -Color Yellow
Install-Poetry
Write-Color -Text "INSTALLED" -Color Cyan
Expand All @@ -280,17 +280,17 @@ function Create-Env {
Write-Color -Text ">>> ", "Installing virtual environment from lock." -Color Green, Gray
}
$startTime = [int][double]::Parse((Get-Date -UFormat %s))
& "$env:POETRY_HOME\bin\poetry" config virtualenvs.in-project true --local
& "$env:POETRY_HOME\bin\poetry" config virtualenvs.create true --local
& "$env:POETRY_HOME\bin\poetry" install --no-root $poetry_verbosity --ansi
& "$poetry_home\bin\poetry" config virtualenvs.in-project true --local
& "$poetry_home\bin\poetry" config virtualenvs.create true --local
& "$poetry_home\bin\poetry" install --no-root $poetry_verbosity --ansi
if ($LASTEXITCODE -ne 0) {
Write-Color -Text "!!! ", "Poetry command failed." -Color Red, Yellow
Restore-Cwd
Exit-WithCode 1
}
if (Test-Path -PathType Container -Path "$($repo_root)\.git") {
Write-Color -Text ">>> ", "Installing pre-commit hooks ..." -Color Green, White
& "$env:POETRY_HOME\bin\poetry" run pre-commit install
& "$poetry_home\bin\poetry" run pre-commit install
if ($LASTEXITCODE -ne 0)
{
Write-Color -Text "!!! ", "Installation of pre-commit hooks failed." -Color Red, Yellow
Expand Down Expand Up @@ -337,7 +337,7 @@ function Build-Ayon($MakeInstaller = $false) {
Write-Color -Text ">>> ", "AYON [ ", $ayon_version, " ]" -Color Green, White, Cyan, White

Write-Color -Text ">>> ", "Reading Poetry ... " -Color Green, Gray -NoNewline
if (-not (Test-Path -PathType Container -Path "$($env:POETRY_HOME)\bin")) {
if (-not (Test-Path -PathType Container -Path "$($poetry_home)\bin")) {
Write-Color -Text "NOT FOUND" -Color Yellow
Write-Color -Text "*** ", "We need to install Poetry create virtual env first ..." -Color Yellow, Gray
Create-Env
Expand All @@ -354,13 +354,13 @@ function Build-Ayon($MakeInstaller = $false) {
Write-Color -Text ">>> ", "Building AYON ..." -Color Green, White
$startTime = [int][double]::Parse((Get-Date -UFormat %s))

$FreezeContent = & "$($env:POETRY_HOME)\bin\poetry" run python -m pip --no-color freeze
& "$($env:POETRY_HOME)\bin\poetry" run python "$($repo_root)\tools\_venv_deps.py"
$FreezeContent = & "$($poetry_home)\bin\poetry" run python -m pip --no-color freeze
& "$($poetry_home)\bin\poetry" run python "$($repo_root)\tools\_venv_deps.py"
# Make sure output is UTF-8 without BOM
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines("$($repo_root)\build\requirements.txt", $FreezeContent, $Utf8NoBomEncoding)

$out = & "$($env:POETRY_HOME)\bin\poetry" run python setup.py build 2>&1
$out = & "$($poetry_home)\bin\poetry" run python setup.py build 2>&1
Set-Content -Path "$($repo_root)\build\build.log" -Value $out
if ($LASTEXITCODE -ne 0)
{
Expand All @@ -372,7 +372,7 @@ function Build-Ayon($MakeInstaller = $false) {
}

Set-Content -Path "$($repo_root)\build\build.log" -Value $out
& "$($env:POETRY_HOME)\bin\poetry" run python "$($repo_root)\tools\build_post_process.py" "build"
& "$($poetry_home)\bin\poetry" run python "$($repo_root)\tools\build_post_process.py" "build"

if ($MakeInstaller) {
Make-Ayon-Installer-Raw
Expand All @@ -388,12 +388,12 @@ function Build-Ayon($MakeInstaller = $false) {
}

function Installer-Post-Process() {
& "$($env:POETRY_HOME)\bin\poetry" run python "$($repo_root)\tools\installer_post_process.py" @args
& "$($poetry_home)\bin\poetry" run python "$($repo_root)\tools\installer_post_process.py" @args
}

function Make-Ayon-Installer-Raw() {
Set-Content -Path "$($repo_root)\build\build.log" -Value $out
& "$($env:POETRY_HOME)\bin\poetry" run python "$($repo_root)\tools\build_post_process.py" "make-installer"
& "$($poetry_home)\bin\poetry" run python "$($repo_root)\tools\build_post_process.py" "make-installer"
}

function Make-Ayon-Installer() {
Expand All @@ -410,23 +410,23 @@ function Make-Ayon-Installer() {

function Install-Runtime-Dependencies() {
Write-Color -Text ">>> ", "Reading Poetry ... " -Color Green, Gray -NoNewline
if (-not (Test-Path -PathType Container -Path "$($env:POETRY_HOME)\bin")) {
if (-not (Test-Path -PathType Container -Path "$($poetry_home)\bin")) {
Write-Color -Text "NOT FOUND" -Color Yellow
Write-Color -Text "*** ", "We need to install Poetry create virtual env first ..." -Color Yellow, Gray
Create-Env
} else {
Write-Color -Text "OK" -Color Green
}
$startTime = [int][double]::Parse((Get-Date -UFormat %s))
& "$($env:POETRY_HOME)\bin\poetry" run python "$($repo_root)\tools\runtime_dependencies.py"
& "$($poetry_home)\bin\poetry" run python "$($repo_root)\tools\runtime_dependencies.py"
$endTime = [int][double]::Parse((Get-Date -UFormat %s))
try {
New-BurntToastNotification -AppLogo "$app_logo" -Text "AYON", "Dependencies downloaded", "All done in $( $endTime - $startTime ) secs."
} catch {}
}

function Run-From-Code() {
& "$($env:POETRY_HOME)\bin\poetry" run python "$($repo_root)\start.py" @arguments
& "$($poetry_home)\bin\poetry" run python "$($repo_root)\start.py" @arguments
}

function Main {
Expand Down Expand Up @@ -465,10 +465,6 @@ function Main {
}
}

if (-not (Test-Path 'env:POETRY_HOME')) {
$env:POETRY_HOME = "$repo_root\.poetry"
}

# Enable if PS 7.x is needed.
# Show-PSWarning

Expand Down

0 comments on commit c7c3b06

Please sign in to comment.