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

推荐订阅源

G
Google Developers Blog
博客园 - 司徒正美
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
博客园 - 聂微东
M
MIT News - Artificial intelligence
博客园_首页
Jina AI
Jina AI
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Vercel News
Vercel News
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
B
Blog
Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

张小凯的博客

再见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

附录

源代码:

参考: