惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
G
Google Developers Blog
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
P
Proofpoint News Feed
V
Visual Studio Blog
爱范儿
爱范儿
The Cloudflare Blog
博客园 - 叶小钗
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
Microsoft Security Blog
Microsoft Security Blog
博客园 - 聂微东
H
Help Net Security
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
量子位
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

张小凯的博客

再见2025,你好2026! 下一代提示词工程语言POML简明教程 开了一个新的专门学习日语的博客 一、并行编程导论与CUDA入门 一些免费的GPU资源 debian12部署kubernetes-1.28集群 分享两个服务器实用脚本:xsync和xcall RSS订阅工具Folo使用 多平台消息推送工具ntfy使用 AppleScript介绍与简单实战 uv使用 gemini-cli使用 跑步一年多的一些总结和感想 通过GithubActions拉取并推送Docker镜像到国内云 使用AnythingLLM+SillconFlow+Milvus快速搭建个人云端知识库 さよなら2024、こんにちは2025! Excel通过身份证号列计算性别 开源的个人书籍管理系统Talebook 2024年安装Docker的方法
Python项目Linter、Formatter和Github-Actions配置
2024-08-21 · via 张小凯的博客

    1. Python项目Linter、Formatter和Github-Actions配置
      1. Linter
      2. Formatter
      3. 项目配置
    2. 附录

关于Python项目的一些配置问题,包括:

  • Linter
  • Formatter
  • Github-Actions配置;

源代码:


Python项目Linter、Formatter和Github-Actions配置

Linter

Linter 使用的是 PyCharm 自带的,符合 PEP8 规范;

也可以使用:

  • flake8
  • pylint

Formatter

直接用 isort 和 black 就可以了:


项目配置

Pre-Commit:

.pre-commit-config.yaml

repos:
  - repo: https://github.com/psf/black
    rev: 23.1.0
    hooks:
      - id: black
  - repo: https://github.com/pycqa/isort
    rev: 5.12.0
    hooks:
      - id: isort

PyProject:

pyproject.toml

[tool.isort]
profile = "black"

依赖配置:

requirements.txt

-e .[all]

...

requirements-dev.txt

-r requirements.txt

# Ci
black
isort

Github Actions:

.github/workflows/ci.yaml

name: CI

on:
  workflow_dispatch:
  push:
  pull_request:


jobs:
  lint_and_test:
    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: ['3.10', '3.11', '3.12']
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ matrix.python-version }}
        id: setup_python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'
          cache-dependency-path: 'requirements-dev.txt'
      - name: Install dependencies
        run: |
          pip install -r requirements-dev.txt
      - name: Run lint
        uses: pre-commit/action@v2.0.0

附录

源代码:

参考: