sphinx-ultra 0.4.0

High-performance Rust-based Sphinx documentation builder for large codebases
Documentation
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
# Sphinx Ultra Rust Builder

[![Crates.io](https://img.shields.io/crates/v/sphinx-ultra.svg)](https://crates.io/crates/sphinx-ultra)
[![CI](https://github.com/salioglu/sphinx-ultra/actions/workflows/ci.yml/badge.svg)](https://github.com/salioglu/sphinx-ultra/actions/workflows/ci.yml)
[![Documentation](https://github.com/salioglu/sphinx-ultra/actions/workflows/docs.yml/badge.svg)](https://salioglu.github.io/sphinx-ultra)
[![Release](https://github.com/salioglu/sphinx-ultra/actions/workflows/release.yml/badge.svg)](https://github.com/salioglu/sphinx-ultra/releases)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust](https://img.shields.io/badge/rust-1.70%2B-orange.svg)](https://www.rust-lang.org)
[![Sponsor](https://img.shields.io/badge/sponsor-GitHub-pink.svg)](https://github.com/sponsors/salioglu)

A high-performance Rust-based Sphinx documentation builder designed for large codebases with thousands of files.

## โš ๏ธ Development Status

**๐Ÿšง Pre-1.0: not yet recommended for production documentation workflows.**

**Mission (see [ROADMAP.md](ROADMAP.md)):** sphinx-ultra 1.0 will be a
production-grade, drop-in replacement for `sphinx-build -b html` โ€” full Sphinx
feature parity (target: Sphinx 9.1.x), **sphinx-needs built in as a first-class
feature** (target: 8.3.x), support for the 5 most popular themes and 15+ most
popular extensions โ€” at 10โ€“100ร— the speed. **No Sphinx or sphinx-needs feature is
excluded from scope**; features are phased, never excluded. The earlier
validation-only scoping is retired.

**Honest current state (verified by code audit, 2026-08):** today's build pipeline
is fast and structurally sound, but the HTML it emits is a placeholder (the source
text, escaped, without rendering, themes, or search). The RST/Markdown parsers are
prototypes, `conf.py` support covers only simple single-line assignments, and the
advertised validation systems exist as tested libraries that the build command does
not yet invoke. The full, file-and-line-level status audit lives in
[docs/IMPLEMENTATION_STATUS.md](docs/IMPLEMENTATION_STATUS.md).

## โœจ Features

### โœ… Working today

- **๐Ÿš€ Parallel build pipeline**: Rayon-based, scales across cores (`-j`)
- **๐Ÿ“‚ Pattern-based file discovery**: Sphinx-style `include_patterns` /
  `exclude_patterns` engine, verified against `sphinx.util.matching` 9.1.0 by a
  committed 881-case differential suite (zero divergence)
- **๐Ÿงฐ sphinx-build compatible CLI**: `sphinx-ultra SOURCEDIR OUTPUTDIR` with
  `-b html`, `-M html`/`-M clean` make-mode, `-D`/`-A` overrides, `-d`, `-n`,
  `-q`, `-E`, `-a`, `-T`, `-t`, `-c`, `-j auto`, `-W`/`--keep-going`/`-w` โ€”
  quickstart Makefiles work unchanged
- **๐Ÿ”„ Incremental cache**: cache hits write their output, `--clean
  --incremental` is safe, config changes invalidate automatically (blake3
  fingerprint); sphinx-build mode is incremental by default
- **โš ๏ธ Build validation**: toctree missing-reference and orphan detection;
  directive/role validation on every build; `-n` nitpicky cross-reference
  checking (`unknown document:` / `undefined label:`) โ€” all through
  Sphinx-style warnings, `-W`, and `-w warnfile`
- **๐Ÿ”ง Config auto-detection**: conf.py (simple assignments only, for now) โ†’
  sphinx-ultra.yaml โ†’ .yml โ†’ .json โ†’ defaults
- **๐Ÿ“Š Statistics**: `stats` command with project analysis
- **๐Ÿ—๏ธ CLI**: `build`, `clean`, `stats`

### ๐Ÿงฉ Built but not yet wired into `build` (activation is roadmap M2โ€“M4)

- **๐Ÿ” Constraint engine** inspired by sphinx-needs (library + examples; wiring
  waits for sphinx-needs item extraction in M4)
- **๐Ÿ–ฅ๏ธ Sphinx-mirroring HTML builder, minijinja template engine, search index,
  objects.inv inventory** (library code, currently bypassed by the build path)

### ๐Ÿ“‹ Roadmap

The canonical, milestone-by-milestone plan โ€” real docutils-fidelity parsing, theme
engine (alabaster, sphinx-rtd-theme, furo, pydata-sphinx-theme, sphinx-book-theme),
byte-compatible search and objects.inv, 16-extension support matrix (autodoc via a
Python sidecar, myst-parser, sphinx-design, copybutton, mermaid, โ€ฆ), first-class
sphinx-needs, i18n, LaTeX/EPUB/man builders, live-reload dev server, and the
production-readiness workstream โ€” is in **[ROADMAP.md](ROADMAP.md)**.

## ๐Ÿš€ Quick Start

### Prerequisites

- Rust 1.85 or newer (declared MSRV, verified in CI)
- Cargo

### Installation

```bash
# Clone and build from source
git clone https://github.com/salioglu/sphinx-ultra.git
cd sphinx-ultra
cargo build --release

# The binary will be available at target/release/sphinx-ultra
```

### Basic Usage

```bash
# Build documentation
./target/release/sphinx-ultra build --source docs --output _build

# Clean build artifacts
./target/release/sphinx-ultra clean --output _build

# Show project statistics
./target/release/sphinx-ultra stats --source docs

# Get help
./target/release/sphinx-ultra --help
```

### Available Commands

- `build`: Build documentation from source files
- `clean`: Remove build artifacts and output files  
- `stats`: Display project statistics and analysis

### sphinx-build Compatible Mode

Invocations that don't start with a subcommand are parsed exactly like
`sphinx-build`, so existing Makefiles and CI scripts work by swapping the
binary name:

```bash
# Classic sphinx-build style
sphinx-ultra docs _build/html -b html

# Make-mode (what sphinx-quickstart Makefiles invoke): output goes to _build/html
sphinx-ultra -M html docs _build

# Overrides, nitpicky mode, fresh environment, quiet
sphinx-ultra docs _build -D project=MyDocs -n -E -q -j auto
```

Supported: positional `SOURCEDIR OUTPUTDIR`, `-b html` (other builders exit 2
until their milestones land), `-M html`/`-M clean`, `-D key=value`,
`-A name=value`, `-d doctreedir`, `-n`, `-q`, `-E`, `-a`, `-T`, `-t tag`,
`-c confdir`, `-j N|auto`, `-W`, `--keep-going`, `-w file`, repeatable `-v`.
sphinx-build mode is incremental by default (`-E` discards the saved
environment, `-a` rewrites everything), and a pre-set `RUST_LOG` always wins
over the verbosity flags. One caveat: a source directory literally named
`build`, `clean`, or `stats` must be written with a path prefix
(`sphinx-ultra ./build _build`).

### Build Options

```bash
# Parallel processing
sphinx-ultra build --jobs 8 --source docs --output _build

# Incremental builds
sphinx-ultra build --incremental --source docs --output _build

# Clean before build
sphinx-ultra build --clean --source docs --output _build

# Save warnings to file
sphinx-ultra build --warning-file warnings.log --source docs --output _build

# Fail on warnings (useful for CI)
sphinx-ultra build --fail-on-warning --source docs --output _build
```

## ๐Ÿ”ง Configuration

Sphinx Ultra supports multiple configuration formats and can auto-detect your setup:

### Configuration Priority

1. **conf.py** (Sphinx standard) - Automatically detected and parsed
2. **sphinx-ultra.yaml** - Native YAML configuration  
3. **sphinx-ultra.yml** - Alternative YAML format
4. **sphinx-ultra.json** - JSON configuration
5. **Default settings** - Used if no config file found

### Sphinx conf.py Support

Sphinx Ultra can read existing Sphinx `conf.py` files, **currently limited to
simple single-line assignments** (strings, booleans, integers, single-line lists):

```python
# conf.py โ€” this subset parses today
project = 'My Documentation'
version = '1.0'
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
html_theme = 'sphinx_rtd_theme'
```

> Multi-line lists, dicts, tuples, string concatenation, and triple-quoted
> strings parse natively; every construct the parser cannot handle (computed
> values, f-strings) produces a `conf.py:<line>` warning instead of being
> silently dropped. Executing dynamic conf.py in your project's venv arrives
> with the M5 sidecar.

### YAML Configuration

Create a `sphinx-ultra.yaml` file for native configuration.

> Every field is optional โ€” a partial YAML file loads with sensible defaults
> for whatever it omits.

```yaml
# Project information
project: "My Documentation"
version: "1.0.0"
copyright: "2024, My Company"

# Build settings
parallel_jobs: 8
max_cache_size_mb: 500
cache_expiration_hours: 24

# Output configuration
output:
  html_theme: "sphinx_rtd_theme"
  syntax_highlighting: true
  highlight_theme: "github"
  search_index: true
  minify_html: false

# File pattern matching (Sphinx-style)
include_patterns:
  - "**/*.rst"
  - "**/*.md"
exclude_patterns:
  - "_build/**"
  - "drafts/**"

# Extensions (limited support currently)
extensions:
  - "sphinx.ext.autodoc"
  - "sphinx.ext.viewcode"
  - "sphinx.ext.intersphinx"

# Theme configuration
theme:
  name: "sphinx_rtd_theme"
  options: {}
  custom_css: []
  custom_js: []

# Optimization settings
optimization:
  parallel_processing: true
  incremental_builds: true
  document_caching: true
```

### Configuration Fields

Many standard Sphinx configuration options are **parsed**; note that a number of
them are not yet consumed by the build (see
[docs/IMPLEMENTATION_STATUS.md](docs/IMPLEMENTATION_STATUS.md) ยง Configuration).
The options that demonstrably change behavior today are project metadata,
`parallel_jobs`, `include_patterns`/`exclude_patterns`, and `fail_on_warning`.
Parsed categories include:
- Project metadata (project, version, copyright, author)
- HTML output options (theme, static paths, CSS/JS files)  
- Extension configuration
- Template and static file paths
- **File pattern matching** (`include_patterns`, `exclude_patterns`) - [compatibility guide]docs/SPHINX_PATTERNS_COMPATIBILITY.md (close to Sphinx; remaining verified divergences tracked in [ROADMAP.md]ROADMAP.md M1)
- Build optimization settings

## ๐Ÿ“ˆ Performance

> **Important caveat:** the numbers below were measured on the **current
> placeholder pipeline** (which does not yet perform full RST rendering, theming,
> or search indexing). They demonstrate the parallel-I/O architecture, not
> end-to-end documentation-build performance. Honest, corpus-based benchmarks with
> regression gates arrive with the real parser (ROADMAP M2, ยง10).

| Files | Build Time | Processing Rate | Memory Usage |
|-------|------------|-----------------|--------------|
| 2 files | 8ms | 250 files/sec | ~10MB |  
| 51 files | 44ms | 1,159 files/sec | ~15MB |
| 100+ files | ~85ms* | 1,176 files/sec* | ~20MB* |

*Projected based on linear scaling

### Performance Features

- **Parallel Processing**: Utilizes all CPU cores for maximum throughput
- **Change Detection**: blake3-based staleness checks; cache hits write their
  output, and any configuration change invalidates the cache automatically
- **Memory Efficient**: Low memory footprint even for large projects
- **Minimal I/O**: Efficient file operations and batch processing

### Comparison Notes

While we don't have direct Sphinx comparison benchmarks yet, the processing speeds above represent significant performance improvements for documentation builds. The actual performance gain depends on:

- Number of files and their complexity
- Available CPU cores  
- Disk I/O speed
- Whether incremental builds are enabled

## ๐Ÿ—๏ธ Architecture

The Rust builder consists of several key components:

- **Parser**: RST/Markdown parsing (prototype today; docutils-fidelity parser is ROADMAP M2)
- **Cache**: Incremental build cache with blake3 change detection
- **Renderer**: minijinja-based template engine (built, not yet wired โ€” ROADMAP M2)
- **Builder**: Parallel processing engine (rayon)

## ๐Ÿ” Advanced Usage

### Incremental Builds

Enable faster rebuilds by only processing changed files:

```bash
sphinx-ultra build --incremental --source docs --output _build
```

Cache hits always write their output (a cached rebuild produces a complete
output tree), `--clean --incremental` is safe, and any configuration change
invalidates the cache automatically. `max_cache_size_mb` and
`cache_expiration_hours` in the config control retention.

### Parallel Processing

Control the number of parallel jobs:

```bash
# Use 16 parallel jobs for maximum performance on large projects
sphinx-ultra build --jobs 16 --source docs --output _build

# Use 1 job for debugging or memory-constrained environments  
sphinx-ultra build --jobs 1 --source docs --output _build
```

### Warning and Error Handling

```bash
# Save all warnings and errors to a log file
sphinx-ultra build --warning-file build.log --source docs --output _build

# Treat warnings as errors (useful for CI/CD)
sphinx-ultra build --fail-on-warning --source docs --output _build

# Combine both for strict CI builds
sphinx-ultra build -w build.log -W --source docs --output _build
```

### Configuration File Usage

```bash
# Use a specific configuration file
sphinx-ultra build --config my-config.yaml --source docs --output _build

# Configuration auto-detection order:
# 1. conf.py (if present)
# 2. sphinx-ultra.yaml  
# 3. sphinx-ultra.yml
# 4. sphinx-ultra.json
# 5. Default configuration
```

### Clean Builds

```bash
# Clean output directory before building
sphinx-ultra build --clean --source docs --output _build

# Or clean manually
sphinx-ultra clean --output _build
```

### Project Analysis

```bash
# Get detailed project statistics
sphinx-ultra stats --source docs
```

Output includes:
- Number of source files discovered
- Total lines of documentation
- Average and largest file sizes  
- Directory depth analysis
- Cross-reference count

## ๐Ÿ› Debugging and Troubleshooting

### Enable Verbose Logging

```bash
# Debug-level logging for detailed build information
# (note: --verbose goes before the subcommand)
sphinx-ultra --verbose build --source docs --output _build
```

### Common Issues

**Configuration Loading Errors**
- Ensure YAML/JSON syntax is valid
- Check that required fields are present
- Use `--config` to specify config file explicitly

**Build Failures**
- Check file permissions in source and output directories
- Verify source files are valid RST/Markdown
- Review warning output for specific issues

**Performance Issues**
- Reduce parallel jobs if memory-constrained: `--jobs 1`
- Check for large files that may slow processing

### Getting Help

- Use `sphinx-ultra --help` for command overview
- Use `sphinx-ultra build --help` for build options
- Check project issues on GitHub
- Enable verbose logging for debugging

## ๐Ÿค Contributing

**We welcome contributors!** This project is in active development and needs help with:

- ๐Ÿงช **Testing**: Try the builder on various documentation projects
- ๐Ÿ› **Bug Reports**: Report issues with parsing, rendering, or performance
- ๐Ÿ’ก **Feature Ideas**: Suggest improvements or new capabilities
- ๐Ÿ“ **Documentation**: Help improve setup guides and usage examples
- ๐Ÿ”ง **Code**: Contribute to core features, optimizations, or new functionality

### Development Setup

```bash
# Clone and build
git clone https://github.com/salioglu/sphinx-ultra.git
cd sphinx-ultra
./dev.sh setup

# Install git pre-commit hooks (recommended)
./dev.sh install-hooks

# Run development commands
./dev.sh fmt           # Format code
./dev.sh clippy        # Run linter
./dev.sh test          # Run tests
./dev.sh pre-commit    # Run all pre-commit checks
./dev.sh check         # Run all checks including tests

# Build documentation
./dev.sh docs
```

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.

**Priority Areas**: We need help with:

- ๐Ÿงช **Testing**: Try the builder on various documentation projects and report results
- ๐Ÿ› **Bug Reports**: Report issues with parsing, rendering, or performance  
- ๐Ÿ’ก **Feature Validation**: Test existing features and suggest improvements
- ๐Ÿ“ **Documentation**: Help improve setup guides and usage examples
- ๐Ÿ”ง **Core Features**: Contribute to parsing, theming, or search functionality
- ๐ŸŽจ **Themes**: Develop modern, responsive documentation themes
- ๐Ÿ”Œ **Extensions**: Expand Sphinx extension compatibility

### What Currently Works Well

- Fast parallel file processing (rayon)
- Configuration auto-detection (conf.py subset โ†’ YAML โ†’ JSON โ†’ defaults)
- Pattern-based file discovery with Sphinx-parity `[!โ€ฆ]`/pruning semantics
- Toctree missing-reference/orphan warnings with `-W`/`-w`

### What Needs Development

- Advanced theming and templating
- Search index functionality  
- Live development server
- Full Sphinx directive compatibility

## ๐Ÿ“ฆ Releases

This project uses an automated release system with version validation to ensure consistency.

### For Users

Download pre-built binaries from the [Releases page](https://github.com/salioglu/sphinx-ultra/releases).

### For Maintainers

```bash
# Setup release environment (one-time)
./scripts/setup.sh

# Create a new patch release (0.1.2 โ†’ 0.1.3)
./scripts/release.sh --patch

# Create a new minor release (0.1.2 โ†’ 0.2.0)
./scripts/release.sh --minor

# Create a new major release (0.1.2 โ†’ 1.0.0)
./scripts/release.sh --major

# Preview what a release would do
./scripts/release.sh --dry-run --patch
```

The release script automatically:

- โœ… Runs tests to ensure quality
- โœ… Updates `Cargo.toml` version  
- โœ… Creates and pushes git tags
- โœ… Triggers GitHub Actions to build and publish

**Version Safety**: The system prevents version mismatches between git tags and `Cargo.toml`. See [`scripts/README.md`](scripts/README.md) for detailed documentation.

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.