SkillAtlasSkill 详情

python-pypi-package-builder

Powered by Awesome Copilot GitHub contributors from allcontributors.org

审核状态:已审核Quality 80Security 62

复制安装命令

用 Codex 或 Claude 安装复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它先审查 Skill 页面再帮你安装。

复制前请先查看来源、License 和安全提示。

项目 README

来源文件:README.md

抓取于 2026年7月31日

🤖 Awesome GitHub Copilot

Powered by Awesome Copilot GitHub contributors from allcontributors.org

A community-created collection of custom agents, instructions, skills, hooks, workflows, and plugins to supercharge your GitHub Copilot experience.

[!TIP] Explore the full collection on the website → awesome-copilot.github.com

The website offers full-text search and filtering across hundreds of resources, plus the Learning Hub for guides and tutorials.

Using this collection in an AI agent? A machine-readable llms.txt is available with structured listings of all agents, instructions, and skills.

📖 Learning Hub

New to GitHub Copilot customization? The Learning Hub on the website offers curated articles, walkthroughs, and reference material — covering everything from core concepts like agents, skills, and instructions to hands-on guides for hooks, agentic workflows, MCP servers, and the Copilot coding agent.

What's in this repo

ResourceDescriptionBrowse
🤖 AgentsSpecialized Copilot agents that integrate with MCP serversAll agents →
📋 InstructionsCoding standards applied automatically by file patternAll instructions →
🎯 SkillsSelf-contained folders with instructions and bundled assetsAll skills →
🔌 PluginsCurated bundles of agents and skills for specific workflowsAll plugins →
🍳 CookbookCopy-paste-ready recipes for working with Copilot APIs—

Install a Plugin

For most users, the Awesome Copilot marketplace is already registered in the Copilot CLI/VS Code, so you can install a plugin directly:

copilot plugin install <plugin-name>@awesome-copilot

If you are using an older Copilot CLI version or a custom setup and see an error that the marketplace is unknown, register it once and then install:

copilot plugin marketplace add github/awesome-copilot
copilot plugin install <plugin-name>@awesome-copilot

Contributing

See CONTRIBUTING.md · AGENTS.md for AI agent guidance · Security · Code of Conduct

The customizations here are sourced from third-party developers. Please inspect any agent and its documentation before installing.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Aaron Powell

Matt Soucoup

Troy Simeon Taylor

Abbas

Peter Strömberg

Daniel Scott-Raynsford

John Haugabook

Pavel Simsa

Harald Kirschner

Muhammad Ubaid Raza

Tom Meschter

Aung Myo Kyaw

JasonYeMSFT

Jon Corbin

troytaylor-msft

Emerson Delatorre

Burke Holland

Kent Yao

Daniel Meppiel

Gordon Lam

Mads Kristensen

Shinji Takenaka

spectatora

Yohan Lasorsa

Vamshi Verma

James Montemagno

Alessandro Fragnani

Ambily

krushideep

devopsfan

Tugdual Grall

Oren Me

Mike Rousos

Justin Yoo

Guilherme do Amaral Alves

Griffin Ashe

Ashley Childress

Adrien Clerbois

ANGELELLI David

Mark Davis

Matt Vevang

Maximilian Irro

NULLchimp

Peter Karda

Saul Dolgin

Shubham Gaikwad

Theo van Kraay

Tianqi Zhang

Will 保哥

Yuta Matsumura

anschnapp

hizahizi-hizumi

黃健旻 Vincent Huang

Bruno Borges

Steve Magne

Shane Neuville

André Silva

Allen Greaves

Amelia Payne

BBoyBen

Brooke Hamilton

Christopher Harrison

Dan

Dan Wahlin

Debbie O'Brien

Ed Harrod

Genevieve Warren

Guillaume

Henrique Nunes

Jeremiah Snee

Kartik Dhiman

Kristiyan Velkov

msalaman

Per Søderlind

Peter Smulovics

Ravish Rathod

Rick Smit

Rob Simpson

Robert Altman

Salih

Sebastian Gräf

Sebastien DEGODEZ

Sergiy Smyrnov

SomeSolutionsArchitect

Stu Mace

Søren Trudsø Mahon

Tj Vita

Peli de Halleux

Paulo Morgado

Paul Crane

Pamela Fox

Oskar Thornblad

Nischay Sharma

Nikolay Marinov

Nik Sachdeva

Nick Taylor

Nick Brady

Nathan Stanford Sr

Máté Barabás

Mike Parker

Mike Kistler

Giovanni de Almeida Martins

이상현

Ankur Sharma

Wendy Breiding

voidfnc

shane lee

sdanzo-hrb

sauran

samqbush

pareenaverma

oleksiyyurchyna

oceans-of-time

kshashank57

Meii

factory-davidgu

dangelov-qa

BenoitMaucotel

benjisho-aidome

Yuki Omoto

Will Schultz

Waren Gonzaga

Vincent Koc

Victor Williams

Ve Sharma

Vasileios Lahanas

Udaya Veeramreddygari

Tài Lê

Tsubasa Ogawa

Troy Witthoeft (glsauto)

Gerald Versluis

George Dernikos

Gautam

Furkan Enes

Florian Mücke

Felix Arjuna

Eldrick Wega

Dobri Danchev

Diego Gamboa

Derek Clair

David Ortinau

Daniel Abbatt

CypherHK

Craig Bekker

Christophe Peugnet

Christian Lechner

Chris Harris

Artem Saveliev

Antoine Rey

Ankit Das

Aline Ávila

Alexander Martinkevich

Aleksandar Dunchev

Alan Sprecacenere

Akash Kumar Shaw

Abdi Daud

AIAlchemyForge

4regab

Miguel P Z

Michael Fairchild

Michael A. Volz (Flynn)

Michael

Mehmet Ali EROL

Max Prilutskiy

Matteo Bianchi

Mark Noble

Manish Jayaswal

Luke Murray

Louella Creemers

Sai Koumudi Kaluvakolanu

Kenny White

KaloyanGenev

Kim Skov Rasmussen

Julien Dubois

José Antonio Garrido

Joseph Gonzales

Jorge Balderas

John Papa

John

Joe Watkins

Jan de Vries

Jakub Jareš

Jackson Miller

Ioana A

Hunter Hogan

Hashim Warren

Gonzalo

Gisela Torres

Shibi Ramachandran

lupritz

Héctor Benedicte

Ted Vilutis

Anthony Shaw

Chris McKee

CASTResearchLabs

白水淳

Imran Siddique

共产主义接班人

Ivan Charapanau

Tadas Labudis

Alvin Ashcraft

Jan Krivanek

Gregg Cochran

Josh N

ian zhang

Garrett Siegel

Roberto Perez

Dan Velton

Lee Reilly

Daniel Coelho

Vahid Faraji

Ashley Wolf

Noah Jenkins

Jeremy Kohn

Harri Sipola

Toru Makabe

Pham Tien Thuan Phat

Benji Shohet

Amaury Levé

Tim Deschryver

Mohammad Asad Alahmadi

fondoger

Yuval Avidani

Csaba Iváncza

Tim Heuer

lance2k

Andrea Liliana Griffiths

Ajith Raghavan

Catherine Han

Igor Shishkin

Burrito Verde

Joseph Van der Wee

Luiz Bon

Sanjay Ramassery Babu

Russ Rimmerman [MSFT]

Roberto Perez

Shehab Sherif

Smit Patel

Steven Vore

Subhashis Bhowmik

Tim Mulholland

Niels Laute

Pavel Sulimau

PrimedPaul

Zhiqi Pu

Ramyashree Shetty

ZdaPhp

pigd0g

rahulbats

suyask-msft

tagedeep

tinkeringDev

Travis Hill

Utkarsh patrikar

Yauhen

Yiou Li

Yuki Omoto

Abhi Bavishi

augustus-0

Branislav Buna

connerlambden

David Raygoza

Diego Porto Ritzel

Eric Scherlinger

Fatih

Felipe Pessoto

François

Geoffrey Casaubon

Anddd7

Anders Eide

Aymen

Kevin van Zonneveld

Luis Cantero

MV Karan

Marcel Deutzer

Jon Galloway

Josh Beard

Julian

Simon Kurtz

Temitayo Afolabi

JoeVenner

Pasindu Premarathna

ecosystem

Punit

Onur Senturk

Andrew Stellman

Jeonghoon Lee

Satya K

Samik Roy

Simina Pasat

Tyler Garner

Vijay Chegu

DTIBeograd

Anmol Behl

Brad Kinnard

Chad Bentz

Marcello Cuoghi

Josh Johanning

jennyf19

Saravanan Rajaraman

Patel Dhruv

Renee Noble

jjpinto

moeyui1

mohammadali2549

Vladislav Guzey

aparna198809

Ed McAdams

Emil Andersson

Mikael

Mrigank Singh

Jim Bennett

Alishahzad1903

Antonio Villanueva

Tim Hanewich

ming

Scott O'Hara

Salih

Shailesh

Shubham Jiyani

Srinivas Vaddi

Philippe D

Rajesh Goldy

dstrupl

wuwen

Tilak Patel

Vijay Bandi

Zixuan Jiang

Dennis Lembree

Dev Shah

Falco

AJ

Anush

Ayush Saklani

Carlos Alexandro Becker

Mangokernel

Mario Codes

Gonzalo Fleming

Steve Magne

Sertxito

Rayner Zeng

ilderaj

mvanderbend-msoft

Parveen Sharma

pmorong

vinod kumar

Vidhart Bhatia

Xiaoyun Ding

denis-a-evdokimov

Adriano Nogueira

Aezan

Andy Anderson

Kweku Dzata

Marcel

Navaneeth Reddy

James

Joseph Counts

Neha Mandge

Srikanth Patchava

Thomas Ray

Nixon Kurian

Petr Stupka

Pieter de Bruin

sudeepghatak

tlietz

dawright22

Alejandro Fernando Suarez Gomez

Burak Bayır

MUHAMMAD SAMIULLAH

Nikola Metulev

Joseph Kasprzyk

Lovy Jain

kimtth

Akash Dwivedi

Suren K
Add your contributions

This project follows the all-contributors specification. Contributions of any kind welcome!

📚 Additional Resources

™️ Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

测试与质量Agent / MCP / Skill 创作

高风险

  • 来源需自行核对维护者身份。
  • 包含脚本或命令调用,安装前请复核。
  • 未检测到明显外部权限要求。
  • 存在潜在风险命令,请谨慎安装。
  • 扫描发现:4 条。

Codex — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/github/awesome-copilot.git
  3. 将 "skills/python-pypi-package-builder" 文件夹复制到 Codex 的 skills 目录中。
  4. 重启 Codex 让新的 skill 生效。

Codex — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Codex 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Codex 让新的 skill 生效。

Claude Code — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/github/awesome-copilot.git
  3. 将 "skills/python-pypi-package-builder" 文件夹复制到 Claude Code 的 skills 目录中。
  4. 重启 Claude Code 让新的 skill 生效。

Claude Code — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Claude Code 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Claude Code 让新的 skill 生效。

Cursor — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/github/awesome-copilot.git
  3. 将 "skills/python-pypi-package-builder" 文件夹复制到 Cursor 的 skills 目录中。
  4. 重启 Cursor 让新的 skill 生效。

Cursor — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Cursor 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Cursor 让新的 skill 生效。

GitHub Copilot — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/github/awesome-copilot.git
  3. 将 "skills/python-pypi-package-builder" 文件夹复制到 GitHub Copilot 的 skills 目录中。
  4. 重启 GitHub Copilot 让新的 skill 生效。

GitHub Copilot — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 GitHub Copilot 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 GitHub Copilot 让新的 skill 生效。

Windsurf — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/github/awesome-copilot.git
  3. 将 "skills/python-pypi-package-builder" 文件夹复制到 Windsurf 的 skills 目录中。
  4. 重启 Windsurf 让新的 skill 生效。

Windsurf — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Windsurf 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Windsurf 让新的 skill 生效。
查看 SKILL.md 原文
name: python-pypi-package-builder
description: 'End-to-end skill for building, testing, linting, versioning, and publishing a production-grade Python library to PyPI. Covers all four build backends (setuptools+setuptools_scm, hatchling, flit, poetry), PEP 440 versioning, semantic versioning, dynamic git-tag versioning, OOP/SOLID design, type hints (PEP 484/526/544/561), Trusted Publishing (OIDC), and the full PyPA packaging flow. Use for: creating Python packages, pip-installable SDKs, CLI tools, framework plugins, pyproject.toml setup, py.typed, setuptools_scm, semver, mypy, pre-commit, GitHub Actions CI/CD, or PyPI publishing.'

Python PyPI Package Builder Skill

A complete, battle-tested guide for building, testing, linting, versioning, typing, and publishing a production-grade Python library to PyPI — from first commit to community-ready release.

AI Agent Instruction: Read this entire file before writing a single line of code or creating any file. Every decision — layout, backend, versioning strategy, patterns, CI — has a decision rule here. Follow the decision trees in order. This skill applies to any Python package type (utility, SDK, CLI, plugin, data library). Do not skip sections.


Quick Navigation

Section in this fileWhat it covers
1. Skill TriggerWhen to load this skill
2. Package Type DecisionIdentify what you are building
3. Folder Structure Decisionsrc/ vs flat vs monorepo
4. Build Backend Decisionsetuptools / hatchling / flit / poetry
5. PyPA Packaging FlowThe canonical publish pipeline
6. Project Structure TemplatesFull layouts for every option
7. Versioning StrategyPEP 440, semver, dynamic vs static
Reference fileWhat it covers
references/pyproject-toml.mdAll four backend templates, setuptools_scm, py.typed, tool configs
references/library-patterns.mdOOP/SOLID, type hints, core class design, factory, protocols, CLI
references/testing-quality.mdconftest.py, unit/backend/async tests, ruff/mypy/pre-commit
references/ci-publishing.mdci.yml, publish.yml, Trusted Publishing, TestPyPI, CHANGELOG, release checklist
references/community-docs.mdREADME, docstrings, CONTRIBUTING, SECURITY, anti-patterns, master checklist
references/architecture-patterns.mdBackend system (plugin/strategy), config layer, transport layer, CLI, backend injection
references/versioning-strategy.mdPEP 440, SemVer, pre-release, setuptools_scm deep-dive, flit static, decision engine
references/release-governance.mdBranch strategy, branch protection, OIDC, tag author validation, prevent invalid tags
references/tooling-ruff.mdRuff-only setup (replaces black/isort), mypy config, pre-commit, asyncio_mode=auto

Scaffold script: run python skills/python-pypi-package-builder/scripts/scaffold.py --name your-package-name to generate the entire directory layout, stub files, and pyproject.toml in one command.


1. Skill Trigger

Load this skill whenever the user wants to:

  • Create, scaffold, or publish a Python package or library to PyPI
  • Build a pip-installable SDK, utility, CLI tool, or framework extension
  • Set up pyproject.toml, linting, mypy, pre-commit, or GitHub Actions for a Python project
  • Understand versioning (setuptools_scm, PEP 440, semver, static versioning)
  • Understand PyPA specs: py.typed, MANIFEST.in, RECORD, classifiers
  • Publish to PyPI using Trusted Publishing (OIDC) or API tokens
  • Refactor an existing package to follow modern Python packaging standards
  • Add type hints, protocols, ABCs, or dataclasses to a Python library
  • Apply OOP/SOLID design patterns to a Python package
  • Choose between build backends (setuptools, hatchling, flit, poetry)

Also trigger for phrases like: "build a Python SDK", "publish my library", "set up PyPI CI", "create a pip package", "how do I publish to PyPI", "pyproject.toml help", "PEP 561 typed", "setuptools_scm version", "semver Python", "PEP 440", "git tag release", "Trusted Publishing".


2. Package Type Decision

Identify what the user is building before writing any code. Each type has distinct patterns.

Decision Table

TypeCore PatternEntry PointKey DepsExample Packages
Utility libraryModule of pure functions + helpersImport API onlyMinimalarrow, humanize, boltons, more-itertools
API client / SDKClass with methods, auth, retry logicImport API onlyhttpx or requestsboto3, stripe-python, openai
CLI toolCommand functions + argument parser[project.scripts] or [project.entry-points]click or typerblack, ruff, httpie, rich
Framework pluginPlugin class, hook registration[project.entry-points."framework.plugin"]Framework deppytest-*, django-*, flask-*
Data processing libraryClasses + functional pipelineImport API onlyOptional: numpy, pandaspydantic, marshmallow, cerberus
Mixed / genericCombination of aboveVariesVariesMany real-world packages

Decision Rule: Ask the user if unclear. A package can combine types (e.g., SDK with a CLI entry point) — use the primary type for structural decisions and add secondary type patterns on top.

For implementation patterns of each type, see references/library-patterns.md.

Package Naming Rules

  • PyPI name: all lowercase, hyphens — my-python-library
  • Python import name: underscores — my_python_library
  • Check availability: https://pypi.org/search/ before starting
  • Avoid shadowing popular packages (verify pip install <name> fails first)

3. Folder Structure Decision

Decision Tree

Does the package have 5+ internal modules OR multiple contributors OR complex sub-packages?
├── YES → Use src/ layout
│         Reason: prevents accidental import of uninstalled code during development;
│         separates source from project root files; PyPA-recommended for large projects.
│
├── NO → Is it a single-module, focused package (e.g., one file + helpers)?
│         ├── YES → Use flat layout
│         └── NO (medium complexity) → Use flat layout, migrate to src/ if it grows
│
└── Is it multiple related packages under one namespace (e.g., myorg.http, myorg.db)?
          └── YES → Use namespace/monorepo layout

Quick Rule Summary

SituationUse
New project, unknown future sizesrc/ layout (safest default)
Single-purpose, 1–4 modulesFlat layout
Large library, many contributorssrc/ layout
Multiple packages in one repoNamespace / monorepo
Migrating old flat projectKeep flat; migrate to src/ at next major version

4. Build Backend Decision

Decision Tree

Does the user need version derived automatically from git tags?
├── YES → Use setuptools + setuptools_scm
│         (git tag v1.0.0 → that IS your release workflow)
│
└── NO → Does the user want an all-in-one tool (deps + build + publish)?
          ├── YES → Use poetry (v2+ supports standard [project] table)
          │
          └── NO → Is the package pure Python with no C extensions?
                    ├── YES, minimal config preferred → Use flit
                    │   (zero config, auto-discovers version from __version__)
                    │
                    └── YES, modern & fast preferred → Use hatchling
                        (zero-config, plugin system, no setup.py needed)

Does the package have C/Cython/Fortran extensions?
└── YES → MUST use setuptools (only backend with full native extension support)

Backend Comparison

BackendVersion sourceConfigC extensionsBest for
setuptools + setuptools_scmgit tags (automatic)pyproject.toml + optional setup.py shimYesProjects with git-tag releases; any complexity
hatchlingmanual or pluginpyproject.toml onlyNoNew pure-Python projects; fast, modern
flit__version__ in __init__.pypyproject.toml onlyNoVery simple, single-module packages
poetrypyproject.toml fieldpyproject.toml onlyNoTeams wanting integrated dep management

For all four complete pyproject.toml templates, see references/pyproject-toml.md.


5. PyPA Packaging Flow

This is the canonical end-to-end flow from source code to user install. Every step must be understood before publishing.

1. SOURCE TREE
   Your code in version control (git)
   └── pyproject.toml describes metadata + build system

2. BUILD
   python -m build
   └── Produces two artifacts in dist/:
       ├── *.tar.gz   → source distribution (sdist)
       └── *.whl      → built distribution (wheel) — preferred by pip

3. VALIDATE
   twine check dist/*
   └── Checks metadata, README rendering, and PyPI compatibility

4. TEST PUBLISH (first release only)
   twine upload --repository testpypi dist/*
   └── Verify: pip install --index-url https://test.pypi.org/simple/ your-package

5. PUBLISH
   twine upload dist/*          ← manual fallback
   OR GitHub Actions publish.yml  ← recommended (Trusted Publishing / OIDC)

6. USER INSTALL
   pip install your-package
   pip install "your-package[extra]"

Key PyPA Concepts

ConceptWhat it means
sdistSource distribution — your source + metadata; used when no wheel is available
wheel (.whl)Pre-built binary — pip extracts directly into site-packages; no build step
PEP 517/518Standard build system interface via pyproject.toml [build-system] table
PEP 621Standard [project] table in pyproject.toml; all modern backends support it
PEP 639license key as SPDX string (e.g., "MIT", "Apache-2.0") — not {text = "MIT"}
PEP 561py.typed empty marker file — tells mypy/IDEs this package ships type information

For complete CI workflow and publishing setup, see references/ci-publishing.md.


6. Project Structure Templates

A. src/ Layout (Recommended default for new projects)

your-package/
├── src/
│   └── your_package/
│       ├── __init__.py           # Public API: __all__, __version__
│       ├── py.typed              # PEP 561 marker — EMPTY FILE
│       ├── core.py               # Primary implementation
│       ├── client.py             # (API client type) or remove
│       ├── cli.py                # (CLI type) click/typer commands, or remove
│       ├── config.py             # Settings / configuration dataclass
│       ├── exceptions.py         # Custom exception hierarchy
│       ├── models.py             # Data classes, Pydantic models, TypedDicts
│       ├── utils.py              # Internal helpers (prefix _utils if private)
│       ├── types.py              # Shared type aliases and TypeVars
│       └── backends/             # (Plugin pattern) — remove if not needed
│           ├── __init__.py       # Protocol / ABC interface definition
│           ├── memory.py         # Default zero-dep implementation
│           └── redis.py          # Optional heavy implementation
├── tests/
│   ├── __init__.py
│   ├── conftest.py               # Shared fixtures
│   ├── unit/
│   │   ├── __init__.py
│   │   ├── test_core.py
│   │   ├── test_config.py
│   │   └── test_models.py
│   ├── integration/
│   │   ├── __init__.py
│   │   └── test_backends.py
│   └── e2e/                      # Optional: end-to-end tests
│       └── __init__.py
├── docs/                         # Optional: mkdocs or sphinx
├── scripts/
│   └── scaffold.py
├── .github/
│   ├── workflows/
│   │   ├── ci.yml
│   │   └── publish.yml
│   └── ISSUE_TEMPLATE/
│       ├── bug_report.md
│       └── feature_request.md
├── .pre-commit-config.yaml
├── pyproject.toml
├── CHANGELOG.md
├── CONTRIBUTING.md
├── SECURITY.md
├── LICENSE
├── README.md
└── .gitignore

B. Flat Layout (Small / focused packages)

your-package/
├── your_package/         # ← at root, not inside src/
│   ├── __init__.py
│   ├── py.typed
│   └── ... (same internal structure)
├── tests/
└── ... (same top-level files)

C. Namespace / Monorepo Layout (Multiple related packages)

your-org/
├── packages/
│   ├── your-org-core/
│   │   ├── src/your_org/core/
│   │   └── pyproject.toml
│   ├── your-org-http/
│   │   ├── src/your_org/http/
│   │   └── pyproject.toml
│   └── your-org-cli/
│       ├── src/your_org/cli/
│       └── pyproject.toml
├── .github/workflows/
└── README.md

Each sub-package has its own pyproject.toml. They share the your_org namespace via PEP 420 implicit namespace packages (no __init__.py in the namespace root).

Internal Module Guidelines

FilePurposeWhen to include
__init__.pyPublic API surface; re-exports; __version__Always
py.typedPEP 561 typed-package marker (empty)Always
core.pyPrimary class / main logicAlways
config.pySettings dataclass or Pydantic modelWhen configurable
exceptions.pyException hierarchy (YourBaseError → specifics)Always
models.pyData models / DTOs / TypedDictsWhen data-heavy
utils.pyInternal helpers (not part of public API)As needed
types.pyShared TypeVar, TypeAlias, Protocol definitionsWhen complex typing
cli.pyCLI entry points (click/typer)CLI type only
backends/Plugin/strategy patternWhen swappable implementations
_compat.pyPython version compatibility shimsWhen 3.9–3.13 compat needed

7. Versioning Strategy

PEP 440 — The Standard

Canonical form:  N[.N]+[{a|b|rc}N][.postN][.devN]

Examples:
  1.0.0          Stable release
  1.0.0a1        Alpha (pre-release)
  1.0.0b2        Beta
  1.0.0rc1       Release candidate
  1.0.0.post1    Post-release (e.g., packaging fix only)
  1.0.0.dev1     Development snapshot (not for PyPI)

Semantic Versioning (recommended)

MAJOR.MINOR.PATCH

MAJOR: Breaking API change (remove/rename public function/class/arg)
MINOR: New feature, fully backward-compatible
PATCH: Bug fix, no API change

Dynamic versioning with setuptools_scm (recommended for git-tag workflows)

# How it works:
git tag v1.0.0          →  installed version = 1.0.0
git tag v1.1.0          →  installed version = 1.1.0
(commits after tag)     →  version = 1.1.0.post1  (suffix stripped for PyPI)

# In code — NEVER hardcode when using setuptools_scm:
from importlib.metadata import version, PackageNotFoundError
try:
    __version__ = version("your-package")
except PackageNotFoundError:
    __version__ = "0.0.0-dev"    # Fallback for uninstalled dev checkouts

Required pyproject.toml config:

[tool.setuptools_scm]
version_scheme = "post-release"
local_scheme   = "no-local-version"   # Prevents +g<hash> from breaking PyPI uploads

Critical: always set fetch-depth: 0 in every CI checkout step. Without full git history, setuptools_scm cannot find tags and the build version silently falls back to 0.0.0+dev.

Static versioning (flit, hatchling manual, poetry)

# your_package/__init__.py
__version__ = "1.0.0"    # Update this before every release

Version specifier best practices for dependencies

# In [project] dependencies:
"httpx>=0.24"            # Minimum version — PREFERRED for libraries
"httpx>=0.24,<1.0"       # Upper bound only when a known breaking change exists
"httpx==0.27.0"          # Pin exactly ONLY in applications, NOT libraries

# NEVER do this in a library — it breaks dependency resolution for users:
# "httpx~=0.24.0"        # Too tight
# "httpx==0.27.*"        # Fragile

Version bump → release flow

# 1. Update CHANGELOG.md — move [Unreleased] entries to [x.y.z] - YYYY-MM-DD
# 2. Commit the changelog
git add CHANGELOG.md
git commit -m "chore: prepare release vX.Y.Z"
# 3. Tag and push — this triggers publish.yml automatically
git tag vX.Y.Z
git push origin main --tags
# 4. Monitor GitHub Actions → verify on https://pypi.org/project/your-package/

For complete pyproject.toml templates for all four backends, see references/pyproject-toml.md.


Where to Go Next

After understanding decisions and structure:

  1. Set up pyproject.toml → references/pyproject-toml.md All four backend templates (setuptools+scm, hatchling, flit, poetry), full tool configs, py.typed setup, versioning config.

  2. Write your library code → references/library-patterns.md OOP/SOLID principles, type hints (PEP 484/526/544/561), core class design, factory functions, __init__.py, plugin/backend pattern, CLI entry point.

  3. Add tests and code quality → references/testing-quality.md conftest.py, unit/backend/async tests, parametrize, ruff/mypy/pre-commit setup.

  4. Set up CI/CD and publish → references/ci-publishing.md ci.yml, publish.yml with Trusted Publishing (OIDC, no API tokens), CHANGELOG format, release checklist.

  5. Polish for community/OSS → references/community-docs.md README sections, docstring format, CONTRIBUTING, SECURITY, issue templates, anti-patterns table, and master release checklist.

  6. Design backends, config, transport, CLI → references/architecture-patterns.md Backend system (plugin/strategy pattern), Settings dataclass, HTTP transport layer, CLI with click/typer, backend injection rules.

  7. Choose and implement a versioning strategy → references/versioning-strategy.md PEP 440 canonical forms, SemVer rules, pre-release identifiers, setuptools_scm deep-dive, flit static versioning, decision engine (DEFAULT/BEGINNER/MINIMAL).

  8. Govern releases and secure the publish pipeline → references/release-governance.md Branch strategy, branch protection rules, OIDC Trusted Publishing setup, tag author validation in CI, tag format enforcement, full governed publish.yml.

  9. Simplify tooling with Ruff → references/tooling-ruff.md Ruff-only setup replacing black/isort/flake8, mypy config, pre-commit hooks, asyncio_mode=auto (remove @pytest.mark.asyncio), migration guide.

发现问题?提交给管理员复核

评分:

评论 (0)

暂无评论,成为第一个评论者吧!