From 7692b941016bee2ca2fcf9fd1c027ae20980f245 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:06:33 +0200 Subject: [PATCH 1/7] added ruff linting git workflow --- .github/workflows/pr_linting.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/pr_linting.yml diff --git a/.github/workflows/pr_linting.yml b/.github/workflows/pr_linting.yml new file mode 100644 index 000000000..3d2431b69 --- /dev/null +++ b/.github/workflows/pr_linting.yml @@ -0,0 +1,24 @@ +name: ๐Ÿ“‡ Code Linting + +on: + push: + branches: [ develop ] + pull_request: + branches: [ develop ] + + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number}} + cancel-in-progress: true + +permissions: + contents: read + pull-requests: write + +jobs: + linting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: chartboost/ruff-action@v1 From 0b29799cd2c36b82f147d7232e192e82f429c950 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:13:08 +0200 Subject: [PATCH 2/7] removed unused actions --- .github/workflows/nightly_merge.yml | 29 ----------- .github/workflows/test_build.yml | 64 ------------------------- .github/workflows/update_bug_report.yml | 33 ------------- 3 files changed, 126 deletions(-) delete mode 100644 .github/workflows/nightly_merge.yml delete mode 100644 .github/workflows/test_build.yml delete mode 100644 .github/workflows/update_bug_report.yml diff --git a/.github/workflows/nightly_merge.yml b/.github/workflows/nightly_merge.yml deleted file mode 100644 index 3f8c75dce..000000000 --- a/.github/workflows/nightly_merge.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: ๐Ÿ”€ Dev -> Main - -on: - schedule: - - cron: '21 3 * * 3,6' - workflow_dispatch: - -jobs: - develop-to-main: - - runs-on: ubuntu-latest - - steps: - - name: ๐Ÿš› Checkout Code - uses: actions/checkout@v2 - - - name: ๐Ÿ”จ Merge develop to main - uses: everlytic/branch-merge@1.1.0 - with: - github_token: ${{ secrets.YNPUT_BOT_TOKEN }} - source_ref: 'develop' - target_branch: 'main' - commit_message_template: '[Automated] Merged {source_ref} into {target_branch}' - - - name: Invoke pre-release workflow - uses: benc-uk/workflow-dispatch@v1 - with: - workflow: prerelease.yml - token: ${{ secrets.YNPUT_BOT_TOKEN }} diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml deleted file mode 100644 index 90bfa92e4..000000000 --- a/.github/workflows/test_build.yml +++ /dev/null @@ -1,64 +0,0 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -name: ๐Ÿ—๏ธ Test Build - -on: - pull_request: - branches: [develop] - types: [review_requested, ready_for_review] - paths-ignore: - - 'docs/**' - - 'website/**' - - 'vendor/**' - -jobs: - Windows-latest: - - runs-on: windows-latest - strategy: - matrix: - python-version: [3.9] - - steps: - - name: ๐Ÿš› Checkout Code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: ๐Ÿงต Install Requirements - shell: pwsh - run: | - ./tools/manage.ps1 create-env - - - name: ๐Ÿ”จ Build - shell: pwsh - run: | - ./tools/manage.ps1 build - - Ubuntu-latest: - - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.9] - - steps: - - name: ๐Ÿš› Checkout Code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: ๐Ÿงต Install Requirements - run: | - ./tools/make.sh create-env - - - name: ๐Ÿ”จ Build - run: | - ./tools/make.sh build diff --git a/.github/workflows/update_bug_report.yml b/.github/workflows/update_bug_report.yml deleted file mode 100644 index 1f795a3cd..000000000 --- a/.github/workflows/update_bug_report.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: ๐Ÿž Update Bug Report - -on: - workflow_dispatch: - release: - # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release - types: [published] - -jobs: - update-bug-report: - runs-on: ubuntu-latest - name: Update bug report - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ github.event.release.target_commitish }} - - name: Update version - uses: ynput/gha-populate-form-version@main - with: - github_token: ${{ secrets.YNPUT_BOT_TOKEN }} - registry: github - dropdown: _version - limit_to: 100 - form: .github/ISSUE_TEMPLATE/bug_report.yml - commit_message: 'chore(): update bug report / version' - dry_run: no-push - - - name: Push to protected develop branch - uses: CasperWA/push-protected@v2.10.0 - with: - token: ${{ secrets.YNPUT_BOT_TOKEN }} - branch: develop - unprotect_reviews: true From 02101d0364ff110a2bb14332f75b3c8f06ea4466 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:35:43 +0200 Subject: [PATCH 3/7] removed and marked imports --- common/ayon_common/connection/credentials.py | 2 -- setup.py | 1 - start.py | 19 +++++++++---------- tools/_venv_deps.py | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/common/ayon_common/connection/credentials.py b/common/ayon_common/connection/credentials.py index 89c44c7c7..bb3ab36f8 100644 --- a/common/ayon_common/connection/credentials.py +++ b/common/ayon_common/connection/credentials.py @@ -30,8 +30,6 @@ get_ayon_appdirs, get_local_site_id, get_ayon_launch_args, - is_staging_enabled, - is_dev_mode_enabled, ) diff --git a/setup.py b/setup.py index 025751b7b..981688eec 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- """Setup info for building AYON Desktop application.""" import os -import re import platform from pathlib import Path diff --git a/start.py b/start.py index 69228a9e1..e5675b935 100644 --- a/start.py +++ b/start.py @@ -331,37 +331,36 @@ def _print(message: str): get_base_url, set_default_settings_variant, get_addons_studio_settings, -) +) # noqa E402 from ayon_api.constants import ( SERVER_URL_ENV_KEY, SERVER_API_ENV_KEY, DEFAULT_VARIANT_ENV_KEY, SITE_ID_ENV_KEY, -) -from ayon_common import is_staging_enabled, is_dev_mode_enabled +) # noqa E402 +from ayon_common import is_staging_enabled, is_dev_mode_enabled # noqa E402 from ayon_common.connection.credentials import ( ask_to_login_ui, add_server, need_server_or_login, load_environments, - set_environments, create_global_connection, confirm_server_login, show_invalid_credentials_ui, -) +) # noqa E402 from ayon_common.distribution import ( AyonDistribution, BundleNotFoundError, show_missing_bundle_information, show_installer_issue_information, UpdateWindowManager, -) +) # noqa E402 from ayon_common.utils import ( store_current_executable_info, get_local_site_id, -) -from ayon_common.startup import show_startup_error +) # noqa E402 +from ayon_common.startup import show_startup_error # noqa E402 def set_global_environments() -> None: @@ -827,7 +826,7 @@ def main_cli(): """ try: - import ayon_core + import ayon_core # noqa F401 ayon_core_used = True except ImportError: ayon_core_used = False @@ -913,7 +912,7 @@ def script_cli(start_arg=None): start_arg = StartArgScript.from_args(sys.argv) # Remove first argument from sys.argv - # - start.py when running from code + # - start.py when running from code # - ayon executable when running from build sys.argv.pop(0) diff --git a/tools/_venv_deps.py b/tools/_venv_deps.py index 8f4a92b0a..1a69243e1 100644 --- a/tools/_venv_deps.py +++ b/tools/_venv_deps.py @@ -32,7 +32,7 @@ def get_poetry_venv_root(): site.addsitedir(str(get_poetry_venv_root())) -from poetry.factory import Factory +from poetry.factory import Factory # noqa E402 def main(): From 15cc2fadba883c7926732084e5059fe2579adaeb Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:35:55 +0200 Subject: [PATCH 4/7] don't use bare except --- tools/ci_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci_tools.py b/tools/ci_tools.py index d8e6be542..11dd64826 100755 --- a/tools/ci_tools.py +++ b/tools/ci_tools.py @@ -18,7 +18,7 @@ def get_release_type_github(Log, github_token): pr_number = match.group(1) try: pr = repo.get_pull(int(pr_number)) - except: + except BaseException: continue for label in pr.labels: labels.add(label.name) From 37f37f510a581d815dd60dcb6e3d6bddbafa9119 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:36:53 +0200 Subject: [PATCH 5/7] removed unncessary f-string --- common/ayon_common/distribution/control.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/ayon_common/distribution/control.py b/common/ayon_common/distribution/control.py index 29e3f0db7..92cf529ad 100644 --- a/common/ayon_common/distribution/control.py +++ b/common/ayon_common/distribution/control.py @@ -658,7 +658,7 @@ def _install_windows(self, filepath): self.log.error(log_output) raise InstallerDistributionError( "Install process failed without known reason." - f" Try to install AYON manually." + " Try to install AYON manually." ) executable = install_exe_path.strip() or None @@ -786,7 +786,7 @@ def _post_source_process( exc_info=True ) self._installer_error = ( - f"Distribution of AYON launcher" + "Distribution of AYON launcher" " failed with unexpected reason." ) From b41d2995ee984dcaa1e12f778629ddfecf934c81 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:37:05 +0200 Subject: [PATCH 6/7] removed ci tools --- tools/ci_tools.py | 230 ---------------------------------------------- 1 file changed, 230 deletions(-) delete mode 100755 tools/ci_tools.py diff --git a/tools/ci_tools.py b/tools/ci_tools.py deleted file mode 100755 index 11dd64826..000000000 --- a/tools/ci_tools.py +++ /dev/null @@ -1,230 +0,0 @@ -import re -from semver import VersionInfo -from git import Repo -from optparse import OptionParser -from github import Github - - -def get_release_type_github(Log, github_token): - minor_labels = ["Bump Minor"] - - g = Github(github_token) - repo = g.get_repo("ynput/OpenPype") - - labels = set() - for line in Log.splitlines(): - match = re.search("pull request #(\d+)", line) - if match: - pr_number = match.group(1) - try: - pr = repo.get_pull(int(pr_number)) - except BaseException: - continue - for label in pr.labels: - labels.add(label.name) - - if any(label in labels for label in minor_labels): - return "minor" - else: - return "patch" - - # TODO: if all is working fine, this part can be cleaned up eventually - # if any(label in labels for label in patch_labels): - # return "patch" - - return None - - -def remove_prefix(text, prefix): - return text[text.startswith(prefix) and len(prefix):] - - -def get_last_version(match): - repo = Repo() - assert not repo.bare - version_types = { - "CI": "CI/[0-9]*", - "release": "[0-9]*" - } - tag = repo.git.describe( - '--tags', - f'--match={version_types[match]}', - '--abbrev=0' - ) - - if match == "CI": - return remove_prefix(tag, "CI/"), tag - else: - return tag, tag - - -def get_log_since_tag(version): - repo = Repo() - assert not repo.bare - return repo.git.log(f'{version}..HEAD', '--merges', '--oneline') - - -def release_type(log): - regex_minor = ["feature/", "(feat)"] - regex_patch = ["bugfix/", "fix/", "(fix)", "enhancement/", "update"] - for reg in regex_minor: - if re.search(reg, log): - return "minor" - for reg in regex_patch: - if re.search(reg, log): - return "patch" - return None - - -def file_regex_replace(filename, regex, version): - with open(filename, 'r+') as f: - text = f.read() - text = re.sub(regex, version, text) - # pp.pprint(f"NEW VERSION {version} INSERTED into {filename}") - f.seek(0) - f.write(text) - f.truncate() - - -def bump_file_versions(version, nightly=False): - - filename = "./version.py" - regex = "(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-((0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?" - file_regex_replace(filename, regex, version) - - if nightly: - # skip nightly reversion in pyproject.toml - return - - # bump pyproject.toml - filename = "pyproject.toml" - regex = "version = \"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(\+((0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?\" # OpenPype" - pyproject_version = f"version = \"{version}\" # AYON" - file_regex_replace(filename, regex, pyproject_version) - - -def calculate_next_nightly(type="nightly", github_token=None): - last_prerelease, last_pre_tag = get_last_version("CI") - last_pre_v = VersionInfo.parse(last_prerelease) - last_pre_v_finalized = last_pre_v.finalize_version() - # print(last_pre_v_finalized) - - last_release, last_release_tag = get_last_version("release") - - last_release_v = VersionInfo.parse(last_release) - bump_type = get_release_type_github( - get_log_since_tag(last_release_tag), - github_token - ) - if not bump_type: - return None - - next_release_v = last_release_v.next_version(part=bump_type) - # print(next_release_v) - - if next_release_v > last_pre_v_finalized: - next_tag = next_release_v.bump_prerelease(token=type).__str__() - return next_tag - elif next_release_v == last_pre_v_finalized: - next_tag = last_pre_v.bump_prerelease(token=type).__str__() - return next_tag - -def finalize_latest_nightly(): - last_prerelease, last_pre_tag = get_last_version("CI") - last_pre_v = VersionInfo.parse(last_prerelease) - last_pre_v_finalized = last_pre_v.finalize_version() - # print(last_pre_v_finalized) - - return last_pre_v_finalized.__str__() - -def finalize_prerelease(prerelease): - - if "/" in prerelease: - prerelease = prerelease.split("/")[-1] - - prerelease_v = VersionInfo.parse(prerelease) - prerelease_v_finalized = prerelease_v.finalize_version() - - return prerelease_v_finalized.__str__() - - -def main(): - usage = "usage: %prog [options] arg" - parser = OptionParser(usage) - parser.add_option("-n", "--nightly", - dest="nightly", action="store_true", - help="Bump nightly version and return it") - parser.add_option("-b", "--bump", - dest="bump", action="store_true", - help="Return if there is something to bump") - parser.add_option("-r", "--release-latest", - dest="releaselatest", action="store_true", - help="finalize latest prerelease to a release") - parser.add_option("-p", "--prerelease", - dest="prerelease", action="store", - help="define prerelease type") - parser.add_option("-f", "--finalize", - dest="finalize", action="store", - help="define prerelease type") - parser.add_option("-v", "--version", - dest="version", action="store", - help="work with explicit version") - parser.add_option("-l", "--lastversion", - dest="lastversion", action="store", - help="work with explicit version") - parser.add_option("-g", "--github_token", - dest="github_token", action="store", - help="github token") - - - (options, args) = parser.parse_args() - - if options.bump: - last_release, last_release_tag = get_last_version("release") - bump_type_release = get_release_type_github( - get_log_since_tag(last_release_tag), - options.github_token - ) - if bump_type_release is None: - print("skip") - else: - print(bump_type_release) - - if options.nightly: - next_tag_v = calculate_next_nightly(github_token=options.github_token) - print(next_tag_v) - bump_file_versions(next_tag_v, True) - - if options.finalize: - new_release = finalize_prerelease(options.finalize) - print(new_release) - bump_file_versions(new_release) - - if options.lastversion: - last_release, last_release_tag = get_last_version(options.lastversion) - print(last_release_tag) - - if options.releaselatest: - new_release = finalize_latest_nightly() - last_release, last_release_tag = get_last_version("release") - - if VersionInfo.parse(new_release) > VersionInfo.parse(last_release): - print(new_release) - bump_file_versions(new_release) - else: - print("skip") - - if options.prerelease: - current_prerelease = VersionInfo.parse(options.prerelease) - new_prerelease = current_prerelease.bump_prerelease().__str__() - print(new_prerelease) - bump_file_versions(new_prerelease) - - if options.version: - bump_file_versions(options.version) - print(f"Injected version {options.version} into the release") - - - -if __name__ == "__main__": - main() From 171646d3135d2841a17964f267ba13e6605add83 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:40:48 +0200 Subject: [PATCH 7/7] fix noqa marks for multiline import --- start.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/start.py b/start.py index e5675b935..ecd0336a9 100644 --- a/start.py +++ b/start.py @@ -327,19 +327,19 @@ def _print(message: str): elif os.getenv("SSL_CERT_FILE") != certifi.where(): _print("--- your system is set to use custom CA certificate bundle.") -from ayon_api import ( +from ayon_api import ( # noqa E402 get_base_url, set_default_settings_variant, get_addons_studio_settings, -) # noqa E402 -from ayon_api.constants import ( +) +from ayon_api.constants import ( # noqa E402 SERVER_URL_ENV_KEY, SERVER_API_ENV_KEY, DEFAULT_VARIANT_ENV_KEY, SITE_ID_ENV_KEY, -) # noqa E402 +) from ayon_common import is_staging_enabled, is_dev_mode_enabled # noqa E402 -from ayon_common.connection.credentials import ( +from ayon_common.connection.credentials import ( # noqa E402 ask_to_login_ui, add_server, need_server_or_login, @@ -347,19 +347,19 @@ def _print(message: str): create_global_connection, confirm_server_login, show_invalid_credentials_ui, -) # noqa E402 -from ayon_common.distribution import ( +) +from ayon_common.distribution import ( # noqa E402 AyonDistribution, BundleNotFoundError, show_missing_bundle_information, show_installer_issue_information, UpdateWindowManager, -) # noqa E402 +) -from ayon_common.utils import ( +from ayon_common.utils import ( # noqa E402 store_current_executable_info, get_local_site_id, -) # noqa E402 +) from ayon_common.startup import show_startup_error # noqa E402