From 58527032e0ea805cfdd51ffd0b5bcb7d29a518c6 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Tue, 15 Aug 2023 02:39:43 -0400 Subject: [PATCH] feat: add default python version for development [skip ci] (#212) --- .github/actions/setup-repo/action.yml | 6 +++--- .github/workflows/binary-releases.yml | 9 ++++----- .github/workflows/build.yml | 2 +- .github/workflows/ci.yml | 7 +++---- .github/workflows/create-releases.yml | 2 ++ .pre-commit-config.yaml | 17 ++--------------- .python-version-default | 1 + DEVELOPMENT.md | 6 ++++++ hatch.toml | 2 +- tools/assert-model-table-latest | 2 +- tools/lock-actions | 3 ++- 11 files changed, 26 insertions(+), 31 deletions(-) create mode 100644 .python-version-default diff --git a/.github/actions/setup-repo/action.yml b/.github/actions/setup-repo/action.yml index 8b684695..6483eb7b 100644 --- a/.github/actions/setup-repo/action.yml +++ b/.github/actions/setup-repo/action.yml @@ -13,7 +13,7 @@ runs: using: composite steps: - name: Setup python - uses: actions/setup-python@v4 + uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # ratchet:actions/setup-python@v4 with: python-version: ${{ inputs.python-version }} architecture: ${{ inputs.architecture }} @@ -26,7 +26,7 @@ runs: shell: bash run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT - name: Cache pip dependencies - uses: actions/cache@v3 + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # ratchet:actions/cache@v3 id: cache-pip with: path: ${{ steps.pip-cache-dir.outputs.dir }} @@ -37,4 +37,4 @@ runs: shell: bash run: pip install hatch towncrier - name: Inject slug/short variables - uses: rlespinasse/github-slug-action@v4.4.1 + uses: rlespinasse/github-slug-action@102b1a064a9b145e56556e22b18b19c624538d94 # ratchet:rlespinasse/github-slug-action@v4.4.1 diff --git a/.github/workflows/binary-releases.yml b/.github/workflows/binary-releases.yml index aa9d2c92..71851770 100644 --- a/.github/workflows/binary-releases.yml +++ b/.github/workflows/binary-releases.yml @@ -22,7 +22,6 @@ concurrency: cancel-in-progress: true env: APP_NAME: openllm - PYTHON_VERSION: '3.11' PYOXIDIZER_VERSION: '0.24.0' HATCH_VERBOSE: 2 jobs: @@ -104,10 +103,10 @@ jobs: - name: Fetch PyApp run: >- mkdir $PYAPP_REPO && curl -L https://github.com/ofek/pyapp/releases/download/v$PYAPP_VERSION/source.tar.gz | tar --strip-components=1 -xzf - -C $PYAPP_REPO - - name: Set up Python ${{ env.PYTHON_VERSION }} + - name: Set up Python uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # ratchet:actions/setup-python@v4 with: - python-version: ${{ env.PYTHON_VERSION }} + python-version-file: .python-version-default - name: Install Hatch run: pip install -U hatch - name: Install Rust toolchain @@ -198,10 +197,10 @@ jobs: steps: - name: Checkout code uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # ratchet:actions/checkout@v3 - - name: Set up Python ${{ env.PYTHON_VERSION }} + - name: Set up Python uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # ratchet:actions/setup-python@v4 with: - python-version: ${{ env.PYTHON_VERSION }} + python-version-file: .python-version-default - name: Pull latest change run: git pull --autostash --no-edit --gpg-sign --ff origin main - name: Install PyOxidizer ${{ env.PYOXIDIZER_VERSION }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe5ee927..60f6c214 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,7 +44,7 @@ jobs: aws-region: ${{ env.AWS_REGION }} - name: Start EC2 Runner id: start-ec2-runner - uses: aarnphm/ec2-github-runner@af796d217e24ecbbc5a2c49e780cd90616e2b962 # ratchet:aarnphm/ec2-github-runner@main + uses: aarnphm/ec2-github-runner@main # ratchet:exclude with: mode: start github-token: ${{ secrets.OPENLLM_PAT }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f86b2c91..7d7c6604 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,6 @@ env: COLUMNS: 120 OPENLLM_DO_NOT_TRACK: True PYTHONUNBUFFERED: '1' - STABLE_PYTHON_VERSION: '3.11' HATCH_VERBOSE: 2 # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun defaults: @@ -40,7 +39,7 @@ jobs: - name: Setup CI uses: ./.github/actions/setup-repo with: - python-version: ${{ env.STABLE_PYTHON_VERSION }} + python-version-file: .python-version-default - name: Install OpenLLM run: pip install -e ./openllm-python - uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507 # ratchet:pre-commit/action@v3.0.0 @@ -87,7 +86,7 @@ jobs: - name: Setup CI uses: ./.github/actions/setup-repo with: - python-version: ${{ env.STABLE_PYTHON_VERSION }} + python-version-file: .python-version-default - name: Download coverage data uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # ratchet:actions/download-artifact@v3 with: @@ -129,7 +128,7 @@ jobs: - name: Setup CI uses: ./.github/actions/setup-repo with: - python-version: ${{ env.STABLE_PYTHON_VERSION }} + python-version-file: .python-version-default - name: Install self run: pip install ./openllm-python - name: Speed diff --git a/.github/workflows/create-releases.yml b/.github/workflows/create-releases.yml index aef5c489..5061fa02 100644 --- a/.github/workflows/create-releases.yml +++ b/.github/workflows/create-releases.yml @@ -129,6 +129,8 @@ jobs: fetch-depth: 0 - name: Setup python uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # ratchet:actions/setup-python@v4 + with: + python-version-file: .python-version-default - name: Install dependencies run: pip install hatch towncrier - name: Install jq and curl diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e754b4ac..1957cac8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,23 +1,10 @@ -# Copyright 2023 BentoML Team. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - ci: autoupdate_schedule: weekly skip: [check-models-table-update, changelog-dry-run, pyright, yapf, mypy, sync-readme] autofix_commit_msg: "ci: auto fixes from pre-commit.ci\n\nFor more information, see https://pre-commit.ci" autoupdate_commit_msg: 'ci: pre-commit autoupdate [pre-commit.ci]' - autofix_prs: false +default_language_version: + python: python3.11 # NOTE: sync with .python-version-default exclude: '.*\.(css|js|svg)$' repos: - repo: https://github.com/astral-sh/ruff-pre-commit diff --git a/.python-version-default b/.python-version-default new file mode 100644 index 00000000..2c073331 --- /dev/null +++ b/.python-version-default @@ -0,0 +1 @@ +3.11 diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 6061e67d..81d45e04 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -22,6 +22,12 @@ out to us if you have any question! Before you can start developing, you'll need to set up your environment: +> [!IMPORTANT] +> We recommend using the Python version from `.python-version-default` file within the project root +> to avoid any version mismatch. You can use [pyenv](https://github.com/pyenv/pyenv) to manage your python version. +> Note that `hatch run setup` will symlink the python version from `.python-version-default` to `.python-version` in the project root. +> Therefore any tools that understand `.python-version` will use the correct Python version. + 1. Ensure you have [Git](https://git-scm.com/), and [Python3.8+](https://www.python.org/downloads/) installed. 2. Fork the OpenLLM repository from GitHub. diff --git a/hatch.toml b/hatch.toml index 6a75a848..6fe794cf 100644 --- a/hatch.toml +++ b/hatch.toml @@ -90,7 +90,7 @@ quality = [ "- pre-commit run --all-files", ] recompile = ["bash ./clean.sh", "compile"] -setup = "pre-commit install" +setup = ["pre-commit install", "- ln -s .python-version-default .python-version"] tool = ["quality", "recompile -nx"] typing = ["- pre-commit run mypy {args:-a}", "- pre-commit run pyright {args:-a}"] update-dummy = ["- ./tools/update-dummy.py", "./tools/update-dummy.py"] diff --git a/tools/assert-model-table-latest b/tools/assert-model-table-latest index c0221136..26fa16d1 100755 --- a/tools/assert-model-table-latest +++ b/tools/assert-model-table-latest @@ -1,6 +1,6 @@ #!/usr/bin/env python3 from __future__ import annotations -import os, subprocess, sys +import os, sys from markdown_it import MarkdownIt md = MarkdownIt() diff --git a/tools/lock-actions b/tools/lock-actions index cda8f826..c4bfe052 100755 --- a/tools/lock-actions +++ b/tools/lock-actions @@ -11,4 +11,5 @@ cd "$GIT_ROOT" || exit 1 exit 1 ) -find "${GIT_ROOT}/.github/workflows" -type f -iname '*.yml' -exec docker run -it --rm -v "${PWD}":"${PWD}" -w "${PWD}" ghcr.io/sethvargo/ratchet:0.4.0 pin {} \; +find "${GIT_ROOT}/.github/workflows" -type f -iname '*.yml' -exec docker run -it --rm -v "${PWD}":"${PWD}" -w "${PWD}" -e RATCHET_EXP_KEEP_NEWLINES=true ghcr.io/sethvargo/ratchet:0.4.0 pin {} \; +docker run -it --rm -v "${PWD}":"${PWD}" -w "${PWD}" -e RATCHET_EXP_KEEP_NEWLINES=true ghcr.io/sethvargo/ratchet:0.4.0 pin .github/actions/setup-repo/action.yml