From 175f7cd0e84a1e23927413e67f94705b19e754fc Mon Sep 17 00:00:00 2001 From: "Xuan (Sean) Hu" Date: Thu, 4 Jul 2024 09:10:21 +0800 Subject: [PATCH] refactor(no-release): make ruff standalone (#630) --- .devcontainer/Dockerfile | 4 +++ .devcontainer/Dockerfile.dockerignore | 1 + .github/workflows/ci.yml | 1 + .gitlab/workflows/ci.yml | 1 + .pre-commit-config.yaml | 4 +-- .renovaterc.json | 2 ++ Makefile | 10 +++++-- pdm.lock | 29 +------------------ pyproject.toml | 1 - .../.devcontainer/Dockerfile.dockerignore | 1 + template/.devcontainer/Dockerfile.jinja | 4 +++ template/.pre-commit-config.yaml.jinja | 4 +-- template/.renovaterc.json.jinja | 2 ++ template/Makefile.jinja | 10 +++++-- .../workflows/ci.yml.jinja | 1 + .../workflows/ci.yml.jinja | 1 + template/pyproject.toml.jinja | 1 - 17 files changed, 37 insertions(+), 40 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 5a621e13..3dd760e0 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -48,6 +48,10 @@ RUN if [ "${PYTHON_VERSION}" = "3.8" ]; then \ pipx install pre-commit==3.7.1; \ fi +# Install prerequisites +RUN --mount=source=Makefile,target=Makefile \ + make prerequisites + # Create a non-root user with sudo permission ARG USERNAME=ss-python ARG USER_UID=1000 diff --git a/.devcontainer/Dockerfile.dockerignore b/.devcontainer/Dockerfile.dockerignore index 8b8ab358..593ed617 100644 --- a/.devcontainer/Dockerfile.dockerignore +++ b/.devcontainer/Dockerfile.dockerignore @@ -1,5 +1,6 @@ * .* +!/Makefile !/README.md !/pdm.lock !/pyproject.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f16a4914..423ecf1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,7 @@ jobs: python-version: ${{ matrix.python-version }} version: 2.16.1 - run: env | sort + - run: make prerequisites - run: make dev - run: make lint test doc build strategy: diff --git a/.gitlab/workflows/ci.yml b/.gitlab/workflows/ci.yml index a35ca13a..1279bc84 100644 --- a/.gitlab/workflows/ci.yml +++ b/.gitlab/workflows/ci.yml @@ -26,6 +26,7 @@ ci: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" - if: $CI_PIPELINE_SOURCE == 'merge_request_event' script: + - make prerequisites - make dev - make lint test doc build stage: ci diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f79930df..7dc8d1ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -59,7 +59,7 @@ repos: require_serial: true - id: ruff name: ruff - entry: pdm run python -m ruff check --force-exclude + entry: ruff check --force-exclude language: system types_or: - python @@ -67,7 +67,7 @@ repos: require_serial: true - id: ruff-format name: ruff-format - entry: pdm run python -m ruff format --force-exclude + entry: ruff format --force-exclude language: system types_or: - python diff --git a/.renovaterc.json b/.renovaterc.json index 33f94067..e4bfcd58 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -10,6 +10,7 @@ "datasourceTemplate": "pypi", "description": "Match Python packages installed with pip/pipx", "fileMatch": [ + "^Makefile$", "^README\\.md$", "^\\.devcontainer/Dockerfile$", "^\\.github/workflows/.+\\.yml$", @@ -20,6 +21,7 @@ "^includes/sample\\.jinja$", "^template/.*\\.github.*/workflows/.+\\.yml(\\.jinja)?$", "^template/.*\\.gitlab.*/workflows/.+\\.yml(\\.jinja)?$", + "^template/Makefile\\.jinja$", "^template/\\.devcontainer/Dockerfile\\.jinja$", "^template/\\.readthedocs\\.yaml$", "^template/\\.renovaterc\\.json\\.jinja$", diff --git a/Makefile b/Makefile index 5e1b5d05..0a91577e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: clean deepclean install dev mypy ruff ruff-format toml-sort lint pre-commit test-run test build publish doc-autobuild doc-gen doc-mypy doc-coverage doc consistency +.PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format toml-sort lint pre-commit test-run test build publish doc-autobuild doc-gen doc-mypy doc-coverage doc consistency ######################################################################################## # Variables @@ -51,6 +51,10 @@ dev: pdm install if [ "$(CI)" != "true" ] && command -v pre-commit > /dev/null 2>&1; then pre-commit install; fi +# Install standalone tools +prerequisites: + pipx install --force ruff==0.5.0 + ######################################################################################## # Lint and pre-commit ######################################################################################## @@ -61,11 +65,11 @@ mypy: # Lint with ruff. ruff: - pdm run python -m ruff check . + ruff check . # Format with ruff. ruff-format: - pdm run python -m ruff format --check . + ruff format --check . # Check lint with toml-sort. toml-sort: diff --git a/pdm.lock b/pdm.lock index 3c5ef875..c577405e 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "doc", "lint", "test"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.2" -content_hash = "sha256:daf4ce9c9306f16b78b25af1c4984de5101a3ef6330c77673368e3e708252f20" +content_hash = "sha256:1f6e6ebed5b67bffe4d942e03647dcff880de3de58626977c9bd4770a948409d" [[package]] name = "alabaster" @@ -933,33 +933,6 @@ files = [ {file = "rich-13.7.1.tar.gz", hash = "sha256:9be308cb1fe2f1f57d67ce99e95af38a1e2bc71ad9813b0e247cf7ffbcc3a432"}, ] -[[package]] -name = "ruff" -version = "0.5.0" -requires_python = ">=3.7" -summary = "An extremely fast Python linter and code formatter, written in Rust." -groups = ["lint"] -files = [ - {file = "ruff-0.5.0-py3-none-linux_armv6l.whl", hash = "sha256:ee770ea8ab38918f34e7560a597cc0a8c9a193aaa01bfbd879ef43cb06bd9c4c"}, - {file = "ruff-0.5.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:38f3b8327b3cb43474559d435f5fa65dacf723351c159ed0dc567f7ab735d1b6"}, - {file = "ruff-0.5.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:7594f8df5404a5c5c8f64b8311169879f6cf42142da644c7e0ba3c3f14130370"}, - {file = "ruff-0.5.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:adc7012d6ec85032bc4e9065110df205752d64010bed5f958d25dbee9ce35de3"}, - {file = "ruff-0.5.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:d505fb93b0fabef974b168d9b27c3960714d2ecda24b6ffa6a87ac432905ea38"}, - {file = "ruff-0.5.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9dc5cfd3558f14513ed0d5b70ce531e28ea81a8a3b1b07f0f48421a3d9e7d80a"}, - {file = "ruff-0.5.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:db3ca35265de239a1176d56a464b51557fce41095c37d6c406e658cf80bbb362"}, - {file = "ruff-0.5.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b1a321c4f68809fddd9b282fab6a8d8db796b270fff44722589a8b946925a2a8"}, - {file = "ruff-0.5.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2c4dfcd8d34b143916994b3876b63d53f56724c03f8c1a33a253b7b1e6bf2a7d"}, - {file = "ruff-0.5.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:81e5facfc9f4a674c6a78c64d38becfbd5e4f739c31fcd9ce44c849f1fad9e4c"}, - {file = "ruff-0.5.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:e589e27971c2a3efff3fadafb16e5aef7ff93250f0134ec4b52052b673cf988d"}, - {file = "ruff-0.5.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d2ffbc3715a52b037bcb0f6ff524a9367f642cdc5817944f6af5479bbb2eb50e"}, - {file = "ruff-0.5.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:cd096e23c6a4f9c819525a437fa0a99d1c67a1b6bb30948d46f33afbc53596cf"}, - {file = "ruff-0.5.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:46e193b36f2255729ad34a49c9a997d506e58f08555366b2108783b3064a0e1e"}, - {file = "ruff-0.5.0-py3-none-win32.whl", hash = "sha256:49141d267100f5ceff541b4e06552e98527870eafa1acc9dec9139c9ec5af64c"}, - {file = "ruff-0.5.0-py3-none-win_amd64.whl", hash = "sha256:e9118f60091047444c1b90952736ee7b1792910cab56e9b9a9ac20af94cd0440"}, - {file = "ruff-0.5.0-py3-none-win_arm64.whl", hash = "sha256:ed5c4df5c1fb4518abcb57725b576659542bdbe93366f4f329e8f398c4b71178"}, - {file = "ruff-0.5.0.tar.gz", hash = "sha256:eb641b5873492cf9bd45bc9c5ae5320648218e04386a5f0c264ad6ccce8226a1"}, -] - [[package]] name = "shellingham" version = "1.5.4" diff --git a/pyproject.toml b/pyproject.toml index 7a96204e..a089b28b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -88,7 +88,6 @@ doc = [ ] lint = [ "mypy", - "ruff", "toml-sort", ] test = [ diff --git a/template/.devcontainer/Dockerfile.dockerignore b/template/.devcontainer/Dockerfile.dockerignore index 8b8ab358..593ed617 100644 --- a/template/.devcontainer/Dockerfile.dockerignore +++ b/template/.devcontainer/Dockerfile.dockerignore @@ -1,5 +1,6 @@ * .* +!/Makefile !/README.md !/pdm.lock !/pyproject.toml diff --git a/template/.devcontainer/Dockerfile.jinja b/template/.devcontainer/Dockerfile.jinja index a6830df8..0438d1ba 100644 --- a/template/.devcontainer/Dockerfile.jinja +++ b/template/.devcontainer/Dockerfile.jinja @@ -48,6 +48,10 @@ RUN if [ "${PYTHON_VERSION}" = "3.8" ]; then \ pipx install pre-commit==3.7.1; \ fi +# Install prerequisites +RUN --mount=source=Makefile,target=Makefile \ + make prerequisites + # Create a non-root user with sudo permission ARG USERNAME={{ repo_name }} ARG USER_UID=1000 diff --git a/template/.pre-commit-config.yaml.jinja b/template/.pre-commit-config.yaml.jinja index 1fd33436..8d53ba64 100644 --- a/template/.pre-commit-config.yaml.jinja +++ b/template/.pre-commit-config.yaml.jinja @@ -62,7 +62,7 @@ repos: require_serial: true - id: ruff name: ruff - entry: pdm run python -m ruff check --force-exclude + entry: ruff check --force-exclude language: system types_or: - python @@ -70,7 +70,7 @@ repos: require_serial: true - id: ruff-format name: ruff-format - entry: pdm run python -m ruff format --force-exclude + entry: ruff format --force-exclude language: system types_or: - python diff --git a/template/.renovaterc.json.jinja b/template/.renovaterc.json.jinja index 9bffc29a..f7cf5843 100644 --- a/template/.renovaterc.json.jinja +++ b/template/.renovaterc.json.jinja @@ -11,6 +11,7 @@ "datasourceTemplate": "pypi", "description": "Match Python packages installed with pip/pipx", "fileMatch": [ + "^Makefile$", "^README\\.md$", "^\\.devcontainer/Dockerfile$", "^\\.github/workflows/.+\\.yml$", @@ -22,6 +23,7 @@ "^includes/sample\\.jinja$", "^template/.*\\.github.*/workflows/.+\\.yml(\\.jinja)?$", "^template/.*\\.gitlab.*/workflows/.+\\.yml(\\.jinja)?$", + "^template/Makefile\\.jinja$", "^template/\\.devcontainer/Dockerfile\\.jinja$", "^template/\\.readthedocs\\.yaml$", "^template/\\.renovaterc\\.json\\.jinja$", diff --git a/template/Makefile.jinja b/template/Makefile.jinja index 955dc121..07720aac 100644 --- a/template/Makefile.jinja +++ b/template/Makefile.jinja @@ -1,5 +1,5 @@ [% from pathjoin("includes", "variable.jinja") import page_url with context -%] -.PHONY: clean deepclean install dev mypy ruff ruff-format toml-sort lint pre-commit test-run test build publish doc-autobuild doc-gen doc-mypy doc-coverage doc +.PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format toml-sort lint pre-commit test-run test build publish doc-autobuild doc-gen doc-mypy doc-coverage doc [%- if project_name == "Serious Scaffold Python" %] consistency[% endif %] ######################################################################################## @@ -53,6 +53,10 @@ dev: pdm install if [ "$(CI)" != "true" ] && command -v pre-commit > /dev/null 2>&1; then pre-commit install; fi +# Install standalone tools +prerequisites: + pipx install --force ruff==0.5.0 + ######################################################################################## # Lint and pre-commit ######################################################################################## @@ -63,11 +67,11 @@ mypy: # Lint with ruff. ruff: - pdm run python -m ruff check . + ruff check . # Format with ruff. ruff-format: - pdm run python -m ruff format --check . + ruff format --check . # Check lint with toml-sort. toml-sort: diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja index 9e5a46cb..a4464e5c 100644 --- a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja @@ -27,6 +27,7 @@ jobs: python-version: {{ '${{ matrix.python-version }}' }} version: 2.16.1 - run: env | sort + - run: make prerequisites - run: make dev - run: make lint test doc build strategy: diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja index 7630b7ec..677d0066 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja @@ -37,6 +37,7 @@ ci: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" - if: $CI_PIPELINE_SOURCE == 'merge_request_event' script: + - make prerequisites - make dev - make lint test doc build stage: ci diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index f78afe54..630ad5a3 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -129,7 +129,6 @@ doc = [ ] lint = [ "mypy", - "ruff", "toml-sort", ] test = [