-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnoxfile.py
More file actions
613 lines (463 loc) · 17 KB
/
noxfile.py
File metadata and controls
613 lines (463 loc) · 17 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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
"""Nox configuration for folder2md4llms with UV optimization and environment reuse.
This configuration is designed to:
1. Use UV for all dependency management (10-100x faster than pip)
2. Maximize environment reuse to minimize disk space and setup time
3. Group sessions by dependency requirements for optimal sharing
4. Provide comprehensive testing across Python versions
5. Integrate seamlessly with existing Make workflow
"""
from pathlib import Path
import nox
# =============================================================================
# Configuration
# =============================================================================
# Use UV as the default backend for all sessions (much faster than pip)
nox.options.default_venv_backend = "uv"
# Enable environment reuse by default to minimize space and setup time
nox.options.reuse_existing_virtualenvs = True
# Supported Python versions (matches GitHub Actions matrix)
PYTHON_VERSIONS = ["3.11", "3.12", "3.13"]
LATEST_PYTHON = "3.13"
# Project paths
SRC_DIR = "src"
TESTS_DIR = "tests"
DOCS_DIR = "docs"
# =============================================================================
# Dependency Group Helpers
# =============================================================================
def install_base_deps(session):
"""Install base dependencies using UV sync for maximum speed."""
session.log("📦 Installing base dependencies with UV...")
session.run("uv", "sync", "--group", "dev", "--no-install-project")
def install_with_group(session, group):
"""Install dependencies for a specific group using UV."""
session.log(f"📦 Installing {group} dependencies with UV...")
session.run("uv", "sync", "--group", group)
def install_minimal_deps(session):
"""Install only minimal dependencies needed for basic functionality."""
session.log("📦 Installing minimal dependencies...")
session.run("uv", "sync", "--no-group", "dev")
def install_project_editable(session):
"""Install the project in editable mode."""
session.run("uv", "pip", "install", "-e", ".")
# =============================================================================
# Core Testing Sessions (Shared Environment: test-base)
# =============================================================================
@nox.session(python=PYTHON_VERSIONS, reuse_venv=True)
def test(session):
"""Run the full test suite across Python versions.
Environment: Shared across Python versions for efficiency.
Dependencies: Core testing stack (pytest, coverage, etc.)
Usage:
nox -s test # All Python versions
nox -s "test-3.11" # Specific Python version
nox -s test -- tests/test_security.py # Specific test file
"""
install_base_deps(session)
install_project_editable(session)
# Use pytest with coverage and parallel execution
args = [
"uv",
"run",
"pytest",
"tests/",
"--cov=folder2md4llms",
"--cov-report=term-missing",
"-n",
"auto", # Parallel execution
"--maxfail=10", # Stop after 10 failures
"--tb=short",
]
if session.posargs:
args.extend(session.posargs)
session.run(*args)
@nox.session(reuse_venv=True)
def test_minimal(session):
"""Test with minimal dependencies to ensure core functionality works.
Environment: Minimal dependencies only.
Purpose: Verify the package works without optional dependencies.
"""
install_minimal_deps(session)
install_project_editable(session)
# Basic test run without optional features
session.run(
"uv",
"run",
"pytest",
"tests/",
"-k",
"not (tiktoken or optional)", # Skip tests requiring optional deps
"--tb=short",
)
@nox.session(reuse_venv=True)
def smoke(session):
"""Quick smoke tests for rapid feedback during development.
Environment: Reuses test environment.
Purpose: Fast validation of core functionality.
"""
install_base_deps(session)
install_project_editable(session)
# Run only fast, essential tests
session.run(
"uv",
"run",
"pytest",
"tests/test_security.py", # Security is critical
"tests/test_cli.py", # CLI functionality
"-v",
"--tb=short",
)
# =============================================================================
# Quality Assurance Sessions (Shared Environment: qa-base)
# =============================================================================
@nox.session(reuse_venv=True)
def lint(session):
"""Run ruff linting checks.
Environment: Shared QA environment with all quality tools.
Purpose: Code quality and style enforcement.
"""
install_base_deps(session)
session.log("🔍 Running ruff linting...")
session.run("uv", "run", "ruff", "check", SRC_DIR, TESTS_DIR)
@nox.session(reuse_venv=True)
def format(session):
"""Format code with ruff.
Environment: Reuses QA environment (ruff already installed).
Purpose: Automatic code formatting.
"""
install_base_deps(session)
session.log("🎨 Formatting code with ruff...")
session.run("uv", "run", "ruff", "format", SRC_DIR, TESTS_DIR)
@nox.session(reuse_venv=True)
def format_check(session):
"""Check if code is properly formatted.
Environment: Reuses QA environment.
Purpose: CI/CD formatting validation.
"""
install_base_deps(session)
session.log("✅ Checking code formatting...")
session.run("uv", "run", "ruff", "format", "--check", SRC_DIR, TESTS_DIR)
@nox.session(reuse_venv=True)
def typing(session):
"""Run MyPy type checking.
Environment: Reuses QA environment.
Purpose: Static type analysis.
"""
install_base_deps(session)
session.log("🔍 Running MyPy type checking...")
session.run("uv", "run", "mypy", SRC_DIR)
@nox.session(reuse_venv=True)
def security(session):
"""Run Bandit security scanning.
Environment: Reuses QA environment.
Purpose: Security vulnerability detection.
"""
install_base_deps(session)
session.log("🔒 Running Bandit security scanning...")
session.run("uv", "run", "bandit", "-r", SRC_DIR, "-ll")
# =============================================================================
# Full Feature Testing (Shared Environment: full-base)
# =============================================================================
@nox.session(python=LATEST_PYTHON, reuse_venv=True)
def test_full(session):
"""Run tests with all optional dependencies enabled.
Environment: Full feature environment with all optional dependencies.
Purpose: Test complete functionality including optional features.
"""
install_base_deps(session)
install_with_group(session, "tiktoken")
install_project_editable(session)
session.log("🚀 Running full feature tests...")
session.run(
"uv",
"run",
"pytest",
"tests/",
"--cov=folder2md4llms",
"--cov-report=html", # Generate HTML coverage report
"--cov-report=xml", # For CI/CD coverage reporting
"-n",
"auto",
"--maxfail=5",
)
@nox.session(python=LATEST_PYTHON, reuse_venv=True)
def test_converters(session):
"""Focus testing on document converters.
Environment: Reuses full-base environment.
Purpose: Intensive testing of conversion functionality.
"""
install_base_deps(session)
install_project_editable(session)
session.log("📄 Testing document converters...")
session.run(
"uv",
"run",
"pytest",
"tests/test_converters.py",
"tests/test_binary_distribution.py",
"-v",
"--tb=long",
)
@nox.session(python=LATEST_PYTHON, reuse_venv=True)
def integration(session):
"""Run integration tests.
Environment: Reuses full-base environment.
Purpose: End-to-end testing of complete workflows.
"""
install_base_deps(session)
install_project_editable(session)
session.log("🔗 Running integration tests...")
session.run(
"uv", "run", "pytest", "tests/", "-k", "integration", "-v", "--tb=short"
)
# =============================================================================
# Build & Distribution (Shared Environment: build-base)
# =============================================================================
@nox.session(reuse_venv=True)
def build(session):
"""Build source and wheel distributions.
Environment: Build environment with packaging tools.
Purpose: Create distributable packages.
"""
install_base_deps(session)
install_with_group(session, "build")
session.log("📦 Building distributions...")
# Clean previous builds
session.run("rm", "-rf", "dist/", "build/", external=True)
session.run("uv", "build")
@nox.session(reuse_venv=True)
def install_test(session):
"""Test package installation in clean environment.
Environment: Clean environment for installation testing.
Purpose: Verify package installs correctly.
"""
session.log("🧪 Testing package installation...")
# Build first if not already built
if not Path("dist").exists():
session.run("uv", "build")
# Find the wheel file
wheel_files = list(Path("dist").glob("*.whl"))
if not wheel_files:
session.error("No wheel file found in dist/")
wheel_file = wheel_files[0]
# Install and test
session.run("uv", "pip", "install", str(wheel_file))
session.run("folder2md", "--version")
session.run("folder2md", "--help")
# =============================================================================
# Documentation & Coverage
# =============================================================================
@nox.session(python=LATEST_PYTHON, reuse_venv=True)
def docs(session):
"""Generate API documentation.
Environment: Documentation environment.
Purpose: Create up-to-date API docs.
"""
install_base_deps(session)
session.log("📚 Generating documentation...")
session.run(
"uv",
"run",
"lazydocs",
"--output-path",
"./docs/api/",
"--overview-file",
"README.md",
"--src-base-url",
"https://github.com/henriqueslab/folder2md4llms/blob/main/",
"--no-watermark",
"src/folder2md4llms",
)
@nox.session(python=LATEST_PYTHON, reuse_venv=True)
def coverage(session):
"""Generate comprehensive coverage report.
Environment: Reuses test environment.
Purpose: Detailed coverage analysis.
"""
install_base_deps(session)
install_project_editable(session)
session.log("📊 Generating coverage report...")
session.run(
"uv",
"run",
"pytest",
"tests/",
"--cov=folder2md4llms",
"--cov-report=html",
"--cov-report=term-missing",
"--cov-report=xml",
"-n",
"auto",
)
session.log("Coverage report generated in htmlcov/")
# =============================================================================
# Development Convenience Sessions
# =============================================================================
@nox.session(reuse_venv=True)
def dev(session):
"""Set up development environment with all dependencies.
Environment: Complete development environment.
Purpose: One-command development setup.
"""
install_base_deps(session)
install_with_group(session, "tiktoken")
install_with_group(session, "build")
install_project_editable(session)
session.log("🛠️ Development environment ready!")
session.log("💡 Run commands with: uv run <command>")
session.log("💡 Or activate with: .nox/dev/bin/activate")
@nox.session(reuse_venv=True)
def fix(session):
"""Format code and fix linting issues.
Environment: Reuses QA environment.
Purpose: One-command code cleanup.
"""
install_base_deps(session)
session.log("🔧 Fixing code issues...")
session.run("uv", "run", "ruff", "format", SRC_DIR, TESTS_DIR)
session.run("uv", "run", "ruff", "check", "--fix", SRC_DIR, TESTS_DIR)
@nox.session(reuse_venv=True)
def check(session):
"""Run all quality checks (format, lint, typing, security).
Environment: Reuses QA environment.
Purpose: Comprehensive quality validation.
"""
install_base_deps(session)
session.log("🔍 Running all quality checks...")
# Format check
session.run("uv", "run", "ruff", "format", "--check", SRC_DIR, TESTS_DIR)
# Linting
session.run("uv", "run", "ruff", "check", SRC_DIR, TESTS_DIR)
# Type checking
session.run("uv", "run", "mypy", SRC_DIR)
# Security scanning
session.run("uv", "run", "bandit", "-r", SRC_DIR, "-ll")
# =============================================================================
# CI/CD Optimized Sessions
# =============================================================================
@nox.session(python=PYTHON_VERSIONS, reuse_venv=True)
def ci_test(session):
"""CI-optimized test session with XML output.
Environment: Shared test environment.
Purpose: CI/CD pipeline testing with proper reporting.
"""
install_base_deps(session)
install_project_editable(session)
session.run(
"uv",
"run",
"pytest",
"tests/",
"--cov=folder2md4llms",
"--cov-report=xml", # For CI coverage reporting
"--cov-report=term-missing",
"-n",
"auto",
"--maxfail=10",
"--tb=short",
"-v",
)
@nox.session(reuse_venv=True)
def ci_quality(session):
"""CI-optimized quality checks with proper exit codes.
Environment: Reuses QA environment.
Purpose: CI/CD pipeline quality gates.
"""
install_base_deps(session)
# Run all checks, failing fast on any issue
session.run("uv", "run", "ruff", "check", SRC_DIR, TESTS_DIR)
session.run("uv", "run", "ruff", "format", "--check", SRC_DIR, TESTS_DIR)
session.run("uv", "run", "mypy", SRC_DIR)
session.run("uv", "run", "bandit", "-r", SRC_DIR, "-ll")
# =============================================================================
# Performance & Benchmarking
# =============================================================================
@nox.session(python=LATEST_PYTHON, reuse_venv=True)
def benchmark(session):
"""Run performance benchmarks.
Environment: Full feature environment.
Purpose: Performance regression testing.
"""
install_base_deps(session)
install_project_editable(session)
session.log("⚡ Running performance benchmarks...")
# Create a test directory structure for benchmarking
test_repo = Path("benchmark_test_repo")
if test_repo.exists():
session.run("rm", "-rf", str(test_repo), external=True)
# Simple benchmark - process this project
session.run(
"uv",
"run",
"python",
"-c",
"""
import time
from folder2md4llms.processor import RepositoryProcessor
from folder2md4llms.utils.config import Config
from pathlib import Path
config = Config()
processor = RepositoryProcessor(config)
start = time.time()
result = processor.process(Path('.'))
end = time.time()
print(f'Processing took {end - start:.2f} seconds')
print(f'Output length: {len(result)} characters')
""",
)
# =============================================================================
# Cleanup & Utilities
# =============================================================================
@nox.session
def clean(session):
"""Clean up all build artifacts and caches.
Purpose: Reset project to clean state.
"""
session.log("🧹 Cleaning up build artifacts...")
# Clean build artifacts
artifacts = [
"build/",
"dist/",
"*.egg-info/",
".pytest_cache/",
".mypy_cache/",
".ruff_cache/",
"htmlcov/",
".coverage",
"coverage.xml",
"__pycache__/",
"*.pyc",
]
for pattern in artifacts:
session.run("rm", "-rf", pattern, external=True)
session.log("✅ Cleanup complete!")
@nox.session
def list_envs(session):
"""List all nox environments and their sizes.
Purpose: Environment management and debugging.
"""
import subprocess # nosec B404
session.log("📋 Nox environments:")
nox_dir = Path(".nox")
if nox_dir.exists():
result = subprocess.run( # nosec B603, B607
["du", "-sh", *nox_dir.glob("*")], capture_output=True, text=True
)
if result.stdout:
session.log("\n" + result.stdout)
else:
session.log("No nox environments found")
# =============================================================================
# Session Groups for Easy Execution
# =============================================================================
# Define session groups for easy parallel execution
nox.options.sessions = [
"lint",
"typing",
"security", # Quality checks (fast)
"test", # Core testing
]
# Additional groups can be run with:
# nox -s test-full integration # Full testing
# nox -s build install_test # Build verification
# nox -s fix check # Development workflow