@zimezone/z-command 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/README.md +57 -38
  2. package/dist/cli.js +14 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/init.d.ts +1 -7
  5. package/dist/commands/init.d.ts.map +1 -1
  6. package/dist/commands/init.js +101 -23
  7. package/dist/commands/init.js.map +1 -1
  8. package/dist/commands/update.d.ts +11 -0
  9. package/dist/commands/update.d.ts.map +1 -0
  10. package/dist/commands/update.js +88 -0
  11. package/dist/commands/update.js.map +1 -0
  12. package/dist/platforms.d.ts +21 -0
  13. package/dist/platforms.d.ts.map +1 -0
  14. package/dist/platforms.js +137 -0
  15. package/dist/platforms.js.map +1 -0
  16. package/dist/types.d.ts +44 -0
  17. package/dist/types.d.ts.map +1 -0
  18. package/dist/types.js +6 -0
  19. package/dist/types.js.map +1 -0
  20. package/package.json +13 -5
  21. package/templates/agents/api-documenter.agent.md +161 -0
  22. package/templates/agents/architect-review.agent.md +146 -0
  23. package/templates/agents/arm-cortex-expert.agent.md +288 -0
  24. package/templates/agents/backend-architect.agent.md +309 -0
  25. package/templates/agents/backend-security-coder.agent.md +152 -0
  26. package/templates/agents/bash-pro.agent.md +285 -0
  27. package/templates/agents/c-pro.agent.md +35 -0
  28. package/templates/agents/c4-code.agent.md +320 -0
  29. package/templates/agents/c4-component.agent.md +227 -0
  30. package/templates/agents/c4-container.agent.md +248 -0
  31. package/templates/agents/c4-context.agent.md +235 -0
  32. package/templates/agents/conductor-validator.agent.md +245 -0
  33. package/templates/agents/csharp-pro.agent.md +38 -0
  34. package/templates/agents/customer-support.agent.md +148 -0
  35. package/templates/agents/database-admin.agent.md +142 -0
  36. package/templates/agents/database-architect.agent.md +238 -0
  37. package/templates/agents/database-optimizer.agent.md +144 -0
  38. package/templates/agents/debugger.agent.md +30 -0
  39. package/templates/agents/deployment-engineer.agent.md +0 -0
  40. package/templates/agents/devops-troubleshooter.agent.md +138 -0
  41. package/templates/agents/django-pro.agent.md +159 -0
  42. package/templates/agents/docs-architect.agent.md +77 -0
  43. package/templates/agents/dotnet-architect.agent.md +175 -0
  44. package/templates/agents/dx-optimizer.agent.md +63 -0
  45. package/templates/agents/elixir-pro.agent.md +38 -0
  46. package/templates/agents/error-detective.agent.md +32 -0
  47. package/templates/agents/event-sourcing-architect.agent.md +42 -0
  48. package/templates/agents/fastapi-pro.agent.md +171 -0
  49. package/templates/agents/firmware-analyst.agent.md +330 -0
  50. package/templates/agents/frontend-security-coder.agent.md +149 -0
  51. package/templates/agents/haskell-pro.agent.md +37 -0
  52. package/templates/agents/hr-pro.agent.md +105 -0
  53. package/templates/agents/incident-responder.agent.md +190 -0
  54. package/templates/agents/ios-developer.agent.md +198 -0
  55. package/templates/agents/java-pro.agent.md +156 -0
  56. package/templates/agents/javascript-pro.agent.md +35 -0
  57. package/templates/agents/julia-pro.agent.md +187 -0
  58. package/templates/agents/legal-advisor.agent.md +49 -0
  59. package/templates/agents/malware-analyst.agent.md +272 -0
  60. package/templates/agents/mermaid-expert.agent.md +39 -0
  61. package/templates/agents/minecraft-bukkit-pro.agent.md +104 -0
  62. package/templates/agents/mobile-security-coder.agent.md +163 -0
  63. package/templates/agents/monorepo-architect.agent.md +44 -0
  64. package/templates/agents/observability-engineer.agent.md +228 -0
  65. package/templates/agents/performance-engineer.agent.md +167 -0
  66. package/templates/agents/php-pro.agent.md +43 -0
  67. package/templates/agents/posix-shell-pro.agent.md +284 -0
  68. package/templates/agents/quant-analyst.agent.md +32 -0
  69. package/templates/agents/reference-builder.agent.md +167 -0
  70. package/templates/agents/reverse-engineer.agent.md +202 -0
  71. package/templates/agents/risk-manager.agent.md +41 -0
  72. package/templates/agents/ruby-pro.agent.md +35 -0
  73. package/templates/agents/rust-pro.agent.md +156 -0
  74. package/templates/agents/sales-automator.agent.md +35 -0
  75. package/templates/agents/scala-pro.agent.md +60 -0
  76. package/templates/agents/search-specialist.agent.md +59 -0
  77. package/templates/agents/security-auditor.agent.md +138 -0
  78. package/templates/agents/seo-authority-builder.agent.md +116 -0
  79. package/templates/agents/seo-cannibalization-detector.agent.md +103 -0
  80. package/templates/agents/seo-content-auditor.agent.md +63 -0
  81. package/templates/agents/seo-content-planner.agent.md +88 -0
  82. package/templates/agents/seo-content-refresher.agent.md +98 -0
  83. package/templates/agents/seo-content-writer.agent.md +76 -0
  84. package/templates/agents/seo-keyword-strategist.agent.md +75 -0
  85. package/templates/agents/seo-meta-optimizer.agent.md +72 -0
  86. package/templates/agents/seo-snippet-hunter.agent.md +94 -0
  87. package/templates/agents/seo-structure-architect.agent.md +88 -0
  88. package/templates/agents/service-mesh-expert.agent.md +41 -0
  89. package/templates/agents/sql-pro.agent.md +146 -0
  90. package/templates/agents/tdd-orchestrator.agent.md +183 -0
  91. package/templates/agents/temporal-python-pro.agent.md +349 -0
  92. package/templates/agents/terraform-specialist.agent.md +137 -0
  93. package/templates/agents/test-automator.agent.md +203 -0
  94. package/templates/agents/threat-modeling-expert.agent.md +44 -0
  95. package/templates/agents/tutorial-engineer.agent.md +118 -0
  96. package/templates/agents/ui-ux-designer.agent.md +188 -0
  97. package/templates/agents/ui-visual-validator.agent.md +192 -0
  98. package/templates/agents/vector-database-engineer.agent.md +43 -0
  99. package/templates/skills/angular-migration/SKILL.md +410 -0
  100. package/templates/skills/api-design-principles/SKILL.md +528 -0
  101. package/templates/skills/api-design-principles/assets/api-design-checklist.md +155 -0
  102. package/templates/skills/api-design-principles/assets/rest-api-template.py +182 -0
  103. package/templates/skills/api-design-principles/references/graphql-schema-design.md +583 -0
  104. package/templates/skills/api-design-principles/references/rest-best-practices.md +408 -0
  105. package/templates/skills/architecture-decision-records/SKILL.md +428 -0
  106. package/templates/skills/architecture-patterns/SKILL.md +494 -0
  107. package/templates/skills/async-python-patterns/SKILL.md +694 -0
  108. package/templates/skills/auth-implementation-patterns/SKILL.md +634 -0
  109. package/templates/skills/changelog-automation/SKILL.md +552 -0
  110. package/templates/skills/code-review-excellence/SKILL.md +520 -0
  111. package/templates/skills/competitive-landscape/SKILL.md +479 -0
  112. package/templates/skills/context-driven-development/SKILL.md +385 -0
  113. package/templates/skills/cost-optimization/SKILL.md +274 -0
  114. package/templates/skills/cqrs-implementation/SKILL.md +554 -0
  115. package/templates/skills/data-quality-frameworks/SKILL.md +587 -0
  116. package/templates/skills/data-storytelling/SKILL.md +453 -0
  117. package/templates/skills/database-migration/SKILL.md +424 -0
  118. package/templates/skills/dbt-transformation-patterns/SKILL.md +561 -0
  119. package/templates/skills/debugging-strategies/SKILL.md +527 -0
  120. package/templates/skills/defi-protocol-templates/SKILL.md +454 -0
  121. package/templates/skills/dependency-upgrade/SKILL.md +409 -0
  122. package/templates/skills/deployment-pipeline-design/SKILL.md +359 -0
  123. package/templates/skills/distributed-tracing/SKILL.md +438 -0
  124. package/templates/skills/dotnet-backend-patterns/SKILL.md +815 -0
  125. package/templates/skills/dotnet-backend-patterns/assets/repository-template.cs +523 -0
  126. package/templates/skills/dotnet-backend-patterns/assets/service-template.cs +336 -0
  127. package/templates/skills/dotnet-backend-patterns/references/dapper-patterns.md +544 -0
  128. package/templates/skills/dotnet-backend-patterns/references/ef-core-best-practices.md +355 -0
  129. package/templates/skills/e2e-testing-patterns/SKILL.md +547 -0
  130. package/templates/skills/employment-contract-templates/SKILL.md +507 -0
  131. package/templates/skills/error-handling-patterns/SKILL.md +636 -0
  132. package/templates/skills/event-store-design/SKILL.md +437 -0
  133. package/templates/skills/fastapi-templates/SKILL.md +567 -0
  134. package/templates/skills/git-advanced-workflows/SKILL.md +400 -0
  135. package/templates/skills/github-actions-templates/SKILL.md +333 -0
  136. package/templates/skills/go-concurrency-patterns/SKILL.md +655 -0
  137. package/templates/skills/grafana-dashboards/SKILL.md +369 -0
  138. package/templates/skills/helm-chart-scaffolding/SKILL.md +544 -0
  139. package/templates/skills/helm-chart-scaffolding/assets/Chart.yaml.template +42 -0
  140. package/templates/skills/helm-chart-scaffolding/assets/values.yaml.template +185 -0
  141. package/templates/skills/helm-chart-scaffolding/references/chart-structure.md +500 -0
  142. package/templates/skills/helm-chart-scaffolding/scripts/validate-chart.sh +244 -0
  143. package/templates/skills/javascript-testing-patterns/SKILL.md +1025 -0
  144. package/templates/skills/langchain-architecture/SKILL.md +338 -0
  145. package/templates/skills/llm-evaluation/SKILL.md +471 -0
  146. package/templates/skills/microservices-patterns/SKILL.md +595 -0
  147. package/templates/skills/modern-javascript-patterns/SKILL.md +911 -0
  148. package/templates/skills/monorepo-management/SKILL.md +622 -0
  149. package/templates/skills/nextjs-app-router-patterns/SKILL.md +544 -0
  150. package/templates/skills/nodejs-backend-patterns/SKILL.md +1020 -0
  151. package/templates/skills/nx-workspace-patterns/SKILL.md +452 -0
  152. package/templates/skills/openapi-spec-generation/SKILL.md +1028 -0
  153. package/templates/skills/paypal-integration/SKILL.md +467 -0
  154. package/templates/skills/pci-compliance/SKILL.md +466 -0
  155. package/templates/skills/postgresql/SKILL.md +204 -0
  156. package/templates/skills/projection-patterns/SKILL.md +490 -0
  157. package/templates/skills/prometheus-configuration/SKILL.md +392 -0
  158. package/templates/skills/prompt-engineering-patterns/SKILL.md +201 -0
  159. package/templates/skills/prompt-engineering-patterns/assets/few-shot-examples.json +106 -0
  160. package/templates/skills/prompt-engineering-patterns/assets/prompt-template-library.md +246 -0
  161. package/templates/skills/prompt-engineering-patterns/references/chain-of-thought.md +399 -0
  162. package/templates/skills/prompt-engineering-patterns/references/few-shot-learning.md +369 -0
  163. package/templates/skills/prompt-engineering-patterns/references/prompt-optimization.md +414 -0
  164. package/templates/skills/prompt-engineering-patterns/references/prompt-templates.md +470 -0
  165. package/templates/skills/prompt-engineering-patterns/references/system-prompts.md +189 -0
  166. package/templates/skills/prompt-engineering-patterns/scripts/optimize-prompt.py +279 -0
  167. package/templates/skills/python-packaging/SKILL.md +870 -0
  168. package/templates/skills/python-performance-optimization/SKILL.md +869 -0
  169. package/templates/skills/python-testing-patterns/SKILL.md +907 -0
  170. package/templates/skills/rag-implementation/SKILL.md +403 -0
  171. package/templates/skills/react-modernization/SKILL.md +513 -0
  172. package/templates/skills/react-native-architecture/SKILL.md +671 -0
  173. package/templates/skills/react-state-management/SKILL.md +429 -0
  174. package/templates/skills/risk-metrics-calculation/SKILL.md +555 -0
  175. package/templates/skills/rust-async-patterns/SKILL.md +517 -0
  176. package/templates/skills/secrets-management/SKILL.md +346 -0
  177. package/templates/skills/security-requirement-extraction/SKILL.md +677 -0
  178. package/templates/skills/shellcheck-configuration/SKILL.md +454 -0
  179. package/templates/skills/similarity-search-patterns/SKILL.md +558 -0
  180. package/templates/skills/slo-implementation/SKILL.md +329 -0
  181. package/templates/skills/sql-optimization-patterns/SKILL.md +493 -0
  182. package/templates/skills/stripe-integration/SKILL.md +442 -0
  183. package/templates/skills/tailwind-design-system/SKILL.md +666 -0
  184. package/templates/skills/temporal-python-testing/SKILL.md +158 -0
  185. package/templates/skills/temporal-python-testing/resources/integration-testing.md +455 -0
  186. package/templates/skills/temporal-python-testing/resources/local-setup.md +553 -0
  187. package/templates/skills/temporal-python-testing/resources/replay-testing.md +462 -0
  188. package/templates/skills/temporal-python-testing/resources/unit-testing.md +328 -0
  189. package/templates/skills/terraform-module-library/SKILL.md +249 -0
  190. package/templates/skills/terraform-module-library/references/aws-modules.md +63 -0
  191. package/templates/skills/threat-mitigation-mapping/SKILL.md +745 -0
  192. package/templates/skills/track-management/SKILL.md +593 -0
  193. package/templates/skills/typescript-advanced-types/SKILL.md +717 -0
  194. package/templates/skills/ui-ux-pro-max/SKILL.md +352 -0
  195. package/templates/skills/ui-ux-pro-max/data/charts.csv +26 -0
  196. package/templates/skills/ui-ux-pro-max/data/colors.csv +97 -0
  197. package/templates/skills/ui-ux-pro-max/data/icons.csv +101 -0
  198. package/templates/skills/ui-ux-pro-max/data/landing.csv +31 -0
  199. package/templates/skills/ui-ux-pro-max/data/products.csv +97 -0
  200. package/templates/skills/ui-ux-pro-max/data/prompts.csv +24 -0
  201. package/templates/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
  202. package/templates/skills/ui-ux-pro-max/data/styles.csv +59 -0
  203. package/templates/skills/ui-ux-pro-max/data/typography.csv +58 -0
  204. package/templates/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  205. package/templates/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  206. package/templates/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
  207. package/templates/skills/ui-ux-pro-max/scripts/core.py +258 -0
  208. package/templates/skills/ui-ux-pro-max/scripts/design_system.py +547 -0
  209. package/templates/skills/ui-ux-pro-max/scripts/search.py +76 -0
  210. package/templates/skills/uv-package-manager/SKILL.md +831 -0
  211. package/templates/skills/vector-index-tuning/SKILL.md +521 -0
  212. package/templates/skills/wcag-audit-patterns/SKILL.md +555 -0
  213. package/templates/skills/workflow-orchestration-patterns/SKILL.md +316 -0
  214. package/templates/skills/workflow-patterns/SKILL.md +623 -0
  215. package/templates/agents/game-developer.agent.md +0 -57
  216. package/templates/agents/kubernetes-specialist.agent.md +0 -56
  217. package/templates/agents/market-researcher.agent.md +0 -47
@@ -0,0 +1,870 @@
1
+ ---
2
+ name: python-packaging
3
+ description: Create distributable Python packages with proper project structure, setup.py/pyproject.toml, and publishing to PyPI. Use when packaging Python libraries, creating CLI tools, or distributing Python code.
4
+ ---
5
+
6
+ # Python Packaging
7
+
8
+ Comprehensive guide to creating, structuring, and distributing Python packages using modern packaging tools, pyproject.toml, and publishing to PyPI.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - Creating Python libraries for distribution
13
+ - Building command-line tools with entry points
14
+ - Publishing packages to PyPI or private repositories
15
+ - Setting up Python project structure
16
+ - Creating installable packages with dependencies
17
+ - Building wheels and source distributions
18
+ - Versioning and releasing Python packages
19
+ - Creating namespace packages
20
+ - Implementing package metadata and classifiers
21
+
22
+ ## Core Concepts
23
+
24
+ ### 1. Package Structure
25
+ - **Source layout**: `src/package_name/` (recommended)
26
+ - **Flat layout**: `package_name/` (simpler but less flexible)
27
+ - **Package metadata**: pyproject.toml, setup.py, or setup.cfg
28
+ - **Distribution formats**: wheel (.whl) and source distribution (.tar.gz)
29
+
30
+ ### 2. Modern Packaging Standards
31
+ - **PEP 517/518**: Build system requirements
32
+ - **PEP 621**: Metadata in pyproject.toml
33
+ - **PEP 660**: Editable installs
34
+ - **pyproject.toml**: Single source of configuration
35
+
36
+ ### 3. Build Backends
37
+ - **setuptools**: Traditional, widely used
38
+ - **hatchling**: Modern, opinionated
39
+ - **flit**: Lightweight, for pure Python
40
+ - **poetry**: Dependency management + packaging
41
+
42
+ ### 4. Distribution
43
+ - **PyPI**: Python Package Index (public)
44
+ - **TestPyPI**: Testing before production
45
+ - **Private repositories**: JFrog, AWS CodeArtifact, etc.
46
+
47
+ ## Quick Start
48
+
49
+ ### Minimal Package Structure
50
+
51
+ ```
52
+ my-package/
53
+ ├── pyproject.toml
54
+ ├── README.md
55
+ ├── LICENSE
56
+ ├── src/
57
+ │ └── my_package/
58
+ │ ├── __init__.py
59
+ │ └── module.py
60
+ └── tests/
61
+ └── test_module.py
62
+ ```
63
+
64
+ ### Minimal pyproject.toml
65
+
66
+ ```toml
67
+ [build-system]
68
+ requires = ["setuptools>=61.0"]
69
+ build-backend = "setuptools.build_meta"
70
+
71
+ [project]
72
+ name = "my-package"
73
+ version = "0.1.0"
74
+ description = "A short description"
75
+ authors = [{name = "Your Name", email = "you@example.com"}]
76
+ readme = "README.md"
77
+ requires-python = ">=3.8"
78
+ dependencies = [
79
+ "requests>=2.28.0",
80
+ ]
81
+
82
+ [project.optional-dependencies]
83
+ dev = [
84
+ "pytest>=7.0",
85
+ "black>=22.0",
86
+ ]
87
+ ```
88
+
89
+ ## Package Structure Patterns
90
+
91
+ ### Pattern 1: Source Layout (Recommended)
92
+
93
+ ```
94
+ my-package/
95
+ ├── pyproject.toml
96
+ ├── README.md
97
+ ├── LICENSE
98
+ ├── .gitignore
99
+ ├── src/
100
+ │ └── my_package/
101
+ │ ├── __init__.py
102
+ │ ├── core.py
103
+ │ ├── utils.py
104
+ │ └── py.typed # For type hints
105
+ ├── tests/
106
+ │ ├── __init__.py
107
+ │ ├── test_core.py
108
+ │ └── test_utils.py
109
+ └── docs/
110
+ └── index.md
111
+ ```
112
+
113
+ **Advantages:**
114
+ - Prevents accidentally importing from source
115
+ - Cleaner test imports
116
+ - Better isolation
117
+
118
+ **pyproject.toml for source layout:**
119
+ ```toml
120
+ [tool.setuptools.packages.find]
121
+ where = ["src"]
122
+ ```
123
+
124
+ ### Pattern 2: Flat Layout
125
+
126
+ ```
127
+ my-package/
128
+ ├── pyproject.toml
129
+ ├── README.md
130
+ ├── my_package/
131
+ │ ├── __init__.py
132
+ │ └── module.py
133
+ └── tests/
134
+ └── test_module.py
135
+ ```
136
+
137
+ **Simpler but:**
138
+ - Can import package without installing
139
+ - Less professional for libraries
140
+
141
+ ### Pattern 3: Multi-Package Project
142
+
143
+ ```
144
+ project/
145
+ ├── pyproject.toml
146
+ ├── packages/
147
+ │ ├── package-a/
148
+ │ │ └── src/
149
+ │ │ └── package_a/
150
+ │ └── package-b/
151
+ │ └── src/
152
+ │ └── package_b/
153
+ └── tests/
154
+ ```
155
+
156
+ ## Complete pyproject.toml Examples
157
+
158
+ ### Pattern 4: Full-Featured pyproject.toml
159
+
160
+ ```toml
161
+ [build-system]
162
+ requires = ["setuptools>=61.0", "wheel"]
163
+ build-backend = "setuptools.build_meta"
164
+
165
+ [project]
166
+ name = "my-awesome-package"
167
+ version = "1.0.0"
168
+ description = "An awesome Python package"
169
+ readme = "README.md"
170
+ requires-python = ">=3.8"
171
+ license = {text = "MIT"}
172
+ authors = [
173
+ {name = "Your Name", email = "you@example.com"},
174
+ ]
175
+ maintainers = [
176
+ {name = "Maintainer Name", email = "maintainer@example.com"},
177
+ ]
178
+ keywords = ["example", "package", "awesome"]
179
+ classifiers = [
180
+ "Development Status :: 4 - Beta",
181
+ "Intended Audience :: Developers",
182
+ "License :: OSI Approved :: MIT License",
183
+ "Programming Language :: Python :: 3",
184
+ "Programming Language :: Python :: 3.8",
185
+ "Programming Language :: Python :: 3.9",
186
+ "Programming Language :: Python :: 3.10",
187
+ "Programming Language :: Python :: 3.11",
188
+ "Programming Language :: Python :: 3.12",
189
+ ]
190
+
191
+ dependencies = [
192
+ "requests>=2.28.0,<3.0.0",
193
+ "click>=8.0.0",
194
+ "pydantic>=2.0.0",
195
+ ]
196
+
197
+ [project.optional-dependencies]
198
+ dev = [
199
+ "pytest>=7.0.0",
200
+ "pytest-cov>=4.0.0",
201
+ "black>=23.0.0",
202
+ "ruff>=0.1.0",
203
+ "mypy>=1.0.0",
204
+ ]
205
+ docs = [
206
+ "sphinx>=5.0.0",
207
+ "sphinx-rtd-theme>=1.0.0",
208
+ ]
209
+ all = [
210
+ "my-awesome-package[dev,docs]",
211
+ ]
212
+
213
+ [project.urls]
214
+ Homepage = "https://github.com/username/my-awesome-package"
215
+ Documentation = "https://my-awesome-package.readthedocs.io"
216
+ Repository = "https://github.com/username/my-awesome-package"
217
+ "Bug Tracker" = "https://github.com/username/my-awesome-package/issues"
218
+ Changelog = "https://github.com/username/my-awesome-package/blob/main/CHANGELOG.md"
219
+
220
+ [project.scripts]
221
+ my-cli = "my_package.cli:main"
222
+ awesome-tool = "my_package.tools:run"
223
+
224
+ [project.entry-points."my_package.plugins"]
225
+ plugin1 = "my_package.plugins:plugin1"
226
+
227
+ [tool.setuptools]
228
+ package-dir = {"" = "src"}
229
+ zip-safe = false
230
+
231
+ [tool.setuptools.packages.find]
232
+ where = ["src"]
233
+ include = ["my_package*"]
234
+ exclude = ["tests*"]
235
+
236
+ [tool.setuptools.package-data]
237
+ my_package = ["py.typed", "*.pyi", "data/*.json"]
238
+
239
+ # Black configuration
240
+ [tool.black]
241
+ line-length = 100
242
+ target-version = ["py38", "py39", "py310", "py311"]
243
+ include = '\.pyi?$'
244
+
245
+ # Ruff configuration
246
+ [tool.ruff]
247
+ line-length = 100
248
+ target-version = "py38"
249
+
250
+ [tool.ruff.lint]
251
+ select = ["E", "F", "I", "N", "W", "UP"]
252
+
253
+ # MyPy configuration
254
+ [tool.mypy]
255
+ python_version = "3.8"
256
+ warn_return_any = true
257
+ warn_unused_configs = true
258
+ disallow_untyped_defs = true
259
+
260
+ # Pytest configuration
261
+ [tool.pytest.ini_options]
262
+ testpaths = ["tests"]
263
+ python_files = ["test_*.py"]
264
+ addopts = "-v --cov=my_package --cov-report=term-missing"
265
+
266
+ # Coverage configuration
267
+ [tool.coverage.run]
268
+ source = ["src"]
269
+ omit = ["*/tests/*"]
270
+
271
+ [tool.coverage.report]
272
+ exclude_lines = [
273
+ "pragma: no cover",
274
+ "def __repr__",
275
+ "raise AssertionError",
276
+ "raise NotImplementedError",
277
+ ]
278
+ ```
279
+
280
+ ### Pattern 5: Dynamic Versioning
281
+
282
+ ```toml
283
+ [build-system]
284
+ requires = ["setuptools>=61.0", "setuptools-scm>=8.0"]
285
+ build-backend = "setuptools.build_meta"
286
+
287
+ [project]
288
+ name = "my-package"
289
+ dynamic = ["version"]
290
+ description = "Package with dynamic version"
291
+
292
+ [tool.setuptools.dynamic]
293
+ version = {attr = "my_package.__version__"}
294
+
295
+ # Or use setuptools-scm for git-based versioning
296
+ [tool.setuptools_scm]
297
+ write_to = "src/my_package/_version.py"
298
+ ```
299
+
300
+ **In __init__.py:**
301
+ ```python
302
+ # src/my_package/__init__.py
303
+ __version__ = "1.0.0"
304
+
305
+ # Or with setuptools-scm
306
+ from importlib.metadata import version
307
+ __version__ = version("my-package")
308
+ ```
309
+
310
+ ## Command-Line Interface (CLI) Patterns
311
+
312
+ ### Pattern 6: CLI with Click
313
+
314
+ ```python
315
+ # src/my_package/cli.py
316
+ import click
317
+
318
+ @click.group()
319
+ @click.version_option()
320
+ def cli():
321
+ """My awesome CLI tool."""
322
+ pass
323
+
324
+ @cli.command()
325
+ @click.argument("name")
326
+ @click.option("--greeting", default="Hello", help="Greeting to use")
327
+ def greet(name: str, greeting: str):
328
+ """Greet someone."""
329
+ click.echo(f"{greeting}, {name}!")
330
+
331
+ @cli.command()
332
+ @click.option("--count", default=1, help="Number of times to repeat")
333
+ def repeat(count: int):
334
+ """Repeat a message."""
335
+ for i in range(count):
336
+ click.echo(f"Message {i + 1}")
337
+
338
+ def main():
339
+ """Entry point for CLI."""
340
+ cli()
341
+
342
+ if __name__ == "__main__":
343
+ main()
344
+ ```
345
+
346
+ **Register in pyproject.toml:**
347
+ ```toml
348
+ [project.scripts]
349
+ my-tool = "my_package.cli:main"
350
+ ```
351
+
352
+ **Usage:**
353
+ ```bash
354
+ pip install -e .
355
+ my-tool greet World
356
+ my-tool greet Alice --greeting="Hi"
357
+ my-tool repeat --count=3
358
+ ```
359
+
360
+ ### Pattern 7: CLI with argparse
361
+
362
+ ```python
363
+ # src/my_package/cli.py
364
+ import argparse
365
+ import sys
366
+
367
+ def main():
368
+ """Main CLI entry point."""
369
+ parser = argparse.ArgumentParser(
370
+ description="My awesome tool",
371
+ prog="my-tool"
372
+ )
373
+
374
+ parser.add_argument(
375
+ "--version",
376
+ action="version",
377
+ version="%(prog)s 1.0.0"
378
+ )
379
+
380
+ subparsers = parser.add_subparsers(dest="command", help="Commands")
381
+
382
+ # Add subcommand
383
+ process_parser = subparsers.add_parser("process", help="Process data")
384
+ process_parser.add_argument("input_file", help="Input file path")
385
+ process_parser.add_argument(
386
+ "--output", "-o",
387
+ default="output.txt",
388
+ help="Output file path"
389
+ )
390
+
391
+ args = parser.parse_args()
392
+
393
+ if args.command == "process":
394
+ process_data(args.input_file, args.output)
395
+ else:
396
+ parser.print_help()
397
+ sys.exit(1)
398
+
399
+ def process_data(input_file: str, output_file: str):
400
+ """Process data from input to output."""
401
+ print(f"Processing {input_file} -> {output_file}")
402
+
403
+ if __name__ == "__main__":
404
+ main()
405
+ ```
406
+
407
+ ## Building and Publishing
408
+
409
+ ### Pattern 8: Build Package Locally
410
+
411
+ ```bash
412
+ # Install build tools
413
+ pip install build twine
414
+
415
+ # Build distribution
416
+ python -m build
417
+
418
+ # This creates:
419
+ # dist/
420
+ # my-package-1.0.0.tar.gz (source distribution)
421
+ # my_package-1.0.0-py3-none-any.whl (wheel)
422
+
423
+ # Check the distribution
424
+ twine check dist/*
425
+ ```
426
+
427
+ ### Pattern 9: Publishing to PyPI
428
+
429
+ ```bash
430
+ # Install publishing tools
431
+ pip install twine
432
+
433
+ # Test on TestPyPI first
434
+ twine upload --repository testpypi dist/*
435
+
436
+ # Install from TestPyPI to test
437
+ pip install --index-url https://test.pypi.org/simple/ my-package
438
+
439
+ # If all good, publish to PyPI
440
+ twine upload dist/*
441
+ ```
442
+
443
+ **Using API tokens (recommended):**
444
+ ```bash
445
+ # Create ~/.pypirc
446
+ [distutils]
447
+ index-servers =
448
+ pypi
449
+ testpypi
450
+
451
+ [pypi]
452
+ username = __token__
453
+ password = pypi-...your-token...
454
+
455
+ [testpypi]
456
+ username = __token__
457
+ password = pypi-...your-test-token...
458
+ ```
459
+
460
+ ### Pattern 10: Automated Publishing with GitHub Actions
461
+
462
+ ```yaml
463
+ # .github/workflows/publish.yml
464
+ name: Publish to PyPI
465
+
466
+ on:
467
+ release:
468
+ types: [created]
469
+
470
+ jobs:
471
+ publish:
472
+ runs-on: ubuntu-latest
473
+
474
+ steps:
475
+ - uses: actions/checkout@v3
476
+
477
+ - name: Set up Python
478
+ uses: actions/setup-python@v4
479
+ with:
480
+ python-version: "3.11"
481
+
482
+ - name: Install dependencies
483
+ run: |
484
+ pip install build twine
485
+
486
+ - name: Build package
487
+ run: python -m build
488
+
489
+ - name: Check package
490
+ run: twine check dist/*
491
+
492
+ - name: Publish to PyPI
493
+ env:
494
+ TWINE_USERNAME: __token__
495
+ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
496
+ run: twine upload dist/*
497
+ ```
498
+
499
+ ## Advanced Patterns
500
+
501
+ ### Pattern 11: Including Data Files
502
+
503
+ ```toml
504
+ [tool.setuptools.package-data]
505
+ my_package = [
506
+ "data/*.json",
507
+ "templates/*.html",
508
+ "static/css/*.css",
509
+ "py.typed",
510
+ ]
511
+ ```
512
+
513
+ **Accessing data files:**
514
+ ```python
515
+ # src/my_package/loader.py
516
+ from importlib.resources import files
517
+ import json
518
+
519
+ def load_config():
520
+ """Load configuration from package data."""
521
+ config_file = files("my_package").joinpath("data/config.json")
522
+ with config_file.open() as f:
523
+ return json.load(f)
524
+
525
+ # Python 3.9+
526
+ from importlib.resources import files
527
+
528
+ data = files("my_package").joinpath("data/file.txt").read_text()
529
+ ```
530
+
531
+ ### Pattern 12: Namespace Packages
532
+
533
+ **For large projects split across multiple repositories:**
534
+
535
+ ```
536
+ # Package 1: company-core
537
+ company/
538
+ └── core/
539
+ ├── __init__.py
540
+ └── models.py
541
+
542
+ # Package 2: company-api
543
+ company/
544
+ └── api/
545
+ ├── __init__.py
546
+ └── routes.py
547
+ ```
548
+
549
+ **Do NOT include __init__.py in the namespace directory (company/):**
550
+
551
+ ```toml
552
+ # company-core/pyproject.toml
553
+ [project]
554
+ name = "company-core"
555
+
556
+ [tool.setuptools.packages.find]
557
+ where = ["."]
558
+ include = ["company.core*"]
559
+
560
+ # company-api/pyproject.toml
561
+ [project]
562
+ name = "company-api"
563
+
564
+ [tool.setuptools.packages.find]
565
+ where = ["."]
566
+ include = ["company.api*"]
567
+ ```
568
+
569
+ **Usage:**
570
+ ```python
571
+ # Both packages can be imported under same namespace
572
+ from company.core import models
573
+ from company.api import routes
574
+ ```
575
+
576
+ ### Pattern 13: C Extensions
577
+
578
+ ```toml
579
+ [build-system]
580
+ requires = ["setuptools>=61.0", "wheel", "Cython>=0.29"]
581
+ build-backend = "setuptools.build_meta"
582
+
583
+ [tool.setuptools]
584
+ ext-modules = [
585
+ {name = "my_package.fast_module", sources = ["src/fast_module.c"]},
586
+ ]
587
+ ```
588
+
589
+ **Or with setup.py:**
590
+ ```python
591
+ # setup.py
592
+ from setuptools import setup, Extension
593
+
594
+ setup(
595
+ ext_modules=[
596
+ Extension(
597
+ "my_package.fast_module",
598
+ sources=["src/fast_module.c"],
599
+ include_dirs=["src/include"],
600
+ )
601
+ ]
602
+ )
603
+ ```
604
+
605
+ ## Version Management
606
+
607
+ ### Pattern 14: Semantic Versioning
608
+
609
+ ```python
610
+ # src/my_package/__init__.py
611
+ __version__ = "1.2.3"
612
+
613
+ # Semantic versioning: MAJOR.MINOR.PATCH
614
+ # MAJOR: Breaking changes
615
+ # MINOR: New features (backward compatible)
616
+ # PATCH: Bug fixes
617
+ ```
618
+
619
+ **Version constraints in dependencies:**
620
+ ```toml
621
+ dependencies = [
622
+ "requests>=2.28.0,<3.0.0", # Compatible range
623
+ "click~=8.1.0", # Compatible release (~= 8.1.0 means >=8.1.0,<8.2.0)
624
+ "pydantic>=2.0", # Minimum version
625
+ "numpy==1.24.3", # Exact version (avoid if possible)
626
+ ]
627
+ ```
628
+
629
+ ### Pattern 15: Git-Based Versioning
630
+
631
+ ```toml
632
+ [build-system]
633
+ requires = ["setuptools>=61.0", "setuptools-scm>=8.0"]
634
+ build-backend = "setuptools.build_meta"
635
+
636
+ [project]
637
+ name = "my-package"
638
+ dynamic = ["version"]
639
+
640
+ [tool.setuptools_scm]
641
+ write_to = "src/my_package/_version.py"
642
+ version_scheme = "post-release"
643
+ local_scheme = "dirty-tag"
644
+ ```
645
+
646
+ **Creates versions like:**
647
+ - `1.0.0` (from git tag)
648
+ - `1.0.1.dev3+g1234567` (3 commits after tag)
649
+
650
+ ## Testing Installation
651
+
652
+ ### Pattern 16: Editable Install
653
+
654
+ ```bash
655
+ # Install in development mode
656
+ pip install -e .
657
+
658
+ # With optional dependencies
659
+ pip install -e ".[dev]"
660
+ pip install -e ".[dev,docs]"
661
+
662
+ # Now changes to source code are immediately reflected
663
+ ```
664
+
665
+ ### Pattern 17: Testing in Isolated Environment
666
+
667
+ ```bash
668
+ # Create virtual environment
669
+ python -m venv test-env
670
+ source test-env/bin/activate # Linux/Mac
671
+ # test-env\Scripts\activate # Windows
672
+
673
+ # Install package
674
+ pip install dist/my_package-1.0.0-py3-none-any.whl
675
+
676
+ # Test it works
677
+ python -c "import my_package; print(my_package.__version__)"
678
+
679
+ # Test CLI
680
+ my-tool --help
681
+
682
+ # Cleanup
683
+ deactivate
684
+ rm -rf test-env
685
+ ```
686
+
687
+ ## Documentation
688
+
689
+ ### Pattern 18: README.md Template
690
+
691
+ ```markdown
692
+ # My Package
693
+
694
+ [![PyPI version](https://badge.fury.io/py/my-package.svg)](https://pypi.org/project/my-package/)
695
+ [![Python versions](https://img.shields.io/pypi/pyversions/my-package.svg)](https://pypi.org/project/my-package/)
696
+ [![Tests](https://github.com/username/my-package/workflows/Tests/badge.svg)](https://github.com/username/my-package/actions)
697
+
698
+ Brief description of your package.
699
+
700
+ ## Installation
701
+
702
+ ```bash
703
+ pip install my-package
704
+ ```
705
+
706
+ ## Quick Start
707
+
708
+ ```python
709
+ from my_package import something
710
+
711
+ result = something.do_stuff()
712
+ ```
713
+
714
+ ## Features
715
+
716
+ - Feature 1
717
+ - Feature 2
718
+ - Feature 3
719
+
720
+ ## Documentation
721
+
722
+ Full documentation: https://my-package.readthedocs.io
723
+
724
+ ## Development
725
+
726
+ ```bash
727
+ git clone https://github.com/username/my-package.git
728
+ cd my-package
729
+ pip install -e ".[dev]"
730
+ pytest
731
+ ```
732
+
733
+ ## License
734
+
735
+ MIT
736
+ ```
737
+
738
+ ## Common Patterns
739
+
740
+ ### Pattern 19: Multi-Architecture Wheels
741
+
742
+ ```yaml
743
+ # .github/workflows/wheels.yml
744
+ name: Build wheels
745
+
746
+ on: [push, pull_request]
747
+
748
+ jobs:
749
+ build_wheels:
750
+ name: Build wheels on ${{ matrix.os }}
751
+ runs-on: ${{ matrix.os }}
752
+ strategy:
753
+ matrix:
754
+ os: [ubuntu-latest, windows-latest, macos-latest]
755
+
756
+ steps:
757
+ - uses: actions/checkout@v3
758
+
759
+ - name: Build wheels
760
+ uses: pypa/cibuildwheel@v2.16.2
761
+
762
+ - uses: actions/upload-artifact@v3
763
+ with:
764
+ path: ./wheelhouse/*.whl
765
+ ```
766
+
767
+ ### Pattern 20: Private Package Index
768
+
769
+ ```bash
770
+ # Install from private index
771
+ pip install my-package --index-url https://private.pypi.org/simple/
772
+
773
+ # Or add to pip.conf
774
+ [global]
775
+ index-url = https://private.pypi.org/simple/
776
+ extra-index-url = https://pypi.org/simple/
777
+
778
+ # Upload to private index
779
+ twine upload --repository-url https://private.pypi.org/ dist/*
780
+ ```
781
+
782
+ ## File Templates
783
+
784
+ ### .gitignore for Python Packages
785
+
786
+ ```gitignore
787
+ # Build artifacts
788
+ build/
789
+ dist/
790
+ *.egg-info/
791
+ *.egg
792
+ .eggs/
793
+
794
+ # Python
795
+ __pycache__/
796
+ *.py[cod]
797
+ *$py.class
798
+ *.so
799
+
800
+ # Virtual environments
801
+ venv/
802
+ env/
803
+ ENV/
804
+
805
+ # IDE
806
+ .vscode/
807
+ .idea/
808
+ *.swp
809
+
810
+ # Testing
811
+ .pytest_cache/
812
+ .coverage
813
+ htmlcov/
814
+
815
+ # Distribution
816
+ *.whl
817
+ *.tar.gz
818
+ ```
819
+
820
+ ### MANIFEST.in
821
+
822
+ ```
823
+ # MANIFEST.in
824
+ include README.md
825
+ include LICENSE
826
+ include pyproject.toml
827
+
828
+ recursive-include src/my_package/data *.json
829
+ recursive-include src/my_package/templates *.html
830
+ recursive-exclude * __pycache__
831
+ recursive-exclude * *.py[co]
832
+ ```
833
+
834
+ ## Checklist for Publishing
835
+
836
+ - [ ] Code is tested (pytest passing)
837
+ - [ ] Documentation is complete (README, docstrings)
838
+ - [ ] Version number updated
839
+ - [ ] CHANGELOG.md updated
840
+ - [ ] License file included
841
+ - [ ] pyproject.toml is complete
842
+ - [ ] Package builds without errors
843
+ - [ ] Installation tested in clean environment
844
+ - [ ] CLI tools work (if applicable)
845
+ - [ ] PyPI metadata is correct (classifiers, keywords)
846
+ - [ ] GitHub repository linked
847
+ - [ ] Tested on TestPyPI first
848
+ - [ ] Git tag created for release
849
+
850
+ ## Resources
851
+
852
+ - **Python Packaging Guide**: https://packaging.python.org/
853
+ - **PyPI**: https://pypi.org/
854
+ - **TestPyPI**: https://test.pypi.org/
855
+ - **setuptools documentation**: https://setuptools.pypa.io/
856
+ - **build**: https://pypa-build.readthedocs.io/
857
+ - **twine**: https://twine.readthedocs.io/
858
+
859
+ ## Best Practices Summary
860
+
861
+ 1. **Use src/ layout** for cleaner package structure
862
+ 2. **Use pyproject.toml** for modern packaging
863
+ 3. **Pin build dependencies** in build-system.requires
864
+ 4. **Version appropriately** with semantic versioning
865
+ 5. **Include all metadata** (classifiers, URLs, etc.)
866
+ 6. **Test installation** in clean environments
867
+ 7. **Use TestPyPI** before publishing to PyPI
868
+ 8. **Document thoroughly** with README and docstrings
869
+ 9. **Include LICENSE** file
870
+ 10. **Automate publishing** with CI/CD