-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathpyproject.toml
More file actions
413 lines (348 loc) · 11.4 KB
/
pyproject.toml
File metadata and controls
413 lines (348 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"
[project]
name = "mellea"
version = "0.3.2"
authors = [
{ name = "Mellea Contributors", email = "melleaadmin@ibm.com" },
]
description = "mellea is a library for writing generative programs"
readme = "README.md"
requires-python = ">=3.11"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
]
dependencies = [
"pydantic",
"openai",
"jinja2",
"ollama>=0.5.1",
"requests>=2.32.3",
"typer",
"click<8.2.0", # Newer versions will cause errors with --help in typer CLIs.
"mistletoe>=1.4.0",
"pillow", # Needed for Intrinsics (HF and OpenAI Backends).
"math_verify", # Needed for Majority Voting Sampling Strategies.
"rouge_score", # Needed for Majority Voting Sampling Strategies.
]
[project.scripts]
m = "cli.m:cli"
[project.optional-dependencies]
# Install optional features: pip install "mellea[all]" or uv sync --all-extras
# Backend integrations
hf = [
"accelerate>=1.9.0",
"datasets>=4.0.0",
"llguidance",
"peft>=0.18.1", # Native aLoRA support added in PEFT 0.18.0
"transformers>=4.53.2,<5",
"trl==0.19.1",
"xgrammar", # Necessary for granite_common intrinsics.
"huggingface-hub>=0.33.4",
]
vllm = [
"vllm>=0.13.0; sys_platform != 'darwin'",
"numpy<=2.2", # ImportError: Numba needs NumPy 2.2 or less. Got NumPy 2.4.
]
litellm = [
"litellm>=1.76",
"boto3", # for Bedrock support.
]
watsonx = [
"ibm-watsonx-ai>=1.3.31",
]
# Feature integrations
tools = [
"smolagents>=1.0.0",
"langchain-core>=1.2.7",
]
telemetry = [
"opentelemetry-api>=1.20.0",
"opentelemetry-sdk>=1.20.0",
"opentelemetry-exporter-otlp>=1.20.0",
"opentelemetry-exporter-prometheus>=0.40b0",
"opentelemetry-distro>=0.59b0",
]
docling = [
"docling>=2.45.0",
]
granite_retriever = [
"sentence-transformers",
"pyarrow",
"elasticsearch>=8.0.0,<9.0.0",
]
# Infrastructure
server = [
"uvicorn",
"fastapi",
]
sandbox = [
"llm-sandbox[docker]>=0.3.23",
]
backends = ["mellea[watsonx,hf,vllm,litellm]"]
hooks = [
"cpex>=0.1.0.dev10; python_version >= '3.11'",
"grpcio>=1.78.0",
]
all = ["mellea[backends,docling,tools,telemetry,server,sandbox,granite_retriever,hooks]"]
[dependency-groups]
# Development groups: uv sync --all-groups
# Code quality
lint = [
"ruff>=0.11.6",
"isort>=6.0.0",
"pre-commit>=4.2.0",
"pylint>=3.3.4",
]
test = [
"pytest",
"pytest-asyncio",
"pytest-cov>=6.0.0",
"pytest-timeout", # For test suite timeout configuration
"pytest-recording", # For blocking network access and using canned server responses
"pytest-xdist>=3.8.0", # For concurrent test execution (uv run pytest -n auto test/)
"psutil", # For test infrastructure: RAM detection in conftest.py
"nbmake>=1.5.5", # Notebook testing
"sentencepiece==0.2.1", # Necessary for test_huggingface_tools test because of Mistral model
"jsonschema",
# Example-only dependencies (run via pytest)
"langchain-community>=0.3.0",
"ddgs>=9.0.0", # Required by DuckDuckGoSearchResults in langchain-community
]
typecheck = [
"mypy>=1.17.0",
"types-requests",
"types-tqdm",
]
build = [
"pdm>=2.24.0",
]
release = [
"python-semantic-release~=7.32",
]
# Convenience: includes all dev dependencies (used by default with uv run)
dev = [
{include-group = "lint"},
{include-group = "test"},
{include-group = "typecheck"},
{include-group = "build"},
{include-group = "release"},
"griffe>=2.0.0",
"mdxify>=0.2.37",
"poethepoet>=0.42.1",
]
# Documentation and notebooks
notebook = [
"ipykernel>=6.29.5",
"ipython>=8.36.0",
"jupyter>=1.1.1",
]
docs = [
"sphinx_rtd_theme",
"sphinx-autodoc-typehints",
"sphinx_mdinclude",
]
# -----------------------------
# poethepoet - Task Runner
# -----------------------------
# Run tasks with: uv run poe <task>
[tool.poe.tasks]
[tool.poe.tasks.apidocs]
cmd = "python tooling/docs-autogen/build.py"
help = "Generate + decorate API docs (version auto-detected from pyproject.toml)"
[tool.poe.tasks.apidocs-clean]
shell = "rm -rf docs/docs/api docs/docs/api-reference.mdx .venv-docs-autogen"
help = "Remove all generated API docs and build artefacts"
[tool.poe.tasks.apidocs-validate]
cmd = "python tooling/docs-autogen/validate.py docs/docs/api --coverage-threshold 80"
help = "Validate generated API docs (coverage, MDX syntax, links)"
[tool.poe.tasks.apidocs-test]
cmd = "pytest tooling/docs-autogen/"
help = "Run docs tooling unit tests"
[tool.poe.tasks.apidocs-orphans]
cmd = "python tooling/docs-autogen/audit_coverage.py --orphans"
help = "Find MDX files not referenced in docs/mint.json navigation"
[tool.poe.tasks.apidocs-quality]
cmd = "python tooling/docs-autogen/audit_coverage.py --quality"
help = "Audit docstring quality for documented public symbols including methods (use --no-methods to skip class methods)"
[tool.poe.tasks.apidocs-preview]
shell = """
set -e
PREVIEW_DIR=/tmp/mellea-preview
python tooling/docs-autogen/build.py --output-dir "$PREVIEW_DIR/api"
python tooling/docs-autogen/audit_coverage.py --quality \
--docs-dir "$PREVIEW_DIR/api"
"""
help = "Generate fresh API docs to /tmp/mellea-preview and audit quality."
# -----------------------------
# Ruff - Linting and Formatting
# -----------------------------
[tool.ruff]
target-version = "py311"
respect-gitignore = true
[tool.ruff.format]
skip-magic-trailing-comma = true
[tool.ruff.lint]
select = [
"C", # flake8-comprehensions
"C9", # mccabe
"D", # flake8-docstrings
"E", # pycodestyle errors (default)
"F", # pyflakes (default)
"I", # isort
"PD", # pandas-vet
"PIE", # pie
"Q", # flake8-quotes
"RUF", # Enable all ruff-specific checks
"S307", # eval
"W", # pycodestyle warnings
"ASYNC", # async
"UP", # pyupgrade
# "T20", # (disallow print statements) keep debugging statements out of the codebase
]
ignore = [
"RUF001", # ambiguous unicode characters (these occur in examples)
"C408", # Unnecessary `dict()` call (rewrite as a literal)
"E501", # Line too long, handled by ruff formatter
"F401", # imported but unused; consider using `importlib.util.find_spec` to test for
"F811", # redefinition of the same function
"PL", # Pylint
"RUF012", # Mutable Class Attributes
"C901", # Complexity warnings
]
[tool.ruff.lint.pydocstyle]
convention = "google"
[tool.ruff.lint.mccabe]
max-complexity = 20
[tool.ruff.lint.isort]
combine-as-imports = true
split-on-trailing-comma = false
[tool.ruff.lint.per-file-ignores]
# E402: Module level import not at top of file
# Intentional in examples (pedagogical structure) and tests (pytestmark before imports)
# D: Docstring errors
# Not required in examples, tests, and notebooks (core mellea/ has complete docstrings)
"docs/**/*.py" = ["E402", "D"]
"docs/**/*.ipynb" = ["D"]
"test/**/*.py" = ["E402", "D"]
"cli/**/*.py" = ["D"]
"tooling/**/*.py" = ["D"]
# -----------------------------
# MyPy - Type Checking
# -----------------------------
[tool.mypy]
install_types = true
non_interactive = true
disable_error_code = ["empty-body", "import-untyped"]
python_version = "3.11"
[[tool.mypy.overrides]]
# Keep import-not-found suppressed for optional dependencies
module = "docs.*"
disable_error_code = [
"import-not-found",
]
[[tool.mypy.overrides]]
# vLLM is an optional backend that doesn't work on macOS
module = "mellea.backends.vllm"
disable_error_code = [
"import-not-found",
]
# -----------------------------
# Codespell - Spell Checking
# -----------------------------
[tool.codespell]
ignore-words-list = 'mellea,hashi,noo,Asai,asai,nd,mot,rouge,Rouge,Strat,Wight,Aer,aer'
check-filenames = true
check-hidden = false
regex = "(?<![a-z])[a-z'`]+|[A-Z][a-z'`]*|[a-z]+'[a-z]*|[a-z]+(?=[_-])|[a-z]+(?=[A-Z])|\\d+"
skip = 'requirements.txt,uv.lock,CHANGELOG.md,test/formatters/granite/testdata/test_canned_output/model_output/*.json'
# -----------------------------
# Pytest - Testing Framework
# -----------------------------
[tool.pytest.ini_options]
testpaths = ["test", "docs"] # Run test/ first (fail fast), then docs/
markers = [
# Backend markers
"ollama: Tests requiring Ollama backend (local, light)",
"openai: Tests requiring OpenAI API (requires API key)",
"watsonx: Tests requiring Watsonx API (requires API key)",
"huggingface: Tests requiring HuggingFace backend (local, heavy)",
"vllm: Tests requiring vLLM backend (local, GPU required)",
"litellm: Tests requiring LiteLLM backend",
# Capability markers
"requires_api_key: Tests requiring external API keys",
"requires_gpu: Tests requiring GPU",
"requires_heavy_ram: Tests requiring 48GB+ RAM",
"qualitative: Non-deterministic quality tests",
"slow: Tests taking >1 minute (e.g., multi-step pipelines like researcher)",
# Composite markers
"llm: Tests that make LLM calls (needs at least Ollama)",
]
asyncio_mode = "auto" # Don't require explicitly marking async tests.
addopts = [
# Skip slow tests by default (use pytest without -m to include them)
"-m", "not slow",
# Run qualitative tests by default (use -m "not qualitative" for fast tests)
"--cov=mellea",
"--cov=cli",
"--cov-report=html",
"--cov-report=json",
# Set timeout to 15 minutes for full test suite
"--timeout=900",
]
filterwarnings = [
# Show each deprecation warning only once per session
"once::DeprecationWarning",
"once::PendingDeprecationWarning",
# Deduplicate noisy Pydantic serialization warnings
"once:.*PydanticSerializationUnexpectedValue.*:UserWarning",
# Ignore SWIG C/C++ binding warnings from vLLM (Python 3.12 issue)
"ignore:builtin type SwigPyPacked has no __module__ attribute:DeprecationWarning",
"ignore:builtin type SwigPyObject has no __module__ attribute:DeprecationWarning",
"ignore:builtin type swigvarlink has no __module__ attribute:DeprecationWarning",
# Keep Watsonx deprecation visible (important for migration)
"default:.*Watsonx Backend is deprecated.*:DeprecationWarning",
]
# -----------------------------
# Coverage - Code Coverage
# -----------------------------
[tool.coverage.run]
branch = true # Measure branch coverage, not just line coverage
source = ["mellea", "cli"]
omit = [
"*/tests/*",
"*/test_*.py",
"*/__pycache__/*",
"*/scratchpad/*",
]
[tool.coverage.report]
show_missing = true
precision = 2
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"@abstractmethod",
"\\.\\.\\.", # Ellipsis in function bodies
]
[tool.coverage.html]
directory = "htmlcov"
# -----------------------------
# Semantic Release - Versioning
# -----------------------------
[tool.semantic_release]
# for default values check:
# https://github.com/python-semantic-release/python-semantic-release/blob/v7.32.2/semantic_release/defaults.cfg
version_source = "tag_only"
branch = "main"
# configure types which should trigger minor and patch version bumps respectively
# (note that they must be a subset of the configured allowed types):
parser_angular_allowed_types = "build,chore,ci,docs,feat,fix,perf,style,refactor,test,release"
parser_angular_minor_types = "release"
parser_angular_patch_types = "fix,perf,feat"