Skip to content

Commit aaad0a3

Browse files
committed
fixup! perf: Prune function bodies from source before building AST
1 parent bc43da8 commit aaad0a3

7 files changed

Lines changed: 16 additions & 25 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ jobs:
7575
- name: Install dependencies
7676
run: make setup
7777

78-
- name: Install prune-source accelerator
79-
run: uv sync --extra native
80-
8178
- name: Check if the documentation builds correctly
8279
run: make check-docs
8380

@@ -153,11 +150,6 @@ jobs:
153150
UV_RESOLUTION: ${{ matrix.resolution }}
154151
run: make setup
155152

156-
- name: Install prune-source accelerator
157-
env:
158-
UV_RESOLUTION: ${{ matrix.resolution }}
159-
run: uv sync --extra native
160-
161153
- name: Download objects inventory
162154
uses: actions/download-artifact@v8
163155
with:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ uv tool install griffe
3232
For faster static analysis, install the optional `prune-source` Rust/Ruff accelerator:
3333

3434
```bash
35-
pip install "griffe[native]"
35+
pip install "griffe[faster]"
3636
```
3737

3838
Griffe automatically imports the accelerator when available and falls back to its full CPython AST

docs/installation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
Griffe is a Python package, so you can install it with your favorite Python package installer or dependency manager.
44

5-
## Install the native parser accelerator
5+
## Install the parser accelerator
66

77
Static analysis can use the optional `prune-source` Rust parser accelerator:
88

99
=== ":simple-python: pip"
1010
```bash
11-
pip install "griffe[native]"
11+
pip install "griffe[faster]"
1212
```
1313

1414
=== ":simple-astral: uv"
1515
```bash
16-
uv add "griffe[native]"
16+
uv add "griffe[faster]"
1717
```
1818

1919
To install only the library, replace `griffe` with `griffelib` in either command. The separately

packages/griffelib/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ classifiers = [
3737
]
3838

3939
[project.optional-dependencies]
40-
# The 'native' extra installs the Rust/Ruff parser accelerator. Griffe automatically falls back to
40+
# The 'faster' extra installs the Rust/Ruff parser accelerator. Griffe automatically falls back to
4141
# CPython's parser when the accelerator is unavailable or an extension needs concrete AST nodes.
42-
native = ["prune-source>=0.1.0,<0.2"]
42+
faster = ["prune-source>=0.1.0,<0.2"]
4343
# The 'pypi' extra provides dependencies needed for the load_pypi functionality
4444
# to download and inspect packages from PyPI.
4545
pypi = ["pip>=24.0", "platformdirs>=4.2", "wheel>=0.42"]

packages/griffelib/src/griffe/_internal/agents/parser.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
from __future__ import annotations
1818

1919
import ast
20-
import sys
21-
from importlib import import_module
2220
from typing import TYPE_CHECKING, Final
2321

2422
if TYPE_CHECKING:

packages/griffelib/tests/test_parser.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_native_parser_is_used_without_node_aware_hooks(monkeypatch: pytest.Monk
5454
"""Use Ruff when installed extensions do not require the concrete source AST."""
5555
calls = 0
5656

57-
def prune(code: str, python_minor: int) -> str: # noqa: ARG001
57+
def prune(code: str) -> str:
5858
nonlocal calls
5959
calls += 1
6060
return code
@@ -69,7 +69,7 @@ def test_native_parser_is_skipped_without_functions(monkeypatch: pytest.MonkeyPa
6969
"""Avoid paying for a second parse when no implementation suite can be removed."""
7070
calls = 0
7171

72-
def prune(code: str, python_minor: int) -> str: # noqa: ARG001
72+
def prune(code: str) -> str:
7373
nonlocal calls
7474
calls += 1
7575
return code
@@ -84,7 +84,7 @@ def test_native_parser_is_skipped_for_stub_files(monkeypatch: pytest.MonkeyPatch
8484
"""Avoid pruning stub files, whose function bodies contain no implementations."""
8585
calls = 0
8686

87-
def prune(code: str, python_minor: int) -> str: # noqa: ARG001
87+
def prune(code: str) -> str:
8888
nonlocal calls
8989
calls += 1
9090
return code
@@ -99,7 +99,7 @@ def test_node_aware_hooks_force_cpython_fallback(monkeypatch: pytest.MonkeyPatch
9999
"""Keep complete CPython nodes available to visit-time extension callbacks."""
100100
calls = 0
101101

102-
def prune(code: str, python_minor: int) -> str: # noqa: ARG001
102+
def prune(code: str) -> str:
103103
nonlocal calls
104104
calls += 1
105105
return code
@@ -114,7 +114,7 @@ def test_custom_visitors_can_disable_native_pruning(monkeypatch: pytest.MonkeyPa
114114
"""Keep the complete tree available to Visitor subclasses with custom traversal."""
115115
calls = 0
116116

117-
def prune(code: str, python_minor: int) -> str: # noqa: ARG001
117+
def prune(code: str) -> str:
118118
nonlocal calls
119119
calls += 1
120120
return code
@@ -131,7 +131,7 @@ class CustomVisitor(Visitor):
131131

132132
def test_cpython_retries_an_invalid_native_result(monkeypatch: pytest.MonkeyPatch) -> None:
133133
"""Never expose a diagnostic caused by native source pruning."""
134-
monkeypatch.setattr(parser_module, "prune_source", lambda code, python_minor: "def invalid(: pass")
134+
monkeypatch.setattr(parser_module, "prune_source", lambda code: "def invalid(: pass")
135135

136136
node = parser_module._compile_module("def valid(): pass", filename="module.py", extensions=Extensions())
137137

@@ -140,7 +140,7 @@ def test_cpython_retries_an_invalid_native_result(monkeypatch: pytest.MonkeyPatc
140140

141141
def test_cpython_compiles_untouched_source_when_native_declines(monkeypatch: pytest.MonkeyPatch) -> None:
142142
"""Use the normal source when Ruff cannot prune it."""
143-
monkeypatch.setattr(parser_module, "prune_source", lambda code, python_minor: None)
143+
monkeypatch.setattr(parser_module, "prune_source", lambda code: None)
144144

145145
node = parser_module._compile_module("def valid(): pass", filename="module.py", extensions=Extensions())
146146

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ expression = "get_version()"
6464
dependencies = ["griffelib=={{version}}", "griffecli=={{version}}"]
6565

6666
[tool.hatch.metadata.hooks.uv-dynamic-versioning.optional-dependencies]
67-
# The 'native' extra re-exports griffelib[native] for backward compatibility.
68-
native = ["griffelib[native]=={{version}}"]
67+
# The 'faster' extra re-exports griffelib[faster].
68+
faster = ["griffelib[faster]=={{version}}"]
6969
# The 'pypi' extra re-exports griffelib[pypi] for backward compatibility.
7070
pypi = ["griffelib[pypi]=={{version}}"]
7171

@@ -105,6 +105,7 @@ ci = [
105105
"duty>=1.6",
106106
"griffe-inherited-docstrings>=1.1.2",
107107
"jsonschema>=4.18",
108+
"prune-source>=0.1",
108109
"pysource-codegen>=0.7",
109110
"pysource-minimize>=0.10",
110111
"pytest>=8.2",

0 commit comments

Comments
 (0)