@sylix/coworker 2.0.11 → 2.0.12

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