From 0d25d51a04e68f80c87c46b76044fa3bbda1e97a Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 19 Mar 2023 15:20:11 +0100 Subject: [PATCH] Convert the script to a Python package It can now be invoked via `python -m msys2_autobuild` or by installing it, which adds a "msys2-autobuild" script. This is a first step towards splitting up the code. The HTTP cache is now stored in the working directory instead of the source directory. --- .github/workflows/build.yml | 11 +++++++---- .github/workflows/maint.yml | 8 ++++---- README.md | 4 ++-- autobuild.py => msys2_autobuild/__init__.py | 8 +++----- msys2_autobuild/__main__.py | 3 +++ .../fetch-validpgpkeys.sh | 0 poetry.lock | 2 +- pyproject.toml | 3 +++ setup.cfg | 2 +- 9 files changed, 24 insertions(+), 17 deletions(-) rename autobuild.py => msys2_autobuild/__init__.py (99%) create mode 100644 msys2_autobuild/__main__.py rename fetch-validpgpkeys.sh => msys2_autobuild/fetch-validpgpkeys.sh (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0710313..fb9b153 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,6 +16,9 @@ on: schedule: - cron: '0 0/3 * * *' +env: + PYTHONUNBUFFERED: 1 + permissions: contents: write @@ -66,7 +69,7 @@ jobs: GITHUB_TOKEN_READONLY: ${{ secrets.GITHUBTOKENREADONLY }} OPTIONAL_DEPS: ${{ github.event.inputs.optional_deps }} run: | - python -u autobuild.py write-build-plan --optional-deps "$OPTIONAL_DEPS" build_plan.json + python -m msys2_autobuild write-build-plan --optional-deps "$OPTIONAL_DEPS" build_plan.json buildPlan="$(cat build_plan.json)" echo "build-plan=$buildPlan" >> $GITHUB_OUTPUT @@ -76,7 +79,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN_READONLY: ${{ secrets.GITHUBTOKENREADONLY }} run: | - python -u autobuild.py clean-assets + python -m msys2_autobuild clean-assets - name: Show build queue if: steps.check.outputs.build-plan != '[]' @@ -85,7 +88,7 @@ jobs: GITHUB_TOKEN_READONLY: ${{ secrets.GITHUBTOKENREADONLY }} OPTIONAL_DEPS: ${{ github.event.inputs.optional_deps }} run: | - python -u autobuild.py show --optional-deps "$OPTIONAL_DEPS" + python -m msys2_autobuild show --optional-deps "$OPTIONAL_DEPS" build: needs: schedule @@ -171,4 +174,4 @@ jobs: $env:VCPKG_ROOT='' $BUILD_ROOT='C:\' $MSYS2_ROOT=(msys2 -c 'cygpath -w /') - python -u autobuild.py build ${{ matrix.build-args }} "$MSYS2_ROOT" "$BUILD_ROOT" + python -m msys2_autobuild build ${{ matrix.build-args }} "$MSYS2_ROOT" "$BUILD_ROOT" diff --git a/.github/workflows/maint.yml b/.github/workflows/maint.yml index fb5e602..5b92a22 100644 --- a/.github/workflows/maint.yml +++ b/.github/workflows/maint.yml @@ -59,8 +59,8 @@ jobs: GITHUB_TOKEN_READONLY: ${{ secrets.GITHUBTOKENREADONLY }} CLEAR_FAILED_BUILD_TYPES: ${{ github.event.inputs.clear_failed_build_types }} run: | - python -u autobuild.py clear-failed --build-types "$CLEAR_FAILED_BUILD_TYPES" - python -u autobuild.py update-status + python -m msys2_autobuild clear-failed --build-types "$CLEAR_FAILED_BUILD_TYPES" + python -m msys2_autobuild update-status - name: Clear failed packages if: ${{ github.event.inputs.clear_failed_packages != '' }} @@ -69,5 +69,5 @@ jobs: GITHUB_TOKEN_READONLY: ${{ secrets.GITHUBTOKENREADONLY }} CLEAR_FAILED_PACKAGES: ${{ github.event.inputs.clear_failed_packages }} run: | - python -u autobuild.py clear-failed --packages "$CLEAR_FAILED_PACKAGES" - python -u autobuild.py update-status + python -m msys2_autobuild clear-failed --packages "$CLEAR_FAILED_PACKAGES" + python -m msys2_autobuild update-status diff --git a/README.md b/README.md index 404060d..86098bf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # msys2-autobuild -## autobuild.py +## CLI ```console $ pacman -S mingw-w64-x86_64-python-tabulate mingw-w64-x86_64-python-pygithub mingw-w64-x86_64-python-requests @@ -11,7 +11,7 @@ $ python -m pip install --user -r requirements.txt ``` ```console -$ ./autobuild.py --help +$ python -m msys2_autobuild --help usage: autobuild.py [-h] {build,show,should-run,update-status,fetch-assets,upload-assets,clean-assets} ... diff --git a/autobuild.py b/msys2_autobuild/__init__.py similarity index 99% rename from autobuild.py rename to msys2_autobuild/__init__.py index 5ecc992..446d1d8 100755 --- a/autobuild.py +++ b/msys2_autobuild/__init__.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python3 - import sys import os import argparse @@ -1671,7 +1669,7 @@ def install_requests_cache() -> Generator: # Monkey patch globally, so pygithub uses it as well. # Only do re-validation with etag/date etc and ignore the cache-control headers that # github sends by default with 60 seconds. - cache_dir = os.path.join(SCRIPT_DIR, '.autobuild_cache') + cache_dir = os.path.join(os.getcwd(), '.autobuild_cache') os.makedirs(cache_dir, exist_ok=True) requests_cache.install_cache( always_revalidate=True, @@ -1786,5 +1784,5 @@ def main(argv: List[str]) -> None: args.func(args) -if __name__ == "__main__": - main(sys.argv) +def run() -> None: + return main(sys.argv) diff --git a/msys2_autobuild/__main__.py b/msys2_autobuild/__main__.py new file mode 100644 index 0000000..7c15dec --- /dev/null +++ b/msys2_autobuild/__main__.py @@ -0,0 +1,3 @@ +from . import run + +run() diff --git a/fetch-validpgpkeys.sh b/msys2_autobuild/fetch-validpgpkeys.sh similarity index 100% rename from fetch-validpgpkeys.sh rename to msys2_autobuild/fetch-validpgpkeys.sh diff --git a/poetry.lock b/poetry.lock index 704bf67..b29d78c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -769,4 +769,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "9ef21636afb4a916efb9a6b2a646f317a0e854c793cadb72c737d4ab77a0046b" +content-hash = "eb5347d2acbf38939ee4195dbfe6df3397d58bfedee304099bd295bea938800a" diff --git a/pyproject.toml b/pyproject.toml index a908697..ffae992 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,9 @@ flake8 = "^6.0.0" types-tabulate = "^0.9.0.0" types-requests = "^2.25.0" +[tool.poetry.scripts] +msys2-autobuild = 'msys2_autobuild:run' + [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" diff --git a/setup.cfg b/setup.cfg index dbbf017..b13bda9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [flake8] -max-line-length = 110 \ No newline at end of file +max-line-length = 110