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

推荐订阅源

M
MIT News - Artificial intelligence
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
J
Java Code Geeks
G
Google Developers Blog
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
The Blog of Author Tim Ferriss
月光博客
月光博客
B
Blog
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
博客园_首页
人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
Jina AI
Jina AI
S
SegmentFault 最新的问题
H
Help Net Security
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News

张小凯的博客

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

附录

源代码:

参考: