Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
【杂项】将 Linter 和 Formatter 迁移到 Ruff (#2)
Browse files Browse the repository at this point in the history
- 移除 `isort`, `black`, `flake8`, `flake8-bugbear`
- 引入 `ruff`
- 重新安装 Git Pre-commit Hooks
- 更新 Workflows 配置文件
  - `macos-latest` 迁移到 arm64 架构
  - 新增 Windows x86 构建
  • Loading branch information
Dragon1573 authored Apr 25, 2024
1 parent bb43b10 commit c1778b0
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 183 deletions.
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

153 changes: 147 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ on:
push:

jobs:
build:
amd64:
name: 编译构建(${{ matrix.os }} amd64)

strategy:
matrix:
os: [ubuntu, macos, windows]
os: [windows-latest, ubuntu-latest]

fail-fast: false

runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.os }}

steps:
- name: 检出仓库
Expand All @@ -28,7 +29,6 @@ jobs:
uses: seanmiddleditch/gha-setup-vsdevenv@v4
with:
arch: amd64
host_arch: amd64
- name: 配置 PDM 构建环境
uses: pdm-project/setup-pdm@v4
with:
Expand All @@ -45,16 +45,157 @@ jobs:
echo "::endgroup::"
- name: 执行持续集成检查
run: pdm run ci
env:
# 让 Ruff 以 GitHub Workflows 集成格式进行输出
RUFF_OUTPUT_FORMAT: github
- name: 获取系统代号
id: get_os
shell: bash
run: |-
if [[ "${{ matrix.os }}" =~ "windows" ]]; then
echo "os=windows" >> "$GITHUB_OUTPUT";
elif [[ "${{ matrix.os }}" =~ "macos" ]]; then
echo "os=darwin" >> "$GITHUB_OUTPUT";
elif [[ "${{ matrix.os }}" =~ "ubuntu" ]]; then
echo "os=linux" >> "$GITHUB_OUTPUT";
fi
- name: 编译打包
# macOS 的图标使用 *.icns 而非 *.ico
# 因此 Dev Dependencies 中的 Pillow 是必要的
# PyInstaller 会使用它转换图标格式
run: pdm run build "Numzle-${{ steps.get_os.outputs.os }}_amd64"
- name: 发布每日构建
if: startsWith(github.ref, 'refs/heads/')
uses: actions/upload-artifact@v4
with:
name: Numzle-${{ steps.get_os.outputs.os }}_amd64
path: dist/Numzle*
retention-days: 7
- name: 生成发布说明
id: changelog
if: startsWith(github.ref, 'refs/tags/')
run: |-
git log -n 1 --pretty="format: ## %s%n%n%b" > CHANGELOG.txt
- name: 发布构建产物
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
body_path: CHANGELOG.txt
draft: true
prerelease: ${{ startsWith(github.ref_name, 'v0') }}
files: |-
dist/Numzle*
i386:
name: 编译构建(${{ matrix.os }} i386)

strategy:
matrix:
os: [windows-latest]

fail-fast: false

runs-on: ${{ matrix.os }}

steps:
- name: 检出仓库
uses: actions/checkout@v4
- name: 安装 MSVC
# Runner 模式预装 MinGW-w64 用于编译 NumPy
# 这还只是实验性质的功能,当 PyInstaller 打包时会崩溃
# 我们需要安装配置 MSVC ,让 PDM 用它去编译构建 NumPy
uses: seanmiddleditch/gha-setup-vsdevenv@v4
with:
arch: x86
- name: 配置 PDM 构建环境
uses: pdm-project/setup-pdm@v4
with:
python-version: 3.11
architecture: x86
cache: true
- name: 安装依赖项和提交钩子
run: |-
echo "::group::安装依赖项"
pdm install
echo "::endgroup::"
echo "::group::安装提交钩子"
pdm run git
echo "::endgroup::"
- name: 执行持续集成检查
run: pdm run ci
env:
# 让 Ruff 以 GitHub Workflows 集成格式进行输出
RUFF_OUTPUT_FORMAT: github
- name: 编译打包
# macOS 的图标使用 *.icns 而非 *.ico
# 因此 Dev Dependencies 中的 Pillow 是必要的
# PyInstaller 会使用它转换图标格式
run: pdm run build "Numzle-windows_i386"
- name: 发布每日构建
if: startsWith(github.ref, 'refs/heads/')
uses: actions/upload-artifact@v4
with:
name: Numzle-windows_i386
path: dist/Numzle*
retention-days: 7
- name: 生成发布说明
id: changelog
if: startsWith(github.ref, 'refs/tags/')
run: |-
git log -n 1 --pretty="format: ## %s%n%n%b" > CHANGELOG.txt
- name: 发布构建产物
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
body_path: CHANGELOG.txt
draft: true
prerelease: ${{ startsWith(github.ref_name, 'v0') }}
files: |-
dist/Numzle*
arm64:
name: 编译构建(${{ matrix.os }} arm64)

strategy:
matrix:
os: [macos-latest]

fail-fast: false

runs-on: ${{ matrix.os }}

steps:
- name: 检出仓库
uses: actions/checkout@v4
- name: 配置 PDM 构建环境
uses: pdm-project/setup-pdm@v4
with:
python-version: 3.11
architecture: arm64
cache: true
- name: 安装依赖项和提交钩子
run: |-
echo "::group::安装依赖项"
pdm install
echo "::endgroup::"
echo "::group::安装提交钩子"
pdm run git
echo "::endgroup::"
- name: 执行持续集成检查
run: pdm run ci
env:
# 让 Ruff 以 GitHub Workflows 集成格式进行输出
RUFF_OUTPUT_FORMAT: github
- name: 编译打包
# macOS 的图标使用 *.icns 而非 *.ico
# 因此 Dev Dependencies 中的 Pillow 是必要的
# PyInstaller 会使用它转换图标格式
run: pdm run build "Numzle-${{ matrix.os }}_amd64"
run: pdm run build "Numzle-darwin_arm64"
- name: 发布每日构建
if: startsWith(github.ref, 'refs/heads/')
uses: actions/upload-artifact@v4
with:
name: Numzle-${{ matrix.os }}_amd64
name: Numzle-darwin_arm64
path: dist/Numzle*
retention-days: 7
- name: 生成发布说明
Expand Down
19 changes: 9 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
repos:
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.1
hooks:
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.12
# Run the linter.
- id: ruff
args:
- "--line-length=120"
- "--fix"
- "--verbose"
# Run the formatter.
- id: ruff-format
Loading

0 comments on commit c1778b0

Please sign in to comment.