Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/extensions/built-in/dataclasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ Additional metadata like `ClassVar`, the `init` and `kw_only` parameters, or the

=== "CLI"
```console
$ griffecli dump -e dataclasses,other my_package
$ griffe dump -e dataclasses,other my_package
```

=== "Python"
```python
import griffe

my_package = griffelib.load("my_package", extensions=griffelib.load_extensions("dataclasses", "other"))
my_package = griffe.load("my_package", extensions=griffe.load_extensions("dataclasses", "other"))
```

=== "mkdocstrings"
Expand Down
4 changes: 2 additions & 2 deletions docs/extensions/built-in/unpack-typeddict.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ To enable the extension:

=== "CLI"
```console
$ griffecli dump -e unpack_typeddict my_package
$ griffe dump -e unpack_typeddict my_package
```

=== "Python"
```python
import griffe

my_package = griffelib.load("my_package", extensions=griffelib.load_extensions("unpack_typeddict"))
my_package = griffe.load("my_package", extensions=griffe.load_extensions("unpack_typeddict"))
```

=== "mkdocstrings"
Expand Down
2 changes: 1 addition & 1 deletion docs/extensions/official/runtime-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This extension stores runtime objects corresponding to each loaded Griffe object

```pycon
>>> import griffe
>>> griffe_data = griffelib.load("griffe", extensions=griffelib.load_extensions("griffe_runtime_objects"), resolve_aliases=True)
>>> griffe_data = griffe.load("griffe", extensions=griffe.load_extensions("griffe_runtime_objects"), resolve_aliases=True)
>>> griffe_data["parse"].extra
defaultdict(<class 'dict'>, {'runtime-objects': {'object': <function parse at 0x78685c951260>}})
>>> griffe_data["Module"].extra
Expand Down
2 changes: 1 addition & 1 deletion docs/extensions/official/warnings-deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

---

This extension adds support for functions and classes decorated with [`@warnings.deprecated(...)`][warnings.deprecated], as implemented thanks to [PEP 702](https://peps.python.org/pep-0702/). The message provided in the decorator call will be stored in the corresponding Griffe object's [`deprecated`][griffelib.Object.deprecated] attribute (usable by downstream rendering templates), and will also add an admonition to the object's docstring with the provided message as text.
This extension adds support for functions and classes decorated with [`@warnings.deprecated(...)`][warnings.deprecated], as implemented thanks to [PEP 702](https://peps.python.org/pep-0702/). The message provided in the decorator call will be stored in the corresponding Griffe object's [`deprecated`][griffe.Object.deprecated] attribute (usable by downstream rendering templates), and will also add an admonition to the object's docstring with the provided message as text.

```python
from warnings import deprecated
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/contributors/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ descriptions = {
"scripts": "Our different scripts. See [Scripts, configuration](#scripts-configuration).",
"site": "Documentation site, built with `make run mkdocs build` (git-ignored).",
"src": "The source of our Python package(s). See [Sources](#sources) and [Program structure](#program-structure).",
"packages/griffe/src/griffe": "Our public API, exposed to users. See [Program structure](#program-structure).",
"packages/griffe/src/griffe/_internal": "Our internal API, hidden from users. See [Program structure](#program-structure).",
"src/griffe": "Our public API, exposed to users. See [Program structure](#program-structure).",
"packages/griffelib/src/griffelib/_internal": "Our internal API, hidden from users. See [Program structure](#program-structure).",
"tests": "Our test suite. See [Tests](#tests).",
".copier-answers.yml": "The answers file generated by [Copier](https://copier.readthedocs.io/en/stable/). See [Boilerplate](#boilerplate).",
"devdeps.txt": "Our development dependencies specification. See [`make setup`][command-setup] command.",
Expand Down Expand Up @@ -108,7 +108,7 @@ The test suite is based on [pytest](https://docs.pytest.org/en/8.2.x/). Test mod

## Program structure

The internal API is contained within the `packages/griffe/src/griffe/_internal` folder. The top-level `griffe/__init__.py` module exposes all the public API, by importing the internal objects from various submodules of `griffelib._internal`.
The internal API is contained within the `packages/griffelib/src/griffelib/_internal` folder. The top-level `griffe/__init__.py` module exposes all the public API, by importing the internal objects from `griffelib`, which itself imports from various submodules of `griffelib._internal`.

Users then import `griffe` directly, or import objects from it.

Expand All @@ -122,7 +122,7 @@ if os.getenv("DEPLOY") == "true":
from pydeps.target import Target

cli.verbose = cli._not_verbose
options = cli.parse_args(["packages/griffe/src/griffe", "--noshow", "--reverse"])
options = cli.parse_args(["packages/griffelib/src/griffelib", "--noshow", "--reverse"])
colors.START_COLOR = 128
target = Target(options["fname"])
with target.chdir_work():
Expand Down
4 changes: 4 additions & 0 deletions docs/guide/contributors/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ Deprecated code should also be marked as legacy code. We use [Yore](https://pawa
Examples:

```python title="Remove function when we bump to 2.0"
# YORE: Bump 2: Remove block.
def deprecated_function():
...
```

```python title="Simplify imports when Python 3.15 is EOL"
# YORE: EOL 3.15: Replace block with line 4.
Expand Down
100 changes: 50 additions & 50 deletions docs/guide/users/checking.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,38 @@ Griffe is able to compare two snapshots of your project to detect API breakages
By default, Griffe will compare the current code to the latest tag:

```console
$ griffecli check mypackage
$ griffe check mypackage
```

To specify another Git reference to check against, use the `--against` or `-a` option:

```console
$ griffecli check mypackage -a 0.2.0
$ griffe check mypackage -a 0.2.0
```

You can specify a Git tag, commit (hash), or even a branch: Griffe will create a worktree at this reference in a temporary directory, and clean it up after finishing.

If you want to also specify the *base* reference to use (instead of the current code), use the `--base` or `-b` option. Some examples:

```console
$ griffecli check mypackage -b HEAD -a 2.0.0
$ griffecli check mypackage -b 2.0.0 -a 1.0.0
$ griffecli check mypackage -b fix-issue-90 -a 1.2.3
$ griffecli check mypackage -b 8afcfd6e
$ griffe check mypackage -b HEAD -a 2.0.0
$ griffe check mypackage -b 2.0.0 -a 1.0.0
$ griffe check mypackage -b fix-issue-90 -a 1.2.3
$ griffe check mypackage -b 8afcfd6e
```

TIP: **Important:** Remember that the base is the most recent reference, and the one we compare it against is the oldest one.

The package name you pass to `griffecli check` must be found relative to the repository root. For Griffe to find packages in subfolders, pass the parent subfolder to the `--search` or `-s` option. Example for `src`-layouts:
The package name you pass to `griffe check` must be found relative to the repository root. For Griffe to find packages in subfolders, pass the parent subfolder to the `--search` or `-s` option. Example for `src`-layouts:

```console
$ griffecli check -s src griffe
$ griffe check -s src griffe
```

Example in a monorepo, within a deeper file tree:

```console
$ griffecli check -s back/services/identity-provider/src identity_provider
$ griffe check -s back/services/identity-provider/src identity_provider
```

### Using PyPI
Expand All @@ -54,39 +54,39 @@ $ pip install griffe[pypi]
The command syntax is:

```console
$ griffecli check package_name -b project-name==2.0 -a project-name==1.0
$ griffe check package_name -b project-name==2.0 -a project-name==1.0
```

You can let Griffe guess the package name by passing an empty string:

```console
$ griffecli check "" -b project-name==2.0 -a project-name==1.0
$ griffe check "" -b project-name==2.0 -a project-name==1.0
```

[PEP 508 version specifiers](https://peps.python.org/pep-0508/) are supported (`<`, `<=`, `!=`, `==`, `>=`, `>`, `~=`). For example, to compare v2 against the version just before it:

```console
$ griffecli check "" -b project-name==2.0 -a project-name<2.0
$ griffe check "" -b project-name==2.0 -a project-name<2.0
```

Without a version specifier on the base reference, or without a base reference at all, Griffe will use the latest available version. The two following commands compare the latest version against v1:

```console
$ griffecli check "" -b project-name -a project-name==1.0
$ griffecli check "" -a project-name==1.0
$ griffe check "" -b project-name -a project-name==1.0
$ griffe check "" -a project-name==1.0
```

Griffe will actually install packages in a cache directory. It means a few things: source distributions are supported, and only packages that are compatible with your current environment can be checked.

## Python API

To programmatically check for API breaking changes, you have to load two snapshots of your code base, for example using our [`load_git()`][griffelib.load_git] utility, and then passing them both to the [`find_breaking_changes()`][griffelib.find_breaking_changes] function. This function will yield instances of [`Breakage`][griffelib.Breakage]. It's up to you how you want to use these breakage instances.
To programmatically check for API breaking changes, you have to load two snapshots of your code base, for example using our [`load_git()`][griffe.load_git] utility, and then passing them both to the [`find_breaking_changes()`][griffe.find_breaking_changes] function. This function will yield instances of [`Breakage`][griffe.Breakage]. It's up to you how you want to use these breakage instances.

```python
import griffe

my_pkg_v1 = griffelib.load_git("my_pkg", ref="v1")
my_pkg_v2 = griffelib.load_git("my_pkg", ref="v2")
my_pkg_v1 = griffe.load_git("my_pkg", ref="v1")
my_pkg_v2 = griffe.load_git("my_pkg", ref="v2")

for breaking_change in find_breaking_changes(my_pkg_v1, my_pkg_v2):
print(breaking_change.explain())
Expand All @@ -110,7 +110,7 @@ jobs:
fetch-depth: 0 # We the need the full Git history.
- uses: astral-sh/setup-uv@v6
# The following command will compare current changes to latest tag.
- run: uvx griffecli check --search src --format github your_package_name
- run: uvx griffe check --search src --format github your_package_name
```

The last step will fail the workflow if any breaking change is found.
Expand Down Expand Up @@ -643,9 +643,9 @@ Griffe supports writing detected breakages in multiple formats, or styles.

This is the default format. Griffe will print each detected breakage on a single line:

```console exec="1" source="console" result="ansi" returncode="1" id="griffecli-check-oneline"
```console exec="1" source="console" result="ansi" returncode="1" id="griffe-check-oneline"
$ export FORCE_COLOR=1 # markdown-exec: hide
$ griffecli check griffe -ssrc -b0.46.0 -a0.45.0
$ griffe check griffe -ssrc -b0.46.0 -a0.45.0
```

[](){#format-verbose}
Expand All @@ -655,11 +655,11 @@ $ griffecli check griffe -ssrc -b0.46.0 -a0.45.0
- **CLI**: `-f verbose` / `-v`
- **API**: `check(..., style="verbose")` / `check(..., style=ExplanationStyle.VERBOSE)` / `check(..., verbose=True)`

Depending on the detected breakages, the lines might be hard to read (being too compact), so `griffecli check` also accepts a `--verbose` or `-v` option to add some space to the output:
Depending on the detected breakages, the lines might be hard to read (being too compact), so `griffe check` also accepts a `--verbose` or `-v` option to add some space to the output:

```console exec="1" source="console" result="ansi" returncode="1" id="griffecli-check-verbose"
```console exec="1" source="console" result="ansi" returncode="1" id="griffe-check-verbose"
$ export FORCE_COLOR=1 # markdown-exec: hide
$ griffecli check griffe -ssrc -b0.46.0 -a0.45.0 --verbose
$ griffe check griffe -ssrc -b0.46.0 -a0.45.0 --verbose
```

[](){#format-markdown}
Expand All @@ -672,26 +672,26 @@ $ griffecli check griffe -ssrc -b0.46.0 -a0.45.0 --verbose
The Markdown format is adapted for changelogs. It doesn't show the file and line number, and instead prints out the complete path of your API objects. With a bit of automation, you will be able to automatically insert a summary of breaking changes in your changelog entries.

```md exec="1" source="tabbed-left" tabs="Output|Result"
- `griffelib.loader.GriffeLoader.resolve_aliases(only_exported)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.loader.GriffeLoader.resolve_aliases(only_exported)`: *Parameter default was changed*: `True` -> `None`
- `griffelib.loader.GriffeLoader.resolve_aliases(only_known_modules)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.loader.GriffeLoader.resolve_aliases(only_known_modules)`: *Parameter default was changed*: `True` -> `None`
- `griffelib.loader.GriffeLoader.resolve_aliases(max_iterations)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.loader.GriffeLoader.resolve_module_aliases(only_exported)`: *Parameter was removed*
- `griffelib.loader.GriffeLoader.resolve_module_aliases(only_known_modules)`: *Parameter was removed*
- `griffelib.git.tmp_worktree(commit)`: *Parameter was removed*
- `griffelib.git.tmp_worktree(repo)`: *Positional parameter was moved*: position: from 2 to 1 (-1)
- `griffelib.git.load_git(commit)`: *Parameter was removed*
- `griffelib.git.load_git(repo)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.git.load_git(submodules)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.git.load_git(try_relative_path)`: *Parameter was removed*
- `griffelib.git.load_git(extensions)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.git.load_git(search_paths)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.git.load_git(docstring_parser)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.git.load_git(docstring_options)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.git.load_git(lines_collection)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.git.load_git(modules_collection)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffelib.git.load_git(allow_inspection)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.loader.GriffeLoader.resolve_aliases(only_exported)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.loader.GriffeLoader.resolve_aliases(only_exported)`: *Parameter default was changed*: `True` -> `None`
- `griffe.loader.GriffeLoader.resolve_aliases(only_known_modules)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.loader.GriffeLoader.resolve_aliases(only_known_modules)`: *Parameter default was changed*: `True` -> `None`
- `griffe.loader.GriffeLoader.resolve_aliases(max_iterations)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.loader.GriffeLoader.resolve_module_aliases(only_exported)`: *Parameter was removed*
- `griffe.loader.GriffeLoader.resolve_module_aliases(only_known_modules)`: *Parameter was removed*
- `griffe.git.tmp_worktree(commit)`: *Parameter was removed*
- `griffe.git.tmp_worktree(repo)`: *Positional parameter was moved*: position: from 2 to 1 (-1)
- `griffe.git.load_git(commit)`: *Parameter was removed*
- `griffe.git.load_git(repo)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.git.load_git(submodules)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.git.load_git(try_relative_path)`: *Parameter was removed*
- `griffe.git.load_git(extensions)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.git.load_git(search_paths)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.git.load_git(docstring_parser)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.git.load_git(docstring_options)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.git.load_git(lines_collection)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.git.load_git(modules_collection)`: *Parameter kind was changed*: positional or keyword -> keyword-only
- `griffe.git.load_git(allow_inspection)`: *Parameter kind was changed*: positional or keyword -> keyword-only
```

[](){#format-github}
Expand All @@ -701,7 +701,7 @@ The Markdown format is adapted for changelogs. It doesn't show the file and line
- **CLI**: `-f github`
- **API**: `check(..., style="github")` / `check(..., style=ExplanationStyle.GITHUB)`

When running `griffecli check` in CI, you can enable GitHub's annotations thanks to the GitHub output style. Annotations are displayed on specific lines of code. They are visible in the Checks tab. When you create an annotation for a file that is part of the pull request, the annotations are also shown in the Files changed tab.
When running `griffe check` in CI, you can enable GitHub's annotations thanks to the GitHub output style. Annotations are displayed on specific lines of code. They are visible in the Checks tab. When you create an annotation for a file that is part of the pull request, the annotations are also shown in the Files changed tab.

/// tab | Files changed tab
![gha_annotations_2](../../img/gha_annotations_2.png)
Expand All @@ -712,12 +712,12 @@ When running `griffecli check` in CI, you can enable GitHub's annotations thanks
///

```console
% python -m griffecli check -fgithub -ssrc griffe
::warning file=packages/griffe/src/griffe/finder.py,line=58,title=Package.name::Attribute value was changed: `name` -> unset
::warning file=packages/griffe/src/griffe/finder.py,line=60,title=Package.path::Attribute value was changed: `path` -> unset
::warning file=packages/griffe/src/griffe/finder.py,line=62,title=Package.stubs::Attribute value was changed: `stubs` -> `None`
::warning file=packages/griffe/src/griffe/finder.py,line=75,title=NamespacePackage.name::Attribute value was changed: `name` -> unset
::warning file=packages/griffe/src/griffe/finder.py,line=77,title=NamespacePackage.path::Attribute value was changed: `path` -> unset
% python -m griffe check -fgithub -ssrc griffe
::warning file=src/griffe/finder.py,line=58,title=Package.name::Attribute value was changed: `name` -> unset
::warning file=src/griffe/finder.py,line=60,title=Package.path::Attribute value was changed: `path` -> unset
::warning file=src/griffe/finder.py,line=62,title=Package.stubs::Attribute value was changed: `stubs` -> `None`
::warning file=src/griffe/finder.py,line=75,title=NamespacePackage.name::Attribute value was changed: `name` -> unset
::warning file=src/griffe/finder.py,line=77,title=NamespacePackage.path::Attribute value was changed: `path` -> unset
```

## Next steps
Expand Down
Loading
Loading