diff --git a/config/coverage.ini b/config/coverage.ini index 7db748bfd..6f57222a8 100644 --- a/config/coverage.ini +++ b/config/coverage.ini @@ -2,7 +2,7 @@ branch = true parallel = true source = - src/griffe + packages/griffe/src/griffe tests/ [coverage:paths] diff --git a/config/ruff.toml b/config/ruff.toml index 0a52cb729..462ddcbce 100644 --- a/config/ruff.toml +++ b/config/ruff.toml @@ -35,27 +35,27 @@ ignore = [ "TRY003", # Avoid specifying long messages outside the exception class ] -logger-objects = ["griffe.logger"] +logger-objects = ["griffe.logger", "griffelib.logger"] [lint.per-file-ignores] -"src/griffe/__main__.py" = [ +"packages/griffecli/src/griffecli/__main__.py" = [ "D100", # Missing module docstring ] -"src/griffe/_internal/cli.py" = [ +"packages/griffecli/src/griffecli/_internal/cli.py" = [ "T201", # Print statement ] -"src/griffe/_internal/git.py" = [ +"packages/griffelib/src/griffelib/_internal/git.py" = [ "S603", # `subprocess` call: check for execution of untrusted input "S607", # Starting a process with a partial executable path ] -"src/griffe/_internal/agents/nodes/*.py" = [ +"packages/griffelib/src/griffelib/_internal/agents/nodes/*.py" = [ "ARG001", # Unused function argument "N812", # Lowercase `keyword` imported as non-lowercase `NodeKeyword` ] -"src/griffe/_internal/debug.py" = [ +"packages/griffelib/src/griffelib/_internal/debug.py" = [ "T201", # Print statement ] -"src/griffe/_internal/**.py" = [ +"packages/griffelib/src/griffelib/_internal/**.py" = [ "D100", # Missing docstring in public module ] "scripts/*.py" = [ @@ -84,7 +84,7 @@ docstring-quotes = "double" ban-relative-imports = "all" [lint.isort] -known-first-party = ["griffe"] +known-first-party = ["griffe", "griffelib", "griffecli"] [lint.pydocstyle] convention = "google" diff --git a/docs/extensions/official/runtime-objects.md b/docs/extensions/official/runtime-objects.md index fbfb72d34..27b391e8a 100644 --- a/docs/extensions/official/runtime-objects.md +++ b/docs/extensions/official/runtime-objects.md @@ -15,7 +15,7 @@ This extension stores runtime objects corresponding to each loaded Griffe object >>> griffe_data["parse"].extra defaultdict(, {'runtime-objects': {'object': }}) >>> griffe_data["Module"].extra -defaultdict(, {'runtime-objects': {'object': }}) +defaultdict(, {'runtime-objects': {'object': }}) ``` It can be useful in combination with mkdocstrings-python and custom templates, to iterate over object values or their attributes that couldn't be loaded by Griffe itself (for example, objects built dynamically and loaded as attributes won't have "members" to iterate over). diff --git a/docs/guide/contributors/architecture.md b/docs/guide/contributors/architecture.md index edd5a94ec..3fc474e75 100644 --- a/docs/guide/contributors/architecture.md +++ b/docs/guide/contributors/architecture.md @@ -23,7 +23,7 @@ descriptions = { "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).", "src/griffe": "Our public API, exposed to users. See [Program structure](#program-structure).", - "src/griffe/_internal": "Our internal API, hidden from 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.", @@ -104,11 +104,11 @@ Sources are located in the `src` folder, following the [src-layout](https://pack Our test suite is located in the `tests` folder. It is located outside of the sources as to not pollute distributions (it would be very wrong to publish a `tests` package as part of our distributions, since this name is extremely common), or worse, the public API. The `tests` folder is however included in our source distributions (`.tar.gz`), alongside most of our metadata and configuration files. Check out `pyproject.toml` to get the full list of files included in our source distributions. -The test suite is based on [pytest](https://docs.pytest.org/en/8.2.x/). Test modules reflect our internal API structure, and except for a few test modules that test specific aspects of our API, each test module tests the logic from the corresponding module in the internal API. For example, `test_finder.py` tests code of the `griffe._internal.finder` internal module, while `test_functions` tests our ability to extract correct information from function signatures, statically. The general rule of thumb when writing new tests is to mirror the internal API. If a test touches to many aspects of the loading process, it can be added to the `test_loader` test module. +The test suite is based on [pytest](https://docs.pytest.org/en/8.2.x/). Test modules reflect our internal API structure, and except for a few test modules that test specific aspects of our API, each test module tests the logic from the corresponding module in the internal API. For example, `test_finder.py` tests code of the `griffelib._internal.finder` internal module, while `test_functions` tests our ability to extract correct information from function signatures, statically. The general rule of thumb when writing new tests is to mirror the internal API. If a test touches to many aspects of the loading process, it can be added to the `test_loader` test module. ## Program structure -The internal API is contained within the `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 `griffe._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. @@ -122,7 +122,7 @@ if os.getenv("DEPLOY") == "true": from pydeps.target import Target cli.verbose = cli._not_verbose - options = cli.parse_args(["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(): diff --git a/docs/guide/contributors/workflow.md b/docs/guide/contributors/workflow.md index 62d2ff5f4..70fde1107 100644 --- a/docs/guide/contributors/workflow.md +++ b/docs/guide/contributors/workflow.md @@ -56,7 +56,11 @@ 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" +```python title="Remove function when we bump to 5.0" +# YORE: Bump 5: Remove block. +def deprecated_function(): + ... +``` ```python title="Simplify imports when Python 3.15 is EOL" # YORE: EOL 3.15: Replace block with line 4. diff --git a/docs/guide/users/loading.md b/docs/guide/users/loading.md index 620917803..4bbd1c12a 100644 --- a/docs/guide/users/loading.md +++ b/docs/guide/users/loading.md @@ -214,10 +214,10 @@ from package1 import X False >>> package2["X"].target Traceback (most recent call last): - File "griffe/_internal/models.py", line 1375, in _resolve_target + File "griffelib/_internal/models.py", line 1375, in _resolve_target resolved = self.modules_collection.get_member(self.target_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "griffe/_internal/mixins.py", line 84, in get_member + File "griffelib/_internal/mixins.py", line 84, in get_member return self.members[parts[0]].get_member(parts[1:]) # type: ignore[attr-defined] ~~~~~~~~~~~~^^^^^^^^^^ KeyError: 'package1' @@ -226,13 +226,13 @@ The above exception was the direct cause of the following exception: Traceback (most recent call last): File "", line 1, in - File "griffe/_internal/dataclasses.py", line 1310, in target + File "griffelib/_internal/dataclasses.py", line 1310, in target self.resolve_target() - File "griffe/_internal/dataclasses.py", line 1369, in resolve_target + File "griffelib/_internal/dataclasses.py", line 1369, in resolve_target self._resolve_target() - File "griffe/_internal/dataclasses.py", line 1377, in _resolve_target + File "griffelib/_internal/dataclasses.py", line 1377, in _resolve_target raise AliasResolutionError(self) from error -griffe._internal.exceptions.AliasResolutionError: Could not resolve alias package2.X pointing at package1.X (in package2/__init__.py:1) +griffelib._internal.exceptions.AliasResolutionError: Could not resolve alias package2.X pointing at package1.X (in package2/__init__.py:1) ``` As you can see in the interpreter session above, Griffe did not resolve the `X` alias. When we tried to access its target object anyway, it failed with a `KeyError`, which was raised again as an [`AliasResolutionError`][griffe.AliasResolutionError]. @@ -250,7 +250,7 @@ False # Hmm? >>> package2["X"].target Traceback (most recent call last): ... -griffe._internal.exceptions.AliasResolutionError: Could not resolve alias package2.X pointing at package1.X (in package2/__init__.py:1) +griffelib._internal.exceptions.AliasResolutionError: Could not resolve alias package2.X pointing at package1.X (in package2/__init__.py:1) ``` The same exception again? What happened here? We loaded both packages, but Griffe still failed to resolve the alias. That is expected; here is the explanation. diff --git a/docs/guide/users/navigating.md b/docs/guide/users/navigating.md index 75a1a0ab3..1d1c169fe 100644 --- a/docs/guide/users/navigating.md +++ b/docs/guide/users/navigating.md @@ -14,17 +14,17 @@ When [loading an object](loading.md), Griffe will give you back an instance of o ```python >>> import griffe >>> type(griffe.load("markdown")) - + >>> type(griffe.load("markdown.core.Markdown")) - + >>> type(griffe.load("markdown.Markdown")) - + >>> type(griffe.load("markdown.core.markdown")) - + >>> type(griffe.load("markdown.markdown")) - + >>> type(griffe.load("markdown.Markdown.references")) - + ``` However deep the object is, Griffe loads the entire package. It means that in all the cases above, Griffe loaded the whole `markdown` package. The model instance Griffe gives you back is therefore part of a tree that you can navigate. diff --git a/docs/installation.md b/docs/installation.md index 531dcab22..fd61e9b19 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -59,6 +59,65 @@ Griffe is a Python package, so you can install it with your favorite Python pack +## Install as a library only + +If you only need the library for API introspection and analysis without the CLI tool, you can install just `griffelib`: + +=== ":simple-python: pip" + ```bash + pip install griffelib + ``` + +
+ + [pip](https://pip.pypa.io/en/stable/) is the main package installer for Python. + +
+ +=== ":simple-pdm: pdm" + ```bash + pdm add griffelib + ``` + +
+ + [PDM](https://pdm-project.org/en/latest/) is an all-in-one solution for Python project management. + +
+ +=== ":simple-poetry: poetry" + ```bash + poetry add griffelib + ``` + +
+ + [Poetry](https://python-poetry.org/) is an all-in-one solution for Python project management. + +
+ +=== ":simple-rye: rye" + ```bash + rye add griffelib + ``` + +
+ + [Rye](https://rye.astral.sh/) is an all-in-one solution for Python project management, written in Rust. + +
+ +=== ":simple-astral: uv" + ```bash + uv add griffelib + ``` + +
+ + [uv](https://docs.astral.sh/uv/) is an extremely fast Python package and project manager, written in Rust. + +
+ ## Install as a tool only === ":simple-python: pip" @@ -104,3 +163,20 @@ Griffe is a Python package, so you can install it with your favorite Python pack [uv](https://docs.astral.sh/uv/) is an extremely fast Python package and project manager, written in Rust. + +## Running Griffe + +Once installed, you can run Griffe using the `griffe` command: + +```console +$ griffe check mypackage +``` + +Or as a Python module: + +```console +$ python -m griffe check mypackage +``` + +TIP: **Alternative CLI Package** +If you need to run Griffe without the full library, you can also use `python -m griffecli` instead of `python -m griffe`. This runs the CLI directly from the `griffecli` package. diff --git a/docs/introduction.md b/docs/introduction.md index a7226fa6e..91d99cc8c 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -22,10 +22,10 @@ Both commands accept a `-h`, `--help` argument to show all the available options ## Python library -As a library, Griffe exposes all its public API directly in the top-level module. It means you can simply import `griffe` to access all its API. +As a library, Griffe exposes all its public API directly in the top-level module. It means you can simply import `griffe` or `griffelib` to access all its API. ```python -import griffe +import griffe # or griffelib griffe.load(...) griffe.find_breaking_changes(...) diff --git a/docs/reference/api/agents.md b/docs/reference/api/agents.md index ca7f50c4d..c977ebe2b 100644 --- a/docs/reference/api/agents.md +++ b/docs/reference/api/agents.md @@ -4,7 +4,7 @@ Griffe is able to analyze code both statically and dynamically. ## **Main API** -::: griffe.visit +::: griffelib.visit ::: griffe.inspect diff --git a/docs/reference/api/cli.md b/docs/reference/api/cli.md index 08e83a31a..8d4d27143 100644 --- a/docs/reference/api/cli.md +++ b/docs/reference/api/cli.md @@ -2,7 +2,7 @@ ## **Main API** -::: griffe.main +::: griffecli.main ::: griffe.check diff --git a/docs/reference/api/expressions.md b/docs/reference/api/expressions.md index 3b010a5d0..d91795c79 100644 --- a/docs/reference/api/expressions.md +++ b/docs/reference/api/expressions.md @@ -1,6 +1,6 @@ # Expressions -::: griffe._internal.expressions +::: griffelib._internal.expressions options: members: false show_root_heading: false diff --git a/duties.py b/duties.py index d3f1178cd..a2f8d7d61 100644 --- a/duties.py +++ b/duties.py @@ -285,7 +285,7 @@ def check_api(ctx: Context, *cli_args: str) -> None: *cli_args: Additional Griffe CLI arguments. """ ctx.run( - tools.griffe.check( + tools.griffecli.check( "griffe", search=["src"], color=True, diff --git a/packages/griffecli/pyproject.toml b/packages/griffecli/pyproject.toml new file mode 100644 index 000000000..b9a6525f8 --- /dev/null +++ b/packages/griffecli/pyproject.toml @@ -0,0 +1,57 @@ +[build-system] +# pdm-backend is left here as a dependency of the version discovery script currently in use. +# It may be removed in the future. See mkdocstrings/griffe#430 +requires = ["hatchling", "pdm-backend", "uv-dynamic-versioning>=0.7.0"] +build-backend = "hatchling.build" + +[project] +name = "griffecli" +description = "The Griffe CLI" +authors = [{name = "Timothée Mazzucotelli", email = "dev@pawamoy.fr"}] +license = "ISC" +license-files = ["LICENSE"] +requires-python = ">=3.10" +keywords = ["api", "signature", "breaking-changes", "static-analysis", "dynamic-analysis"] +dynamic = ["version", "dependencies", "optional-dependencies"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + # YORE: EOL 3.10: Remove line. + "Programming Language :: Python :: 3.10", + # YORE: EOL 3.11: Remove line. + "Programming Language :: Python :: 3.11", + # YORE: EOL 3.12: Remove line. + "Programming Language :: Python :: 3.12", + # YORE: EOL 3.13: Remove line. + "Programming Language :: Python :: 3.13", + # YORE: EOL 3.14: Remove line. + "Programming Language :: Python :: 3.14", + "Topic :: Documentation", + "Topic :: Software Development", + "Topic :: Software Development :: Documentation", + "Topic :: Utilities", + "Typing :: Typed", +] + +[project.scripts] +griffecli = "griffecli:main" + +[tool.hatch.version] +source = "code" +path = "../../scripts/get_version.py" +expression = "get_version()" + +[tool.hatch.metadata.hooks.uv-dynamic-versioning] +# Dependencies are dynamically versioned; {{version}} is substituted at build time. +dependencies = ["griffelib=={{version}}", "colorama>=0.4"] + +[tool.hatch.metadata.hooks.uv-dynamic-versioning.optional-dependencies] +# No optional dependencies for the CLI package + +[tool.hatch.build.targets.sdist] + +[tool.hatch.build.targets.wheel] +sources = ["src/"] diff --git a/packages/griffecli/src/griffecli/__init__.py b/packages/griffecli/src/griffecli/__init__.py new file mode 100644 index 000000000..b7c23fc12 --- /dev/null +++ b/packages/griffecli/src/griffecli/__init__.py @@ -0,0 +1,27 @@ +# This top-level module imports all public names from the CLI package, +# and exposes them as public objects. + +"""Griffe CLI package. + +The CLI (Command Line Interface) for the griffe library. +This package provides command-line tools for interacting with griffe. + +## CLI entrypoints + +- [`griffecli.main`][]: Run the main program. +- [`griffecli.check`][]: Check for API breaking changes in two versions of the same package. +- [`griffecli.dump`][]: Load packages data and dump it as JSON. +- [`griffecli.get_parser`][]: Get the argument parser for the CLI. +""" + +from __future__ import annotations + +from griffecli._internal.cli import DEFAULT_LOG_LEVEL, check, dump, get_parser, main + +__all__ = [ + "DEFAULT_LOG_LEVEL", + "check", + "dump", + "get_parser", + "main", +] diff --git a/packages/griffecli/src/griffecli/__main__.py b/packages/griffecli/src/griffecli/__main__.py new file mode 100644 index 000000000..22d5b7441 --- /dev/null +++ b/packages/griffecli/src/griffecli/__main__.py @@ -0,0 +1,13 @@ +# Entry-point module, in case you use `python -m griffecli`. +# +# Why does this file exist, and why `__main__`? For more info, read: +# +# - https://www.python.org/dev/peps/pep-0338/ +# - https://docs.python.org/3/using/cmdline.html#cmdoption-m + +import sys + +from griffecli._internal.cli import main + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/packages/griffecli/src/griffecli/_internal/__init__.py b/packages/griffecli/src/griffecli/_internal/__init__.py new file mode 100644 index 000000000..03d25ad8f --- /dev/null +++ b/packages/griffecli/src/griffecli/_internal/__init__.py @@ -0,0 +1 @@ +# Internal modules for the griffecli package. diff --git a/src/griffe/_internal/cli.py b/packages/griffecli/src/griffecli/_internal/cli.py similarity index 96% rename from src/griffe/_internal/cli.py rename to packages/griffecli/src/griffecli/_internal/cli.py index 1f6c767f5..a78a52fbe 100644 --- a/src/griffe/_internal/cli.py +++ b/packages/griffecli/src/griffecli/_internal/cli.py @@ -4,11 +4,11 @@ # We might be tempted to import things from `__main__` later, # but that will cause problems; the code will get executed twice: # -# - When we run `python -m griffe`, Python will execute +# - When we run `python -m griffecli`, Python will execute # `__main__.py` as a script. That means there won't be any -# `griffe.__main__` in `sys.modules`. +# `griffecli.__main__` in `sys.modules`. # - When you import `__main__` it will get executed again (as a module) because -# there's no `griffe.__main__` in `sys.modules`. +# there's no `griffecli.__main__` in `sys.modules`. from __future__ import annotations @@ -24,21 +24,21 @@ import colorama -from griffe._internal import debug -from griffe._internal.diff import find_breaking_changes -from griffe._internal.encoders import JSONEncoder -from griffe._internal.enumerations import ExplanationStyle, Parser -from griffe._internal.exceptions import ExtensionError, GitError -from griffe._internal.extensions.base import load_extensions -from griffe._internal.git import _get_latest_tag, _get_repo_root -from griffe._internal.loader import GriffeLoader, load, load_git, load_pypi -from griffe._internal.logger import logger +from griffelib._internal import debug +from griffelib._internal.diff import find_breaking_changes +from griffelib._internal.encoders import JSONEncoder +from griffelib._internal.enumerations import ExplanationStyle, Parser +from griffelib._internal.exceptions import ExtensionError, GitError +from griffelib._internal.extensions.base import load_extensions +from griffelib._internal.git import _get_latest_tag, _get_repo_root +from griffelib._internal.loader import GriffeLoader, load, load_git, load_pypi +from griffelib._internal.logger import logger if TYPE_CHECKING: from collections.abc import Sequence - from griffe._internal.docstrings.parsers import DocstringOptions, DocstringStyle - from griffe._internal.extensions.base import Extension, Extensions + from griffelib._internal.docstrings.parsers import DocstringOptions, DocstringStyle + from griffelib._internal.extensions.base import Extension, Extensions DEFAULT_LOG_LEVEL = os.getenv("GRIFFE_LOG_LEVEL", "INFO").upper() diff --git a/packages/griffelib/pyproject.toml b/packages/griffelib/pyproject.toml new file mode 100644 index 000000000..e445c11e2 --- /dev/null +++ b/packages/griffelib/pyproject.toml @@ -0,0 +1,55 @@ +[build-system] +# pdm-backend is left here as a dependency of the version discovery script currently in use. +# It may be removed in the future. See mkdocstrings/griffe#430 +requires = ["hatchling", "pdm-backend", "uv-dynamic-versioning>=0.7.0"] +build-backend = "hatchling.build" + +[project] +name = "griffelib" +description = "The Griffe library" +authors = [{name = "Timothée Mazzucotelli", email = "dev@pawamoy.fr"}] +license = "ISC" +license-files = ["LICENSE"] +requires-python = ">=3.10" +keywords = ["api", "signature", "breaking-changes", "static-analysis", "dynamic-analysis"] +dynamic = ["version", "dependencies", "optional-dependencies"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + # YORE: EOL 3.10: Remove line. + "Programming Language :: Python :: 3.10", + # YORE: EOL 3.11: Remove line. + "Programming Language :: Python :: 3.11", + # YORE: EOL 3.12: Remove line. + "Programming Language :: Python :: 3.12", + # YORE: EOL 3.13: Remove line. + "Programming Language :: Python :: 3.13", + # YORE: EOL 3.14: Remove line. + "Programming Language :: Python :: 3.14", + "Topic :: Documentation", + "Topic :: Software Development", + "Topic :: Software Development :: Documentation", + "Topic :: Utilities", + "Typing :: Typed", +] + +[tool.hatch.version] +source = "code" +path = "../../scripts/get_version.py" +expression = "get_version()" + +[tool.hatch.metadata.hooks.uv-dynamic-versioning] +# No base dependencies needed for griffelib + +[tool.hatch.metadata.hooks.uv-dynamic-versioning.optional-dependencies] +# The 'pypi' extra provides dependencies needed for the load_pypi functionality +# to download and inspect packages from PyPI. +pypi = ["pip>=24.0", "platformdirs>=4.2", "wheel>=0.42"] + +[tool.hatch.build.targets.sdist] + +[tool.hatch.build.targets.wheel] +sources = ["src/"] diff --git a/packages/griffelib/src/griffelib/__init__.py b/packages/griffelib/src/griffelib/__init__.py new file mode 100644 index 000000000..7e9f74d4f --- /dev/null +++ b/packages/griffelib/src/griffelib/__init__.py @@ -0,0 +1,594 @@ +# This top-level module imports all public names from the package, +# and exposes them as public objects. We have tests to make sure +# no object is forgotten in this list. + +"""Griffe library package. + +Signatures for entire Python programs. +Extract the structure, the frame, the skeleton of your project, +to generate API documentation or find breaking changes in your API. + +The entirety of the library API is exposed here, in the top-level `griffelib` module. +For backward compatibility, you can also import from `griffe` which re-exports everything. + +All messages written to standard output or error are logged using the `logging` module. +Our logger's name is set to `"griffe"` and is public (you can rely on it). +You can obtain the logger from the standard `logging` module: `logging.getLogger("griffe")`. +Actual logging messages are not part of the public API (they might change without notice). + +Raised exceptions throughout the package are part of the public API (you can rely on them). +Their actual messages are not part of the public API (they might change without notice). + +The following paragraphs will help you discover the package's content. + +## Loaders + +To load API data, Griffe provides several high-level functions. + +- [`griffe.load`][]: Load and return a Griffe object. +- [`griffe.load_git`][]: Load and return a module from a specific Git reference. +- [`griffe.load_pypi`][]: Load and return a module from a specific package version downloaded using pip. + +## Models + +The data loaded by Griffe is represented by several classes. + +- [`griffe.Module`][]: The class representing a Python module. +- [`griffe.Class`][]: The class representing a Python class. +- [`griffe.Function`][]: The class representing a Python function or method. +- [`griffe.Attribute`][]: The class representing a Python attribute. +- [`griffe.Alias`][]: This class represents an alias, or indirection, to an object declared in another module. + +Additional classes are available to represent other concepts. + +- [`griffe.Decorator`][]: This class represents a decorator. +- [`griffe.Parameters`][]: This class is a container for parameters. +- [`griffe.Parameter`][]: This class represent a function parameter. + +## Agents + +Griffe is able to analyze code both statically and dynamically, using the following "agents". +However most of the time you will only need to use the loaders above. + +- [`griffe.visit`][]: Parse and visit a module file. +- [`griffe.inspect`][]: Inspect a module. + +## Serializers + +Griffe can serizalize data to dictionary and JSON. + +- [`griffe.Object.as_json`][griffe.Object.as_json] +- [`griffe.Object.from_json`][griffe.Object.from_json] +- [`griffe.JSONEncoder`][]: JSON encoder for Griffe objects. +- [`griffe.json_decoder`][]: JSON decoder for Griffe objects. + +## API checks + +Griffe can compare two versions of the same package to find breaking changes. + +- [`griffe.find_breaking_changes`][]: Find breaking changes between two versions of the same API. +- [`griffe.Breakage`][]: Breakage classes can explain what broke from a version to another. + +## Extensions + +Griffe supports extensions. You can create your own extension by subclassing the `griffe.Extension` class. + +- [`griffe.load_extensions`][]: Load configured extensions. +- [`griffe.Extension`][]: Base class for Griffe extensions. + +## Docstrings + +Griffe can parse docstrings into structured data. + +Main class: + +- [`griffe.Docstring`][]: This class represents docstrings. + +Docstring section and element classes all start with `Docstring`. + +Docstring parsers: + +- [`griffe.parse`][]: Parse the docstring. +- [`griffe.parse_auto`][]: Parse a docstring by automatically detecting the style it uses. +- [`griffe.parse_google`][]: Parse a Google-style docstring. +- [`griffe.parse_numpy`][]: Parse a Numpydoc-style docstring. +- [`griffe.parse_sphinx`][]: Parse a Sphinx-style docstring. + +## Exceptions + +Griffe uses several exceptions to signal errors. + +- [`griffe.GriffeError`][]: The base exception for all Griffe errors. +- [`griffe.LoadingError`][]: Exception for loading errors. +- [`griffe.NameResolutionError`][]: Exception for names that cannot be resolved in a object scope. +- [`griffe.UnhandledEditableModuleError`][]: Exception for unhandled editables modules, when searching modules. +- [`griffe.UnimportableModuleError`][]: Exception for modules that cannot be imported. +- [`griffe.AliasResolutionError`][]: Exception for aliases that cannot be resolved. +- [`griffe.CyclicAliasError`][]: Exception raised when a cycle is detected in aliases. +- [`griffe.LastNodeError`][]: Exception raised when trying to access a next or previous node. +- [`griffe.RootNodeError`][]: Exception raised when trying to use siblings properties on a root node. +- [`griffe.BuiltinModuleError`][]: Exception raised when trying to access the filepath of a builtin module. +- [`griffe.ExtensionError`][]: Base class for errors raised by extensions. +- [`griffe.ExtensionNotLoadedError`][]: Exception raised when an extension could not be loaded. +- [`griffe.GitError`][]: Exception raised for errors related to Git. + +# Expressions + +Griffe stores snippets of code (attribute values, decorators, base class, type annotations) as expressions. +Expressions are basically abstract syntax trees (AST) with a few differences compared to the nodes returned by [`ast`][]. +Griffe provides a few helpers to extract expressions from regular AST nodes. + +- [`griffe.get_annotation`][]: Get a type annotation as expression. +- [`griffe.get_base_class`][]: Get a base class as expression. +- [`griffe.get_class_keyword`][]: Get a class keyword as expression. +- [`griffe.get_condition`][]: Get a condition as expression. +- [`griffe.get_expression`][]: Get an expression from an AST node. +- [`griffe.safe_get_annotation`][]: Get a type annotation as expression, safely (returns `None` on error). +- [`griffe.safe_get_base_class`][]: Get a base class as expression, safely (returns `None` on error). +- [`griffe.safe_get_class_keyword`][]: Get a class keyword as expression, safely (returns `None` on error). +- [`griffe.safe_get_condition`][]: Get a condition as expression, safely (returns `None` on error). +- [`griffe.safe_get_expression`][]: Get an expression from an AST node, safely (returns `None` on error). + +The base class for expressions. + +- [`griffe.Expr`][] + +Expression classes all start with `Expr`. + +# Loggers + +If you want to log messages from extensions, get a logger with `get_logger`. +The `logger` attribute is used by Griffe itself. You can use it to temporarily disable Griffe logging. + +- [`griffe.logger`][]: Our global logger, used throughout the library. +- [`griffe.get_logger`][]: Create and return a new logger instance. + +# Helpers + +To test your Griffe extensions, or to load API data from code in memory, Griffe provides the following helpers. + +- [`griffe.temporary_pyfile`][]: Create a Python file containing the given code in a temporary directory. +- [`griffe.temporary_pypackage`][]: Create a package containing the given modules in a temporary directory. +- [`griffe.temporary_visited_module`][]: Create and visit a temporary module with the given code. +- [`griffe.temporary_visited_package`][]: Create and visit a temporary package. +- [`griffe.temporary_inspected_module`][]: Create and inspect a temporary module with the given code. +- [`griffe.temporary_inspected_package`][]: Create and inspect a temporary package. +""" + +from __future__ import annotations + +from griffelib._internal.agents.inspector import Inspector, inspect +from griffelib._internal.agents.nodes.assignments import get_instance_names, get_name, get_names +from griffelib._internal.agents.nodes.ast import ( + ast_children, + ast_first_child, + ast_kind, + ast_last_child, + ast_next, + ast_next_siblings, + ast_previous, + ast_previous_siblings, + ast_siblings, +) +from griffelib._internal.agents.nodes.docstrings import get_docstring +from griffelib._internal.agents.nodes.exports import get__all__, safe_get__all__ +from griffelib._internal.agents.nodes.imports import relative_to_absolute +from griffelib._internal.agents.nodes.parameters import ParametersType, get_parameters +from griffelib._internal.agents.nodes.runtime import ObjectNode +from griffelib._internal.agents.nodes.values import get_value, safe_get_value +from griffelib._internal.agents.visitor import Visitor, builtin_decorators, stdlib_decorators, typing_overload, visit +from griffelib._internal.c3linear import c3linear_merge +from griffelib._internal.collections import LinesCollection, ModulesCollection +from griffelib._internal.diff import ( + AttributeChangedTypeBreakage, + AttributeChangedValueBreakage, + Breakage, + ClassRemovedBaseBreakage, + ObjectChangedKindBreakage, + ObjectRemovedBreakage, + ParameterAddedRequiredBreakage, + ParameterChangedDefaultBreakage, + ParameterChangedKindBreakage, + ParameterChangedRequiredBreakage, + ParameterMovedBreakage, + ParameterRemovedBreakage, + ReturnChangedTypeBreakage, + find_breaking_changes, +) +from griffelib._internal.docstrings.auto import ( + AutoOptions, + DocstringDetectionMethod, + PerStyleOptions, + infer_docstring_style, + parse_auto, +) +from griffelib._internal.docstrings.google import GoogleOptions, parse_google +from griffelib._internal.docstrings.models import ( + DocstringAdmonition, + DocstringAttribute, + DocstringClass, + DocstringDeprecated, + DocstringElement, + DocstringFunction, + DocstringModule, + DocstringNamedElement, + DocstringParameter, + DocstringRaise, + DocstringReceive, + DocstringReturn, + DocstringSection, + DocstringSectionAdmonition, + DocstringSectionAttributes, + DocstringSectionClasses, + DocstringSectionDeprecated, + DocstringSectionExamples, + DocstringSectionFunctions, + DocstringSectionModules, + DocstringSectionOtherParameters, + DocstringSectionParameters, + DocstringSectionRaises, + DocstringSectionReceives, + DocstringSectionReturns, + DocstringSectionText, + DocstringSectionTypeAliases, + DocstringSectionTypeParameters, + DocstringSectionWarns, + DocstringSectionYields, + DocstringTypeAlias, + DocstringTypeParameter, + DocstringWarn, + DocstringYield, +) +from griffelib._internal.docstrings.numpy import NumpyOptions, parse_numpy +from griffelib._internal.docstrings.parsers import ( + DocstringOptions, + DocstringStyle, + parse, + parsers, +) +from griffelib._internal.docstrings.sphinx import SphinxOptions, parse_sphinx +from griffelib._internal.docstrings.utils import docstring_warning, parse_docstring_annotation +from griffelib._internal.encoders import JSONEncoder, json_decoder +from griffelib._internal.enumerations import ( + BreakageKind, + DocstringSectionKind, + ExplanationStyle, + Kind, + LogLevel, + ObjectKind, + ParameterKind, + Parser, + TypeParameterKind, +) +from griffelib._internal.exceptions import ( + AliasResolutionError, + BuiltinModuleError, + CyclicAliasError, + ExtensionError, + ExtensionNotLoadedError, + GitError, + GriffeError, + LastNodeError, + LoadingError, + NameResolutionError, + RootNodeError, + UnhandledEditableModuleError, + UnimportableModuleError, +) +from griffelib._internal.expressions import ( + Expr, + ExprAttribute, + ExprBinOp, + ExprBoolOp, + ExprCall, + ExprCompare, + ExprComprehension, + ExprConstant, + ExprDict, + ExprDictComp, + ExprExtSlice, + ExprFormatted, + ExprGeneratorExp, + ExprIfExp, + ExprJoinedStr, + ExprKeyword, + ExprLambda, + ExprList, + ExprListComp, + ExprName, + ExprNamedExpr, + ExprParameter, + ExprSet, + ExprSetComp, + ExprSlice, + ExprSubscript, + ExprTuple, + ExprUnaryOp, + ExprVarKeyword, + ExprVarPositional, + ExprYield, + ExprYieldFrom, + get_annotation, + get_base_class, + get_class_keyword, + get_condition, + get_expression, + safe_get_annotation, + safe_get_base_class, + safe_get_class_keyword, + safe_get_condition, + safe_get_expression, +) +from griffelib._internal.extensions.base import ( + Extension, + Extensions, + LoadableExtensionType, + builtin_extensions, + load_extensions, +) +from griffelib._internal.extensions.dataclasses import DataclassesExtension +from griffelib._internal.extensions.unpack_typeddict import UnpackTypedDictExtension +from griffelib._internal.finder import ModuleFinder, NamePartsAndPathType, NamePartsType, NamespacePackage, Package +from griffelib._internal.git import GitInfo, KnownGitService +from griffelib._internal.importer import dynamic_import, sys_path +from griffelib._internal.loader import GriffeLoader, load, load_git, load_pypi +from griffelib._internal.logger import Logger, get_logger, logger, patch_loggers +from griffelib._internal.merger import merge_stubs +from griffelib._internal.mixins import ( + DelMembersMixin, + GetMembersMixin, + ObjectAliasMixin, + SerializationMixin, + SetMembersMixin, +) +from griffelib._internal.models import ( + Alias, + Attribute, + Class, + Decorator, + Docstring, + Function, + Module, + Object, + Parameter, + Parameters, + TypeAlias, + TypeParameter, + TypeParameters, +) +from griffelib._internal.stats import Stats +from griffelib._internal.tests import ( + TmpPackage, + htree, + module_vtree, + temporary_inspected_module, + temporary_inspected_package, + temporary_pyfile, + temporary_pypackage, + temporary_visited_module, + temporary_visited_package, + vtree, +) + +# Regenerate this list with the following Python snippet: +# import griffelib +# names = sorted(n for n in dir(griffelib) if not n.startswith("_") and n not in ("annotations",)) +# print('__all__ = [\n "' + '",\n "'.join(names) + '",\n]') +__all__ = [ + "Alias", + "AliasResolutionError", + "Attribute", + "AttributeChangedTypeBreakage", + "AttributeChangedValueBreakage", + "AutoOptions", + "Breakage", + "BreakageKind", + "BuiltinModuleError", + "Class", + "ClassRemovedBaseBreakage", + "CyclicAliasError", + "DataclassesExtension", + "Decorator", + "DelMembersMixin", + "Docstring", + "DocstringAdmonition", + "DocstringAttribute", + "DocstringClass", + "DocstringDeprecated", + "DocstringDetectionMethod", + "DocstringElement", + "DocstringFunction", + "DocstringModule", + "DocstringNamedElement", + "DocstringOptions", + "DocstringParameter", + "DocstringRaise", + "DocstringReceive", + "DocstringReturn", + "DocstringSection", + "DocstringSectionAdmonition", + "DocstringSectionAttributes", + "DocstringSectionClasses", + "DocstringSectionDeprecated", + "DocstringSectionExamples", + "DocstringSectionFunctions", + "DocstringSectionKind", + "DocstringSectionModules", + "DocstringSectionOtherParameters", + "DocstringSectionParameters", + "DocstringSectionRaises", + "DocstringSectionReceives", + "DocstringSectionReturns", + "DocstringSectionText", + "DocstringSectionTypeAliases", + "DocstringSectionTypeParameters", + "DocstringSectionWarns", + "DocstringSectionYields", + "DocstringStyle", + "DocstringTypeAlias", + "DocstringTypeParameter", + "DocstringWarn", + "DocstringYield", + "ExplanationStyle", + "Expr", + "ExprAttribute", + "ExprBinOp", + "ExprBoolOp", + "ExprCall", + "ExprCompare", + "ExprComprehension", + "ExprConstant", + "ExprDict", + "ExprDictComp", + "ExprExtSlice", + "ExprFormatted", + "ExprGeneratorExp", + "ExprIfExp", + "ExprJoinedStr", + "ExprKeyword", + "ExprLambda", + "ExprList", + "ExprListComp", + "ExprName", + "ExprNamedExpr", + "ExprParameter", + "ExprSet", + "ExprSetComp", + "ExprSlice", + "ExprSubscript", + "ExprTuple", + "ExprUnaryOp", + "ExprVarKeyword", + "ExprVarPositional", + "ExprYield", + "ExprYieldFrom", + "Extension", + "ExtensionError", + "ExtensionNotLoadedError", + "Extensions", + "Function", + "GetMembersMixin", + "GitError", + "GitInfo", + "GoogleOptions", + "GriffeError", + "GriffeLoader", + "Inspector", + "JSONEncoder", + "Kind", + "KnownGitService", + "LastNodeError", + "LinesCollection", + "LoadableExtensionType", + "LoadingError", + "LogLevel", + "Logger", + "Module", + "ModuleFinder", + "ModulesCollection", + "NamePartsAndPathType", + "NamePartsType", + "NameResolutionError", + "NamespacePackage", + "NumpyOptions", + "Object", + "ObjectAliasMixin", + "ObjectChangedKindBreakage", + "ObjectKind", + "ObjectNode", + "ObjectRemovedBreakage", + "Package", + "Parameter", + "ParameterAddedRequiredBreakage", + "ParameterChangedDefaultBreakage", + "ParameterChangedKindBreakage", + "ParameterChangedRequiredBreakage", + "ParameterKind", + "ParameterMovedBreakage", + "ParameterRemovedBreakage", + "Parameters", + "ParametersType", + "Parser", + "PerStyleOptions", + "ReturnChangedTypeBreakage", + "RootNodeError", + "SerializationMixin", + "SetMembersMixin", + "SphinxOptions", + "Stats", + "TmpPackage", + "TypeAlias", + "TypeParameter", + "TypeParameterKind", + "TypeParameters", + "UnhandledEditableModuleError", + "UnimportableModuleError", + "UnpackTypedDictExtension", + "Visitor", + "ast_children", + "ast_first_child", + "ast_kind", + "ast_last_child", + "ast_next", + "ast_next_siblings", + "ast_previous", + "ast_previous_siblings", + "ast_siblings", + "builtin_decorators", + "builtin_extensions", + "c3linear_merge", + "docstring_warning", + "dynamic_import", + "find_breaking_changes", + "get__all__", + "get_annotation", + "get_base_class", + "get_class_keyword", + "get_condition", + "get_docstring", + "get_expression", + "get_instance_names", + "get_logger", + "get_name", + "get_names", + "get_parameters", + "get_value", + "htree", + "infer_docstring_style", + "inspect", + "json_decoder", + "load", + "load_extensions", + "load_git", + "load_pypi", + "logger", + "merge_stubs", + "module_vtree", + "parse", + "parse_auto", + "parse_docstring_annotation", + "parse_google", + "parse_numpy", + "parse_sphinx", + "parsers", + "patch_loggers", + "relative_to_absolute", + "safe_get__all__", + "safe_get_annotation", + "safe_get_base_class", + "safe_get_class_keyword", + "safe_get_condition", + "safe_get_expression", + "safe_get_value", + "stdlib_decorators", + "sys_path", + "temporary_inspected_module", + "temporary_inspected_package", + "temporary_pyfile", + "temporary_pypackage", + "temporary_visited_module", + "temporary_visited_package", + "typing_overload", + "visit", + "vtree", +] diff --git a/src/griffe/_internal/__init__.py b/packages/griffelib/src/griffelib/_internal/__init__.py similarity index 100% rename from src/griffe/_internal/__init__.py rename to packages/griffelib/src/griffelib/_internal/__init__.py diff --git a/src/griffe/_internal/agents/__init__.py b/packages/griffelib/src/griffelib/_internal/agents/__init__.py similarity index 100% rename from src/griffe/_internal/agents/__init__.py rename to packages/griffelib/src/griffelib/_internal/agents/__init__.py diff --git a/src/griffe/_internal/agents/inspector.py b/packages/griffelib/src/griffelib/_internal/agents/inspector.py similarity index 96% rename from src/griffe/_internal/agents/inspector.py rename to packages/griffelib/src/griffelib/_internal/agents/inspector.py index 1ff89bfe6..7eb5df5c2 100644 --- a/src/griffe/_internal/agents/inspector.py +++ b/packages/griffelib/src/griffelib/_internal/agents/inspector.py @@ -12,14 +12,14 @@ from inspect import signature as getsignature from typing import TYPE_CHECKING, Any -from griffe._internal.agents.nodes.runtime import ObjectNode -from griffe._internal.collections import LinesCollection, ModulesCollection -from griffe._internal.enumerations import Kind, ParameterKind, TypeParameterKind -from griffe._internal.expressions import Expr, ExprBinOp, ExprSubscript, ExprTuple, safe_get_annotation -from griffe._internal.extensions.base import Extensions, load_extensions -from griffe._internal.importer import dynamic_import -from griffe._internal.logger import logger -from griffe._internal.models import ( +from griffelib._internal.agents.nodes.runtime import ObjectNode +from griffelib._internal.collections import LinesCollection, ModulesCollection +from griffelib._internal.enumerations import Kind, ParameterKind, TypeParameterKind +from griffelib._internal.expressions import Expr, ExprBinOp, ExprSubscript, ExprTuple, safe_get_annotation +from griffelib._internal.extensions.base import Extensions, load_extensions +from griffelib._internal.importer import dynamic_import +from griffelib._internal.logger import logger +from griffelib._internal.models import ( Alias, Attribute, Class, @@ -37,8 +37,8 @@ from collections.abc import Sequence from pathlib import Path - from griffe._internal.docstrings.parsers import DocstringOptions, DocstringStyle - from griffe._internal.enumerations import Parser + from griffelib._internal.docstrings.parsers import DocstringOptions, DocstringStyle + from griffelib._internal.enumerations import Parser _TYPING_MODULES: tuple[types.ModuleType, ...] try: @@ -75,16 +75,16 @@ def inspect( In this case, we load the module using introspection. Griffe therefore provides this function for dynamic analysis. - It uses a [`NodeVisitor`][ast.NodeVisitor]-like class, the [`Inspector`][griffe.Inspector], + It uses a [`NodeVisitor`][ast.NodeVisitor]-like class, the [`Inspector`][griffelib.Inspector], to inspect the module with [`inspect.getmembers()`][inspect.getmembers]. - The inspection agent works similarly to the regular [`Visitor`][griffe.Visitor] agent, + The inspection agent works similarly to the regular [`Visitor`][griffelib.Visitor] agent, in that it maintains a state with the current object being handled, and recursively handle its members. Important: This function is generally not used directly. - In most cases, users can rely on the [`GriffeLoader`][griffe.GriffeLoader] - and its accompanying [`load`][griffe.load] shortcut and their respective options + In most cases, users can rely on the [`GriffeLoader`][griffelib.GriffeLoader] + and its accompanying [`load`][griffelib.load] shortcut and their respective options to load modules using dynamic analysis. Parameters: diff --git a/src/griffe/_internal/agents/nodes/__init__.py b/packages/griffelib/src/griffelib/_internal/agents/nodes/__init__.py similarity index 100% rename from src/griffe/_internal/agents/nodes/__init__.py rename to packages/griffelib/src/griffelib/_internal/agents/nodes/__init__.py diff --git a/src/griffe/_internal/agents/nodes/assignments.py b/packages/griffelib/src/griffelib/_internal/agents/nodes/assignments.py similarity index 100% rename from src/griffe/_internal/agents/nodes/assignments.py rename to packages/griffelib/src/griffelib/_internal/agents/nodes/assignments.py diff --git a/src/griffe/_internal/agents/nodes/ast.py b/packages/griffelib/src/griffelib/_internal/agents/nodes/ast.py similarity index 98% rename from src/griffe/_internal/agents/nodes/ast.py rename to packages/griffelib/src/griffelib/_internal/agents/nodes/ast.py index 9cb261486..778fd75ef 100644 --- a/src/griffe/_internal/agents/nodes/ast.py +++ b/packages/griffelib/src/griffelib/_internal/agents/nodes/ast.py @@ -5,7 +5,7 @@ from ast import AST from typing import TYPE_CHECKING -from griffe._internal.exceptions import LastNodeError +from griffelib._internal.exceptions import LastNodeError if TYPE_CHECKING: from collections.abc import Iterator diff --git a/src/griffe/_internal/agents/nodes/docstrings.py b/packages/griffelib/src/griffelib/_internal/agents/nodes/docstrings.py similarity index 100% rename from src/griffe/_internal/agents/nodes/docstrings.py rename to packages/griffelib/src/griffelib/_internal/agents/nodes/docstrings.py diff --git a/src/griffe/_internal/agents/nodes/exports.py b/packages/griffelib/src/griffelib/_internal/agents/nodes/exports.py similarity index 91% rename from src/griffe/_internal/agents/nodes/exports.py rename to packages/griffelib/src/griffelib/_internal/agents/nodes/exports.py index d726e9c03..657c752e0 100644 --- a/src/griffe/_internal/agents/nodes/exports.py +++ b/packages/griffelib/src/griffelib/_internal/agents/nodes/exports.py @@ -6,13 +6,13 @@ from contextlib import suppress from typing import TYPE_CHECKING, Any, Callable -from griffe._internal.agents.nodes.values import get_value -from griffe._internal.enumerations import LogLevel -from griffe._internal.expressions import ExprName -from griffe._internal.logger import logger +from griffelib._internal.agents.nodes.values import get_value +from griffelib._internal.enumerations import LogLevel +from griffelib._internal.expressions import ExprName +from griffelib._internal.logger import logger if TYPE_CHECKING: - from griffe._internal.models import Module + from griffelib._internal.models import Module def _extract_attribute(node: ast.Attribute, parent: Module) -> list[str | ExprName]: diff --git a/src/griffe/_internal/agents/nodes/imports.py b/packages/griffelib/src/griffelib/_internal/agents/nodes/imports.py similarity index 95% rename from src/griffe/_internal/agents/nodes/imports.py rename to packages/griffelib/src/griffelib/_internal/agents/nodes/imports.py index c194d07bc..25b5cf1b6 100644 --- a/src/griffe/_internal/agents/nodes/imports.py +++ b/packages/griffelib/src/griffelib/_internal/agents/nodes/imports.py @@ -7,7 +7,7 @@ if TYPE_CHECKING: import ast - from griffe._internal.models import Module + from griffelib._internal.models import Module def relative_to_absolute(node: ast.ImportFrom, name: ast.alias, current_module: Module) -> str: diff --git a/src/griffe/_internal/agents/nodes/parameters.py b/packages/griffelib/src/griffelib/_internal/agents/nodes/parameters.py similarity index 97% rename from src/griffe/_internal/agents/nodes/parameters.py rename to packages/griffelib/src/griffelib/_internal/agents/nodes/parameters.py index b6b6f445d..349be63d1 100644 --- a/src/griffe/_internal/agents/nodes/parameters.py +++ b/packages/griffelib/src/griffelib/_internal/agents/nodes/parameters.py @@ -6,7 +6,7 @@ from itertools import zip_longest from typing import TYPE_CHECKING, Optional, Union -from griffe._internal.enumerations import ParameterKind +from griffelib._internal.enumerations import ParameterKind if TYPE_CHECKING: from collections.abc import Iterable diff --git a/src/griffe/_internal/agents/nodes/runtime.py b/packages/griffelib/src/griffelib/_internal/agents/nodes/runtime.py similarity index 99% rename from src/griffe/_internal/agents/nodes/runtime.py rename to packages/griffelib/src/griffelib/_internal/agents/nodes/runtime.py index b63d4f9c9..693a82a8f 100644 --- a/src/griffe/_internal/agents/nodes/runtime.py +++ b/packages/griffelib/src/griffelib/_internal/agents/nodes/runtime.py @@ -9,8 +9,8 @@ from types import GetSetDescriptorType, ModuleType from typing import TYPE_CHECKING, Any, ClassVar -from griffe._internal.enumerations import ObjectKind -from griffe._internal.logger import logger +from griffelib._internal.enumerations import ObjectKind +from griffelib._internal.logger import logger if TYPE_CHECKING: import types diff --git a/src/griffe/_internal/agents/nodes/values.py b/packages/griffelib/src/griffelib/_internal/agents/nodes/values.py similarity index 96% rename from src/griffe/_internal/agents/nodes/values.py rename to packages/griffelib/src/griffelib/_internal/agents/nodes/values.py index 63941f823..89465b97d 100644 --- a/src/griffe/_internal/agents/nodes/values.py +++ b/packages/griffelib/src/griffelib/_internal/agents/nodes/values.py @@ -6,7 +6,7 @@ from ast import unparse from typing import TYPE_CHECKING -from griffe._internal.logger import logger +from griffelib._internal.logger import logger if TYPE_CHECKING: from pathlib import Path diff --git a/src/griffe/_internal/agents/visitor.py b/packages/griffelib/src/griffelib/_internal/agents/visitor.py similarity index 96% rename from src/griffe/_internal/agents/visitor.py rename to packages/griffelib/src/griffelib/_internal/agents/visitor.py index 7cad06dde..f1a9e18ff 100644 --- a/src/griffe/_internal/agents/visitor.py +++ b/packages/griffelib/src/griffelib/_internal/agents/visitor.py @@ -8,20 +8,20 @@ from contextlib import suppress from typing import TYPE_CHECKING, Final -from griffe._internal.agents.nodes.assignments import get_instance_names, get_names -from griffe._internal.agents.nodes.ast import ( +from griffelib._internal.agents.nodes.assignments import get_instance_names, get_names +from griffelib._internal.agents.nodes.ast import ( ast_children, ast_kind, ast_next, ) -from griffe._internal.agents.nodes.docstrings import get_docstring -from griffe._internal.agents.nodes.exports import safe_get__all__ -from griffe._internal.agents.nodes.imports import relative_to_absolute -from griffe._internal.agents.nodes.parameters import get_parameters -from griffe._internal.collections import LinesCollection, ModulesCollection -from griffe._internal.enumerations import Kind, TypeParameterKind -from griffe._internal.exceptions import AliasResolutionError, CyclicAliasError, LastNodeError -from griffe._internal.expressions import ( +from griffelib._internal.agents.nodes.docstrings import get_docstring +from griffelib._internal.agents.nodes.exports import safe_get__all__ +from griffelib._internal.agents.nodes.imports import relative_to_absolute +from griffelib._internal.agents.nodes.parameters import get_parameters +from griffelib._internal.collections import LinesCollection, ModulesCollection +from griffelib._internal.enumerations import Kind, TypeParameterKind +from griffelib._internal.exceptions import AliasResolutionError, CyclicAliasError, LastNodeError +from griffelib._internal.expressions import ( Expr, ExprName, safe_get_annotation, @@ -30,8 +30,8 @@ safe_get_condition, safe_get_expression, ) -from griffe._internal.extensions.base import Extensions, load_extensions -from griffe._internal.models import ( +from griffelib._internal.extensions.base import Extensions, load_extensions +from griffelib._internal.models import ( Alias, Attribute, Class, @@ -49,8 +49,8 @@ if TYPE_CHECKING: from pathlib import Path - from griffe._internal.docstrings.parsers import DocstringOptions, DocstringStyle - from griffe._internal.enumerations import Parser + from griffelib._internal.docstrings.parsers import DocstringOptions, DocstringStyle + from griffelib._internal.enumerations import Parser builtin_decorators = { @@ -92,13 +92,13 @@ def visit( """Parse and visit a module file. We provide this function for static analysis. It uses a [`NodeVisitor`][ast.NodeVisitor]-like class, - the [`Visitor`][griffe.Visitor], to compile and parse code (using [`compile`][]) + the [`Visitor`][griffelib.Visitor], to compile and parse code (using [`compile`][]) then visit the resulting AST (Abstract Syntax Tree). Important: This function is generally not used directly. - In most cases, users can rely on the [`GriffeLoader`][griffe.GriffeLoader] - and its accompanying [`load`][griffe.load] shortcut and their respective options + In most cases, users can rely on the [`GriffeLoader`][griffelib.GriffeLoader] + and its accompanying [`load`][griffelib.load] shortcut and their respective options to load modules using static analysis. Parameters: diff --git a/src/griffe/_internal/c3linear.py b/packages/griffelib/src/griffelib/_internal/c3linear.py similarity index 100% rename from src/griffe/_internal/c3linear.py rename to packages/griffelib/src/griffelib/_internal/c3linear.py diff --git a/src/griffe/_internal/collections.py b/packages/griffelib/src/griffelib/_internal/collections.py similarity index 94% rename from src/griffe/_internal/collections.py rename to packages/griffelib/src/griffelib/_internal/collections.py index 787f57a73..9927855a2 100644 --- a/src/griffe/_internal/collections.py +++ b/packages/griffelib/src/griffelib/_internal/collections.py @@ -5,13 +5,13 @@ from typing import TYPE_CHECKING, Any -from griffe._internal.mixins import DelMembersMixin, GetMembersMixin, SetMembersMixin +from griffelib._internal.mixins import DelMembersMixin, GetMembersMixin, SetMembersMixin if TYPE_CHECKING: from collections.abc import ItemsView, KeysView, ValuesView from pathlib import Path - from griffe._internal.models import Module + from griffelib._internal.models import Module class LinesCollection: diff --git a/src/griffe/_internal/debug.py b/packages/griffelib/src/griffelib/_internal/debug.py similarity index 93% rename from src/griffe/_internal/debug.py rename to packages/griffelib/src/griffelib/_internal/debug.py index 8f3ca86d3..7f8ea2698 100644 --- a/src/griffe/_internal/debug.py +++ b/packages/griffelib/src/griffelib/_internal/debug.py @@ -1,7 +1,7 @@ # This module is here to help users report bugs. # It provides a function to print environment information, -# which is called from the public `griffe.debug` module -# (when called with `python -m griffe.debug`) +# which is called from the public `griffelib.debug` module +# (when called with `python -m griffelib.debug`) # or thanks to the `--debug-info` CLI flag. from __future__ import annotations @@ -62,7 +62,7 @@ def _interpreter_name_version() -> tuple[str, str]: return "", "0.0.0" -def _get_version(dist: str = "griffe") -> str: +def _get_version(dist: str = "griffelib") -> str: """Get version of the given distribution. Parameters: @@ -84,7 +84,7 @@ def _get_debug_info() -> _Environment: Environment information. """ py_name, py_version = _interpreter_name_version() - packages = ["griffe"] + packages = ["griffelib"] variables = ["PYTHONPATH", *[var for var in os.environ if var.startswith("GRIFFE")]] return _Environment( interpreter_name=py_name, diff --git a/src/griffe/_internal/diff.py b/packages/griffelib/src/griffelib/_internal/diff.py similarity index 97% rename from src/griffe/_internal/diff.py rename to packages/griffelib/src/griffelib/_internal/diff.py index 59e98f08f..46f4645d1 100644 --- a/src/griffe/_internal/diff.py +++ b/packages/griffelib/src/griffelib/_internal/diff.py @@ -12,15 +12,15 @@ from pathlib import Path from typing import TYPE_CHECKING, Any -from griffe._internal.enumerations import BreakageKind, ExplanationStyle, ParameterKind -from griffe._internal.exceptions import AliasResolutionError -from griffe._internal.git import _WORKTREE_PREFIX -from griffe._internal.logger import logger +from griffelib._internal.enumerations import BreakageKind, ExplanationStyle, ParameterKind +from griffelib._internal.exceptions import AliasResolutionError +from griffelib._internal.git import _WORKTREE_PREFIX +from griffelib._internal.logger import logger if TYPE_CHECKING: from collections.abc import Iterable, Iterator - from griffe._internal.models import Alias, Attribute, Class, Function, Object + from griffelib._internal.models import Alias, Attribute, Class, Function, Object _POSITIONAL = frozenset((ParameterKind.positional_only, ParameterKind.positional_or_keyword)) _KEYWORD = frozenset((ParameterKind.keyword_only, ParameterKind.positional_or_keyword)) @@ -150,7 +150,7 @@ def _relative_package_filepath(self) -> Path: def _location(self) -> Path: # Absolute file path probably means temporary worktree. # We use our worktree prefix to remove some components - # of the path on the left (`/tmp/griffe-worktree-*/griffe_*/repo`). + # of the path on the left (`/tmp/griffelib-worktree-*/griffe_*/repo`). if self._relative_filepath.is_absolute(): parts = self._relative_filepath.parts for index, part in enumerate(parts): @@ -674,10 +674,10 @@ def find_breaking_changes( Breaking changes. Examples: - >>> import sys, griffe - >>> new = griffe.load("pkg") - >>> old = griffe.load_git("pkg", "1.2.3") - >>> for breakage in griffe.find_breaking_changes(old, new) + >>> import sys, griffelib + >>> new = griffelib.load("pkg") + >>> old = griffelib.load_git("pkg", "1.2.3") + >>> for breakage in griffelib.find_breaking_changes(old, new) ... print(breakage.explain(style=style), file=sys.stderr) """ yield from _member_incompatibilities(old_obj, new_obj) diff --git a/src/griffe/_internal/docstrings/__init__.py b/packages/griffelib/src/griffelib/_internal/docstrings/__init__.py similarity index 100% rename from src/griffe/_internal/docstrings/__init__.py rename to packages/griffelib/src/griffelib/_internal/docstrings/__init__.py diff --git a/src/griffe/_internal/docstrings/auto.py b/packages/griffelib/src/griffelib/_internal/docstrings/auto.py similarity index 90% rename from src/griffe/_internal/docstrings/auto.py rename to packages/griffelib/src/griffelib/_internal/docstrings/auto.py index ea582f91d..e7643f29c 100644 --- a/src/griffe/_internal/docstrings/auto.py +++ b/packages/griffelib/src/griffelib/_internal/docstrings/auto.py @@ -5,15 +5,15 @@ import re from typing import TYPE_CHECKING, Literal, TypedDict -from griffe._internal.enumerations import Parser +from griffelib._internal.enumerations import Parser if TYPE_CHECKING: - from griffe._internal.docstrings.google import GoogleOptions - from griffe._internal.docstrings.models import DocstringSection - from griffe._internal.docstrings.numpy import NumpyOptions - from griffe._internal.docstrings.parsers import DocstringStyle - from griffe._internal.docstrings.sphinx import SphinxOptions - from griffe._internal.models import Docstring + from griffelib._internal.docstrings.google import GoogleOptions + from griffelib._internal.docstrings.models import DocstringSection + from griffelib._internal.docstrings.numpy import NumpyOptions + from griffelib._internal.docstrings.parsers import DocstringStyle + from griffelib._internal.docstrings.sphinx import SphinxOptions + from griffelib._internal.models import Docstring # This is not our preferred order, but the safest order for proper detection @@ -143,7 +143,7 @@ def infer_docstring_style( Returns: The inferred parser, and optionally parsed sections (when method is 'max_sections'). """ - from griffe._internal.docstrings.parsers import parsers # noqa: PLC0415 + from griffelib._internal.docstrings.parsers import parsers # noqa: PLC0415 per_style_options = per_style_options or {} @@ -195,7 +195,7 @@ def parse_auto( ) -> list[DocstringSection]: """Parse a docstring by automatically detecting the style it uses. - See [`infer_docstring_style`][griffe.infer_docstring_style] for more information + See [`infer_docstring_style`][griffelib.infer_docstring_style] for more information on the available parameters. Parameters: @@ -208,7 +208,7 @@ def parse_auto( Returns: A list of docstring sections. """ - from griffe._internal.docstrings.parsers import parse # noqa: PLC0415 + from griffelib._internal.docstrings.parsers import parse # noqa: PLC0415 per_style_options = per_style_options or {} diff --git a/src/griffe/_internal/docstrings/google.py b/packages/griffelib/src/griffelib/_internal/docstrings/google.py similarity index 99% rename from src/griffe/_internal/docstrings/google.py rename to packages/griffelib/src/griffelib/_internal/docstrings/google.py index 42dd73b54..5924c892c 100644 --- a/src/griffe/_internal/docstrings/google.py +++ b/packages/griffelib/src/griffelib/_internal/docstrings/google.py @@ -6,7 +6,7 @@ from contextlib import suppress from typing import TYPE_CHECKING, TypedDict -from griffe._internal.docstrings.models import ( +from griffelib._internal.docstrings.models import ( DocstringAttribute, DocstringClass, DocstringFunction, @@ -37,15 +37,15 @@ DocstringWarn, DocstringYield, ) -from griffe._internal.docstrings.utils import docstring_warning, parse_docstring_annotation -from griffe._internal.enumerations import DocstringSectionKind, LogLevel +from griffelib._internal.docstrings.utils import docstring_warning, parse_docstring_annotation +from griffelib._internal.enumerations import DocstringSectionKind, LogLevel if TYPE_CHECKING: from re import Pattern from typing import Any, Literal - from griffe._internal.expressions import Expr - from griffe._internal.models import Docstring + from griffelib._internal.expressions import Expr + from griffelib._internal.models import Docstring _section_kind = { diff --git a/src/griffe/_internal/docstrings/models.py b/packages/griffelib/src/griffelib/_internal/docstrings/models.py similarity index 98% rename from src/griffe/_internal/docstrings/models.py rename to packages/griffelib/src/griffelib/_internal/docstrings/models.py index 545ea78d1..ce444eb80 100644 --- a/src/griffe/_internal/docstrings/models.py +++ b/packages/griffelib/src/griffelib/_internal/docstrings/models.py @@ -4,14 +4,14 @@ from typing import TYPE_CHECKING -from griffe._internal.enumerations import DocstringSectionKind -from griffe._internal.expressions import ExprTuple +from griffelib._internal.enumerations import DocstringSectionKind +from griffelib._internal.expressions import ExprTuple if TYPE_CHECKING: from collections.abc import Sequence from typing import Any, Literal - from griffe._internal.expressions import Expr + from griffelib._internal.expressions import Expr # Elements ----------------------------------------------- diff --git a/src/griffe/_internal/docstrings/numpy.py b/packages/griffelib/src/griffelib/_internal/docstrings/numpy.py similarity index 98% rename from src/griffe/_internal/docstrings/numpy.py rename to packages/griffelib/src/griffelib/_internal/docstrings/numpy.py index 080b7f63e..33550e502 100644 --- a/src/griffe/_internal/docstrings/numpy.py +++ b/packages/griffelib/src/griffelib/_internal/docstrings/numpy.py @@ -24,7 +24,7 @@ from textwrap import dedent from typing import TYPE_CHECKING, TypedDict -from griffe._internal.docstrings.models import ( +from griffelib._internal.docstrings.models import ( DocstringAttribute, DocstringClass, DocstringFunction, @@ -56,16 +56,16 @@ DocstringWarn, DocstringYield, ) -from griffe._internal.docstrings.utils import docstring_warning, parse_docstring_annotation -from griffe._internal.enumerations import DocstringSectionKind, LogLevel -from griffe._internal.expressions import ExprName +from griffelib._internal.docstrings.utils import docstring_warning, parse_docstring_annotation +from griffelib._internal.enumerations import DocstringSectionKind, LogLevel +from griffelib._internal.expressions import ExprName if TYPE_CHECKING: from re import Pattern from typing import Any, Literal - from griffe._internal.expressions import Expr - from griffe._internal.models import Docstring + from griffelib._internal.expressions import Expr + from griffelib._internal.models import Docstring _section_kind = { diff --git a/src/griffe/_internal/docstrings/parsers.py b/packages/griffelib/src/griffelib/_internal/docstrings/parsers.py similarity index 72% rename from src/griffe/_internal/docstrings/parsers.py rename to packages/griffelib/src/griffelib/_internal/docstrings/parsers.py index bb91f600a..f24ff1f7d 100644 --- a/src/griffe/_internal/docstrings/parsers.py +++ b/packages/griffelib/src/griffelib/_internal/docstrings/parsers.py @@ -5,15 +5,15 @@ from typing import TYPE_CHECKING, Any, Callable, Literal, Union -from griffe._internal.docstrings.auto import AutoOptions, parse_auto -from griffe._internal.docstrings.google import GoogleOptions, parse_google -from griffe._internal.docstrings.models import DocstringSection, DocstringSectionText -from griffe._internal.docstrings.numpy import NumpyOptions, parse_numpy -from griffe._internal.docstrings.sphinx import SphinxOptions, parse_sphinx -from griffe._internal.enumerations import Parser +from griffelib._internal.docstrings.auto import AutoOptions, parse_auto +from griffelib._internal.docstrings.google import GoogleOptions, parse_google +from griffelib._internal.docstrings.models import DocstringSection, DocstringSectionText +from griffelib._internal.docstrings.numpy import NumpyOptions, parse_numpy +from griffelib._internal.docstrings.sphinx import SphinxOptions, parse_sphinx +from griffelib._internal.enumerations import Parser if TYPE_CHECKING: - from griffe._internal.models import Docstring + from griffelib._internal.models import Docstring DocstringStyle = Literal["google", "numpy", "sphinx", "auto"] diff --git a/src/griffe/_internal/docstrings/sphinx.py b/packages/griffelib/src/griffelib/_internal/docstrings/sphinx.py similarity index 98% rename from src/griffe/_internal/docstrings/sphinx.py rename to packages/griffelib/src/griffelib/_internal/docstrings/sphinx.py index 743aa42f2..f11fa5e7e 100644 --- a/src/griffe/_internal/docstrings/sphinx.py +++ b/packages/griffelib/src/griffelib/_internal/docstrings/sphinx.py @@ -11,7 +11,7 @@ from inspect import cleandoc from typing import TYPE_CHECKING, Any, Callable, TypedDict -from griffe._internal.docstrings.models import ( +from griffelib._internal.docstrings.models import ( DocstringAttribute, DocstringParameter, DocstringRaise, @@ -23,11 +23,11 @@ DocstringSectionReturns, DocstringSectionText, ) -from griffe._internal.docstrings.utils import docstring_warning, parse_docstring_annotation +from griffelib._internal.docstrings.utils import docstring_warning, parse_docstring_annotation if TYPE_CHECKING: - from griffe._internal.expressions import Expr - from griffe._internal.models import Docstring + from griffelib._internal.expressions import Expr + from griffelib._internal.models import Docstring # TODO: Examples: from the documentation, we're not sure there is a standard format for examples diff --git a/src/griffe/_internal/docstrings/utils.py b/packages/griffelib/src/griffelib/_internal/docstrings/utils.py similarity index 88% rename from src/griffe/_internal/docstrings/utils.py rename to packages/griffelib/src/griffelib/_internal/docstrings/utils.py index 4c67069b0..5d2423cf7 100644 --- a/src/griffe/_internal/docstrings/utils.py +++ b/packages/griffelib/src/griffelib/_internal/docstrings/utils.py @@ -6,14 +6,14 @@ from contextlib import suppress from typing import TYPE_CHECKING -from griffe._internal.enumerations import LogLevel -from griffe._internal.exceptions import BuiltinModuleError -from griffe._internal.expressions import safe_get_annotation -from griffe._internal.logger import logger +from griffelib._internal.enumerations import LogLevel +from griffelib._internal.exceptions import BuiltinModuleError +from griffelib._internal.expressions import safe_get_annotation +from griffelib._internal.logger import logger if TYPE_CHECKING: - from griffe._internal.expressions import Expr - from griffe._internal.models import Docstring + from griffelib._internal.expressions import Expr + from griffelib._internal.models import Docstring def docstring_warning( diff --git a/src/griffe/_internal/encoders.py b/packages/griffelib/src/griffelib/_internal/encoders.py similarity index 96% rename from src/griffe/_internal/encoders.py rename to packages/griffelib/src/griffelib/_internal/encoders.py index 3f148dff4..fca73bd8e 100644 --- a/src/griffe/_internal/encoders.py +++ b/packages/griffelib/src/griffelib/_internal/encoders.py @@ -7,10 +7,10 @@ from pathlib import Path, PosixPath, WindowsPath from typing import Any, Callable -from griffe._internal import expressions -from griffe._internal.enumerations import Kind, ParameterKind, TypeParameterKind -from griffe._internal.git import GitInfo -from griffe._internal.models import ( +from griffelib._internal import expressions +from griffelib._internal.enumerations import Kind, ParameterKind, TypeParameterKind +from griffelib._internal.git import GitInfo +from griffelib._internal.models import ( Alias, Attribute, Class, @@ -41,11 +41,11 @@ class JSONEncoder(json.JSONEncoder): the [`json.dump`][] or [`json.dumps`][] methods. Examples: - >>> from griffe import JSONEncoder + >>> from griffelib import JSONEncoder >>> JSONEncoder(full=True).encode(..., **kwargs) >>> import json - >>> from griffe import JSONEncoder + >>> from griffelib import JSONEncoder >>> json.dumps(..., cls=JSONEncoder, full=True, **kwargs) """ @@ -61,7 +61,7 @@ def __init__( *args: See [`json.JSONEncoder`][]. full: Whether to dump full data or base data. If you plan to reload the data in Python memory - using the [`json_decoder`][griffe.json_decoder], + using the [`json_decoder`][griffelib.json_decoder], you don't need the full data as it can be inferred again using the base data. If you want to feed a non-Python tool instead, dump the full data. @@ -342,7 +342,7 @@ def json_decoder( Examples: >>> import json - >>> from griffe import json_decoder + >>> from griffelib import json_decoder >>> json.loads(..., object_hook=json_decoder) Parameters: diff --git a/src/griffe/_internal/enumerations.py b/packages/griffelib/src/griffelib/_internal/enumerations.py similarity index 100% rename from src/griffe/_internal/enumerations.py rename to packages/griffelib/src/griffelib/_internal/enumerations.py diff --git a/src/griffe/_internal/exceptions.py b/packages/griffelib/src/griffelib/_internal/exceptions.py similarity index 98% rename from src/griffe/_internal/exceptions.py rename to packages/griffelib/src/griffelib/_internal/exceptions.py index 4d104aa8e..3b864f7ad 100644 --- a/src/griffe/_internal/exceptions.py +++ b/packages/griffelib/src/griffelib/_internal/exceptions.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from griffe._internal.models import Alias + from griffelib._internal.models import Alias class GriffeError(Exception): diff --git a/src/griffe/_internal/expressions.py b/packages/griffelib/src/griffelib/_internal/expressions.py similarity index 99% rename from src/griffe/_internal/expressions.py rename to packages/griffelib/src/griffelib/_internal/expressions.py index 702bc56aa..512f2f830 100644 --- a/src/griffe/_internal/expressions.py +++ b/packages/griffelib/src/griffelib/_internal/expressions.py @@ -13,16 +13,16 @@ from functools import partial from typing import TYPE_CHECKING, Any, Protocol -from griffe._internal.agents.nodes.parameters import get_parameters -from griffe._internal.enumerations import LogLevel, ParameterKind -from griffe._internal.exceptions import NameResolutionError -from griffe._internal.logger import logger +from griffelib._internal.agents.nodes.parameters import get_parameters +from griffelib._internal.enumerations import LogLevel, ParameterKind +from griffelib._internal.exceptions import NameResolutionError +from griffelib._internal.logger import logger if TYPE_CHECKING: from collections.abc import Iterable, Iterator, Sequence from pathlib import Path - from griffe._internal.models import Class, Function, Module + from griffelib._internal.models import Class, Function, Module class _OperatorPrecedence(IntEnum): @@ -180,7 +180,7 @@ def iterate(self, *, flat: bool = True) -> Iterator[str | Expr]: # noqa: ARG002 without them getting rendered as strings. On the contrary, when flat is true, the whole tree is flattened as a sequence - of strings and instances of [Names][griffe.ExprName]. + of strings and instances of [Names][griffelib.ExprName]. Yields: Strings and names when flat, strings and expressions otherwise. @@ -227,7 +227,7 @@ def canonical_path(self) -> str: @property def canonical_name(self) -> str: """Name of the expressed name/attribute/parameter.""" - # We must handle things like `griffe.Visitor` and `griffe.Visitor(code)`. + # We must handle things like `griffelib.Visitor` and `griffelib.Visitor(code)`. return self.canonical_path.rsplit(".", 1)[-1].split("(", 1)[-1].removesuffix(")") @property diff --git a/src/griffe/_internal/extensions/__init__.py b/packages/griffelib/src/griffelib/_internal/extensions/__init__.py similarity index 100% rename from src/griffe/_internal/extensions/__init__.py rename to packages/griffelib/src/griffelib/_internal/extensions/__init__.py diff --git a/src/griffe/_internal/extensions/base.py b/packages/griffelib/src/griffelib/_internal/extensions/base.py similarity index 96% rename from src/griffe/_internal/extensions/base.py rename to packages/griffelib/src/griffelib/_internal/extensions/base.py index 8013bf806..c51893ee8 100644 --- a/src/griffe/_internal/extensions/base.py +++ b/packages/griffelib/src/griffelib/_internal/extensions/base.py @@ -10,19 +10,19 @@ from pathlib import Path from typing import TYPE_CHECKING, Any, Union -from griffe._internal.agents.nodes.ast import ast_children, ast_kind -from griffe._internal.exceptions import ExtensionNotLoadedError -from griffe._internal.importer import dynamic_import +from griffelib._internal.agents.nodes.ast import ast_children, ast_kind +from griffelib._internal.exceptions import ExtensionNotLoadedError +from griffelib._internal.importer import dynamic_import if TYPE_CHECKING: import ast from types import ModuleType - from griffe._internal.agents.inspector import Inspector - from griffe._internal.agents.nodes.runtime import ObjectNode - from griffe._internal.agents.visitor import Visitor - from griffe._internal.loader import GriffeLoader - from griffe._internal.models import Alias, Attribute, Class, Function, Module, Object, TypeAlias + from griffelib._internal.agents.inspector import Inspector + from griffelib._internal.agents.nodes.runtime import ObjectNode + from griffelib._internal.agents.visitor import Visitor + from griffelib._internal.loader import GriffeLoader + from griffelib._internal.models import Alias, Attribute, Class, Function, Module, Object, TypeAlias class Extension: @@ -543,7 +543,7 @@ def _load_extension( # If the import path corresponds to a built-in extension, expand it. if import_path in builtin_extensions: - import_path = f"griffe._internal.extensions.{import_path}" + import_path = f"griffelib._internal.extensions.{import_path}" # If the import path is a path to an existing file, load it. elif os.path.exists(import_path): # noqa: PTH110 try: @@ -603,7 +603,7 @@ def load_extensions(*exts: LoadableExtensionType) -> Extensions: # TODO: Deprecate and remove at some point? # Always add our built-in dataclasses extension. - from griffe._internal.extensions.dataclasses import DataclassesExtension # noqa: PLC0415 + from griffelib._internal.extensions.dataclasses import DataclassesExtension # noqa: PLC0415 for ext in extensions._extensions: if type(ext) is DataclassesExtension: diff --git a/src/griffe/_internal/extensions/dataclasses.py b/packages/griffelib/src/griffelib/_internal/extensions/dataclasses.py similarity index 96% rename from src/griffe/_internal/extensions/dataclasses.py rename to packages/griffelib/src/griffelib/_internal/extensions/dataclasses.py index 5e6fa7b01..100b858ad 100644 --- a/src/griffe/_internal/extensions/dataclasses.py +++ b/packages/griffelib/src/griffelib/_internal/extensions/dataclasses.py @@ -10,16 +10,16 @@ from functools import cache from typing import Any, cast -from griffe._internal.enumerations import ParameterKind -from griffe._internal.expressions import ( +from griffelib._internal.enumerations import ParameterKind +from griffelib._internal.expressions import ( Expr, ExprAttribute, ExprCall, ExprDict, ) -from griffe._internal.extensions.base import Extension -from griffe._internal.logger import logger -from griffe._internal.models import Attribute, Class, Decorator, Function, Module, Parameter, Parameters +from griffelib._internal.extensions.base import Extension +from griffelib._internal.logger import logger +from griffelib._internal.models import Attribute, Class, Decorator, Function, Module, Parameter, Parameters def _dataclass_decorator(decorators: list[Decorator]) -> Expr | None: diff --git a/src/griffe/_internal/extensions/unpack_typeddict.py b/packages/griffelib/src/griffelib/_internal/extensions/unpack_typeddict.py similarity index 96% rename from src/griffe/_internal/extensions/unpack_typeddict.py rename to packages/griffelib/src/griffelib/_internal/extensions/unpack_typeddict.py index 162cbbf69..d228c9d3c 100644 --- a/src/griffe/_internal/extensions/unpack_typeddict.py +++ b/packages/griffelib/src/griffelib/_internal/extensions/unpack_typeddict.py @@ -7,14 +7,14 @@ from itertools import chain from typing import TYPE_CHECKING, Any, TypedDict -from griffe._internal.docstrings.models import ( +from griffelib._internal.docstrings.models import ( DocstringParameter, DocstringSectionParameters, ) -from griffe._internal.enumerations import DocstringSectionKind, ParameterKind -from griffe._internal.expressions import Expr, ExprSubscript -from griffe._internal.extensions.base import Extension -from griffe._internal.models import Class, Docstring, Function, Parameter, Parameters +from griffelib._internal.enumerations import DocstringSectionKind, ParameterKind +from griffelib._internal.expressions import Expr, ExprSubscript +from griffelib._internal.extensions.base import Extension +from griffelib._internal.models import Class, Docstring, Function, Parameter, Parameters if TYPE_CHECKING: from collections.abc import Iterable, Iterator diff --git a/src/griffe/_internal/finder.py b/packages/griffelib/src/griffelib/_internal/finder.py similarity index 94% rename from src/griffe/_internal/finder.py rename to packages/griffelib/src/griffelib/_internal/finder.py index 23bc3be29..b2e38ef66 100644 --- a/src/griffe/_internal/finder.py +++ b/packages/griffelib/src/griffelib/_internal/finder.py @@ -5,12 +5,12 @@ # # ```pycon # >>> from importlib.util import _find_spec -# >>> _find_spec("griffe.agents", _find_spec("griffe", None).submodule_search_locations) +# >>> _find_spec("griffelib.agents", _find_spec("griffelib", None).submodule_search_locations) # ModuleSpec( -# name='griffe.agents', +# name='griffelib.agents', # loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fa5f34e8110>, -# origin='/media/data/dev/griffe/src/griffe/agents/__init__.py', -# submodule_search_locations=['/media/data/dev/griffe/src/griffe/agents'], +# origin='/media/data/dev/griffelib/packages/griffelib/src/griffelib/agents/__init__.py', +# submodule_search_locations=['/media/data/dev/griffelib/packages/griffelib/src/griffelib/agents'], # ) # ``` @@ -27,14 +27,14 @@ from pathlib import Path from typing import TYPE_CHECKING, ClassVar -from griffe._internal.exceptions import UnhandledEditableModuleError -from griffe._internal.logger import logger +from griffelib._internal.exceptions import UnhandledEditableModuleError +from griffelib._internal.logger import logger if TYPE_CHECKING: from collections.abc import Iterator, Sequence from re import Pattern - from griffe._internal.models import Module + from griffelib._internal.models import Module _editable_editables_patterns = [re.compile(pat) for pat in (r"^__editables_\w+\.py$", r"^_editable_impl_\w+\.py$")] @@ -89,9 +89,9 @@ class ModuleFinder: """The Griffe finder, allowing to find modules on the file system. The module finder is generally not used directly. - Each [`GriffeLoader`][griffe.GriffeLoader] instance creates its own module finder instance. + Each [`GriffeLoader`][griffelib.GriffeLoader] instance creates its own module finder instance. The finder can be configured when instantiating the loader - thanks to the [loader][griffe.GriffeLoader]'s `search_paths` parameter. + thanks to the [loader][griffelib.GriffeLoader]'s `search_paths` parameter. """ accepted_py_module_extensions: ClassVar[list[str]] = [".py", ".pyc", ".pyo", ".pyd", ".pyi", ".so"] @@ -470,9 +470,9 @@ def _handle_pth_file(path: Path) -> list[_SP]: def _handle_editable_module(path: Path) -> list[_SP]: if _match_pattern(path.name, (*_editable_editables_patterns, *_editable_scikit_build_core_patterns)): # Support for how 'editables' write these files: - # example line: `F.map_module('griffe', '/media/data/dev/griffe/src/griffe/__init__.py')`. + # example line: `F.map_module('griffelib', '/media/data/dev/griffelib/packages/griffelib/src/griffelib/__init__.py')`. # And how 'scikit-build-core' writes these files: - # example line: `install({'griffe': '/media/data/dev/griffe/src/griffe/__init__.py'}, {'cmake_example': ...}, None, False, True)`. + # example line: `install({'griffelib': '/media/data/dev/griffelib/packages/griffelib/src/griffelib/__init__.py'}, {'cmake_example': ...}, None, False, True)`. try: editable_lines = path.read_text(encoding="utf-8-sig").strip().splitlines(keepends=False) except FileNotFoundError as error: @@ -483,7 +483,7 @@ def _handle_editable_module(path: Path) -> list[_SP]: return [_SP(new_path)] if _match_pattern(path.name, _editable_setuptools_patterns): # Support for how 'setuptools' writes these files: - # example line: `MAPPING = {'griffe': '/media/data/dev/griffe/src/griffe', 'briffe': '/media/data/dev/griffe/src/briffe'}`. + # example line: `MAPPING = {'griffelib': '/media/data/dev/griffelib/packages/griffelib/src/griffelib', 'briffe': '/media/data/dev/griffelib/src/briffe'}`. # with annotation: `MAPPING: dict[str, str] = {...}`. parsed_module = ast.parse(path.read_text(encoding="utf8")) for node in parsed_module.body: @@ -497,7 +497,7 @@ def _handle_editable_module(path: Path) -> list[_SP]: return [_SP(Path(cst.value).parent) for cst in node.value.values if isinstance(cst, ast.Constant)] # type: ignore[arg-type] if _match_pattern(path.name, _editable_meson_python_patterns): # Support for how 'meson-python' writes these files: - # example line: `install({'package', 'module1'}, '/media/data/dev/griffe/build/cp311', ["path"], False)`. + # example line: `install({'package', 'module1'}, '/media/data/dev/griffelib/build/cp311', ["path"], False)`. # Compiled modules then found in the cp311 folder, under src/package. parsed_module = ast.parse(path.read_text(encoding="utf8")) for node in parsed_module.body: diff --git a/src/griffe/_internal/git.py b/packages/griffelib/src/griffelib/_internal/git.py similarity index 97% rename from src/griffe/_internal/git.py rename to packages/griffelib/src/griffelib/_internal/git.py index 47642c009..2ee41d424 100644 --- a/src/griffe/_internal/git.py +++ b/packages/griffelib/src/griffelib/_internal/git.py @@ -1,4 +1,4 @@ -# This module contains Git utilities, used by our [`load_git`][griffe.load_git] function, +# This module contains Git utilities, used by our [`load_git`][griffelib.load_git] function, # which in turn is used to load the API for different snapshots of a Git repository # and find breaking changes between them. @@ -16,15 +16,15 @@ from typing import TYPE_CHECKING, Literal from urllib.parse import urlsplit, urlunsplit -from griffe._internal.exceptions import BuiltinModuleError, GitError +from griffelib._internal.exceptions import BuiltinModuleError, GitError if TYPE_CHECKING: from collections.abc import Iterator - from griffe._internal.models import Module + from griffelib._internal.models import Module -_WORKTREE_PREFIX = "griffe-worktree-" +_WORKTREE_PREFIX = "griffelib-worktree-" def _normalize(value: str) -> str: @@ -120,7 +120,7 @@ def _tmp_worktree(repo: str | Path = ".", ref: str = "HEAD") -> Iterator[Path]: normref = _normalize(ref) # Branch names can contain slashes. with TemporaryDirectory(prefix=f"{_WORKTREE_PREFIX}{repo_name}-{normref}-") as tmp_dir: location = os.path.join(tmp_dir, normref) # noqa: PTH118 - tmp_branch = f"griffe-{normref}" # Temporary branch name must not already exist. + tmp_branch = f"griffelib-{normref}" # Temporary branch name must not already exist. try: _git("-C", str(repo), "worktree", "add", "-b", tmp_branch, location, ref) except GitError as error: diff --git a/src/griffe/_internal/importer.py b/packages/griffelib/src/griffelib/_internal/importer.py similarity index 98% rename from src/griffe/_internal/importer.py rename to packages/griffelib/src/griffelib/_internal/importer.py index b75b44ee2..4144357c3 100644 --- a/src/griffe/_internal/importer.py +++ b/packages/griffelib/src/griffelib/_internal/importer.py @@ -1,5 +1,5 @@ # This module contains utilities to dynamically import objects. -# These utilities are used by our [`Inspector`][griffe.Inspector] to dynamically import objects +# These utilities are used by our [`Inspector`][griffelib.Inspector] to dynamically import objects # specified as Python paths, like `package.module.Class.method`. from __future__ import annotations diff --git a/src/griffe/_internal/loader.py b/packages/griffelib/src/griffelib/_internal/loader.py similarity index 95% rename from src/griffe/_internal/loader.py rename to packages/griffelib/src/griffelib/_internal/loader.py index b2a2d45b5..ba9c6eddb 100644 --- a/src/griffe/_internal/loader.py +++ b/packages/griffelib/src/griffelib/_internal/loader.py @@ -14,31 +14,31 @@ from pathlib import Path from typing import TYPE_CHECKING, ClassVar, cast -from griffe._internal.agents.inspector import inspect -from griffe._internal.agents.visitor import visit -from griffe._internal.collections import LinesCollection, ModulesCollection -from griffe._internal.enumerations import Kind -from griffe._internal.exceptions import ( +from griffelib._internal.agents.inspector import inspect +from griffelib._internal.agents.visitor import visit +from griffelib._internal.collections import LinesCollection, ModulesCollection +from griffelib._internal.enumerations import Kind +from griffelib._internal.exceptions import ( AliasResolutionError, CyclicAliasError, LoadingError, UnimportableModuleError, ) -from griffe._internal.expressions import ExprName -from griffe._internal.extensions.base import Extensions, load_extensions -from griffe._internal.finder import ModuleFinder, NamespacePackage, Package -from griffe._internal.git import GitInfo, _tmp_worktree -from griffe._internal.importer import dynamic_import -from griffe._internal.logger import logger -from griffe._internal.merger import merge_stubs -from griffe._internal.models import Alias, Module, Object -from griffe._internal.stats import Stats +from griffelib._internal.expressions import ExprName +from griffelib._internal.extensions.base import Extensions, load_extensions +from griffelib._internal.finder import ModuleFinder, NamespacePackage, Package +from griffelib._internal.git import GitInfo, _tmp_worktree +from griffelib._internal.importer import dynamic_import +from griffelib._internal.logger import logger +from griffelib._internal.merger import merge_stubs +from griffelib._internal.models import Alias, Module, Object +from griffelib._internal.stats import Stats if TYPE_CHECKING: from collections.abc import Sequence - from griffe._internal.docstrings.parsers import DocstringOptions, DocstringStyle - from griffe._internal.enumerations import Parser + from griffelib._internal.docstrings.parsers import DocstringOptions, DocstringStyle + from griffelib._internal.enumerations import Parser class GriffeLoader: @@ -119,8 +119,8 @@ def load( with regular methods and properties (`parent`, `members`, etc.). Examples: - >>> loader.load("griffe.Module") - Alias("Module", "griffe._internal.models.Module") + >>> loader.load("griffelib.Module") + Alias("Module", "griffelib._internal.models.Module") Parameters: objspec: The Python path of an object, or file path to a module. @@ -293,7 +293,7 @@ def resolve_aliases( def expand_exports(self, module: Module, seen: set | None = None) -> None: """Expand exports: try to recursively expand all module exports (`__all__` values). - See also: [`Module.exports`][griffe.Module.exports]. + See also: [`Module.exports`][griffelib.Module.exports]. Parameters: module: The module to recurse on. @@ -340,7 +340,7 @@ def expand_wildcards( ) -> None: """Expand wildcards: try to recursively expand all found wildcards. - See also: [`Alias.wildcard`][griffe.Alias.wildcard]. + See also: [`Alias.wildcard`][griffelib.Alias.wildcard]. Parameters: obj: The object and its members to recurse on. @@ -645,7 +645,7 @@ def _load_submodule(self, module: Module, subparts: tuple[str, ...], subpath: Pa logger.debug( "Submodule '%s' is shadowing the member at the same path. " "We recommend renaming the member or the submodule (for example prefixing it with `_`), " - "see https://mkdocstrings.github.io/griffe/best_practices/#avoid-member-submodule-name-shadowing.", + "see https://mkdocstrings.github.io/griffelib/best_practices/#avoid-member-submodule-name-shadowing.", submodule.path, ) parent_module.set_member(submodule_name, submodule) @@ -769,37 +769,37 @@ def load( In Griffe's context, loading means: - searching for a package, and finding it on the file system or as a builtin module - (see the [`ModuleFinder`][griffe.ModuleFinder] class for more information) + (see the [`ModuleFinder`][griffelib.ModuleFinder] class for more information) - extracting information from each of its (sub)modules, by either parsing - the source code (see the [`visit`][griffe.visit] function) - or inspecting the module at runtime (see the [`inspect`][griffe.inspect] function) + the source code (see the [`visit`][griffelib.visit] function) + or inspecting the module at runtime (see the [`inspect`][griffelib.inspect] function) The extracted information is stored in a collection of modules, which can be queried later. Each collected module is a tree of objects, representing the structure of the module. - See the [`Module`][griffe.Module], [`Class`][griffe.Class], - [`Function`][griffe.Function], [`Attribute`][griffe.Attribute], and - [`TypeAlias`][griffe.TypeAlias] classes for more information. + See the [`Module`][griffelib.Module], [`Class`][griffelib.Class], + [`Function`][griffelib.Function], [`Attribute`][griffelib.Attribute], and + [`TypeAlias`][griffelib.TypeAlias] classes for more information. - The main class used to load modules is [`GriffeLoader`][griffe.GriffeLoader]. - Convenience functions like this one and [`load_git`][griffe.load_git] are also available. + The main class used to load modules is [`GriffeLoader`][griffelib.GriffeLoader]. + Convenience functions like this one and [`load_git`][griffelib.load_git] are also available. Example: ```python - import griffe + import griffelib - module = griffe.load(...) + module = griffelib.load(...) ``` This is a shortcut for: ```python - from griffe import GriffeLoader + from griffelib import GriffeLoader loader = GriffeLoader(...) module = loader.load(...) ``` - See the documentation for the loader: [`GriffeLoader`][griffe.GriffeLoader]. + See the documentation for the loader: [`GriffeLoader`][griffelib.GriffeLoader]. Parameters: objspec: The Python path of an object, or file path to a module. @@ -873,13 +873,13 @@ def load_git( This function will create a temporary [git worktree](https://git-scm.com/docs/git-worktree) at the requested reference - before loading `module` with [`griffe.load`][griffe.load]. + before loading `module` with [`griffelib.load`][griffelib.load]. This function requires that the `git` executable is installed. Examples: ```python - from griffe import load_git + from griffelib import load_git old_api = load_git("my_module", ref="v0.1.0", repo="path/to/repo") ``` @@ -983,7 +983,7 @@ def load_pypi( import platformdirs # noqa: PLC0415 - pypi_cache_dir = Path(platformdirs.user_cache_dir("griffe")) + pypi_cache_dir = Path(platformdirs.user_cache_dir("griffelib")) install_dir = pypi_cache_dir / f"{distribution}{version_spec}" if install_dir.exists(): logger.debug("Using cached %s%s", distribution, version_spec) diff --git a/src/griffe/_internal/logger.py b/packages/griffelib/src/griffelib/_internal/logger.py similarity index 97% rename from src/griffe/_internal/logger.py rename to packages/griffelib/src/griffelib/_internal/logger.py index 6a7290fc3..4a7d45773 100644 --- a/src/griffe/_internal/logger.py +++ b/packages/griffelib/src/griffelib/_internal/logger.py @@ -4,7 +4,8 @@ # For example, mkdocstrings-python patches the logger to relocate it as a child # of `mkdocs.plugins` so that it fits in the MkDocs logging configuration. # -# We use a single, global logger because our public API is exposed in a single module, `griffe`. +# We use a single, global logger because our public API is exposed in a single module. +# The logger name is "griffe" for backward compatibility. # Extensions however should use their own logger, which is why we provide the `get_logger` function. from __future__ import annotations diff --git a/src/griffe/_internal/merger.py b/packages/griffelib/src/griffelib/_internal/merger.py similarity index 95% rename from src/griffe/_internal/merger.py rename to packages/griffelib/src/griffelib/_internal/merger.py index 798ebf08e..d95eaa1d2 100644 --- a/src/griffe/_internal/merger.py +++ b/packages/griffelib/src/griffelib/_internal/merger.py @@ -5,11 +5,11 @@ from contextlib import suppress from typing import TYPE_CHECKING -from griffe._internal.exceptions import AliasResolutionError, CyclicAliasError -from griffe._internal.logger import logger +from griffelib._internal.exceptions import AliasResolutionError, CyclicAliasError +from griffelib._internal.logger import logger if TYPE_CHECKING: - from griffe._internal.models import Attribute, Class, Function, Module, Object, TypeAlias + from griffelib._internal.models import Attribute, Class, Function, Module, Object, TypeAlias def _merge_module_stubs(module: Module, stubs: Module) -> None: diff --git a/src/griffe/_internal/mixins.py b/packages/griffelib/src/griffelib/_internal/mixins.py similarity index 97% rename from src/griffe/_internal/mixins.py rename to packages/griffelib/src/griffelib/_internal/mixins.py index 05d69414c..b7455674c 100644 --- a/src/griffe/_internal/mixins.py +++ b/packages/griffelib/src/griffelib/_internal/mixins.py @@ -7,14 +7,14 @@ from contextlib import suppress from typing import TYPE_CHECKING, Any, TypeVar -from griffe._internal.enumerations import Kind -from griffe._internal.exceptions import AliasResolutionError, BuiltinModuleError, CyclicAliasError -from griffe._internal.merger import merge_stubs +from griffelib._internal.enumerations import Kind +from griffelib._internal.exceptions import AliasResolutionError, BuiltinModuleError, CyclicAliasError +from griffelib._internal.merger import merge_stubs if TYPE_CHECKING: from collections.abc import Sequence - from griffe._internal.models import Alias, Attribute, Class, Function, Module, Object, TypeAlias + from griffelib._internal.models import Alias, Attribute, Class, Function, Module, Object, TypeAlias _ObjType = TypeVar("_ObjType") @@ -222,7 +222,7 @@ def as_json(self, *, full: bool = False, **kwargs: Any) -> str: Returns: A JSON string. """ - from griffe._internal.encoders import JSONEncoder # Avoid circular import. # noqa: PLC0415 + from griffelib._internal.encoders import JSONEncoder # Avoid circular import. # noqa: PLC0415 return json.dumps(self, cls=JSONEncoder, full=full, **kwargs) @@ -241,7 +241,7 @@ def from_json(cls: type[_ObjType], json_string: str, **kwargs: Any) -> _ObjType: TypeError: When the json_string does not represent and object of the class from which this classmethod has been called. """ - from griffe._internal.encoders import json_decoder # Avoid circular import. # noqa: PLC0415 + from griffelib._internal.encoders import json_decoder # Avoid circular import. # noqa: PLC0415 kwargs.setdefault("object_hook", json_decoder) obj = json.loads(json_string, **kwargs) diff --git a/src/griffe/_internal/models.py b/packages/griffelib/src/griffelib/_internal/models.py similarity index 86% rename from src/griffe/_internal/models.py rename to packages/griffelib/src/griffelib/_internal/models.py index 9cc60e17f..50a38814f 100644 --- a/src/griffe/_internal/models.py +++ b/packages/griffelib/src/griffelib/_internal/models.py @@ -11,21 +11,26 @@ from textwrap import dedent from typing import TYPE_CHECKING, Any, Callable, Literal, Union, cast -from griffe._internal.c3linear import c3linear_merge -from griffe._internal.docstrings.parsers import DocstringOptions, DocstringStyle, parse -from griffe._internal.enumerations import Kind, ParameterKind, Parser, TypeParameterKind -from griffe._internal.exceptions import AliasResolutionError, BuiltinModuleError, CyclicAliasError, NameResolutionError -from griffe._internal.expressions import ExprCall, ExprName, ExprTuple -from griffe._internal.logger import logger -from griffe._internal.mixins import ObjectAliasMixin +from griffelib._internal.c3linear import c3linear_merge +from griffelib._internal.docstrings.parsers import DocstringOptions, DocstringStyle, parse +from griffelib._internal.enumerations import Kind, ParameterKind, Parser, TypeParameterKind +from griffelib._internal.exceptions import ( + AliasResolutionError, + BuiltinModuleError, + CyclicAliasError, + NameResolutionError, +) +from griffelib._internal.expressions import ExprCall, ExprName, ExprTuple +from griffelib._internal.logger import logger +from griffelib._internal.mixins import ObjectAliasMixin if TYPE_CHECKING: from collections.abc import Sequence - from griffe._internal.collections import LinesCollection, ModulesCollection - from griffe._internal.docstrings.models import DocstringSection - from griffe._internal.expressions import Expr - from griffe._internal.git import GitInfo + from griffelib._internal.collections import LinesCollection, ModulesCollection + from griffelib._internal.docstrings.models import DocstringSection + from griffelib._internal.expressions import Expr + from griffelib._internal.git import GitInfo from functools import cached_property @@ -97,18 +102,18 @@ def __init__( self.value: str = inspect.cleandoc(value.rstrip()) """The original value of the docstring, cleaned by `inspect.cleandoc`. - See also: [`source`][griffe.Docstring.source]. + See also: [`source`][griffelib.Docstring.source]. """ self.lineno: int | None = lineno """The starting line number of the docstring. - See also: [`endlineno`][griffe.Docstring.endlineno].""" + See also: [`endlineno`][griffelib.Docstring.endlineno].""" self.endlineno: int | None = endlineno """The ending line number of the docstring. - See also: [`lineno`][griffe.Docstring.lineno].""" + See also: [`lineno`][griffelib.Docstring.lineno].""" self.parent: Object | None = parent """The object this docstring is attached to.""" @@ -116,22 +121,22 @@ def __init__( self.parser: DocstringStyle | Parser | None = parser """The selected docstring parser. - See also: [`parser_options`][griffe.Docstring.parser_options], - [`parse`][griffe.Docstring.parse]. + See also: [`parser_options`][griffelib.Docstring.parser_options], + [`parse`][griffelib.Docstring.parse]. """ self.parser_options: DocstringOptions = parser_options or {} """The configured parsing options. - See also: [`parser`][griffe.Docstring.parser], - [`parse`][griffe.Docstring.parse]. + See also: [`parser`][griffelib.Docstring.parser], + [`parse`][griffelib.Docstring.parse]. """ @property def lines(self) -> list[str]: """The lines of the docstring. - See also: [`source`][griffe.Docstring.source]. + See also: [`source`][griffelib.Docstring.source]. """ return self.value.split("\n") @@ -147,7 +152,7 @@ def source(self) -> str: ValueError: If the original docstring cannot be retrieved (no parent, no line numbers, or attached to namespace package). - See also: [`value`][griffe.Docstring.value]. + See also: [`value`][griffelib.Docstring.value]. """ if self.parent is None: raise ValueError("Cannot get original docstring without parent object") @@ -169,8 +174,8 @@ def parse( ) -> list[DocstringSection]: """Parse the docstring into structured data. - See also: [`parser`][griffe.Docstring.parser], - [`parser_options`][griffe.Docstring.parser_options]. + See also: [`parser`][griffelib.Docstring.parser], + [`parser_options`][griffelib.Docstring.parser_options]. Parameters: parser: The docstring parser to use. @@ -210,7 +215,7 @@ def as_dict( class Parameter: # noqa: PLW1641 """This class represent a function parameter. - See also: [`Parameters`][griffe.Parameters]. + See also: [`Parameters`][griffelib.Parameters]. """ def __init__( @@ -302,7 +307,7 @@ class Parameters: True ``` - See also: [`Parameter`][griffe.Parameter]. + See also: [`Parameter`][griffelib.Parameter]. """ def __init__(self, *parameters: Parameter) -> None: @@ -613,20 +618,20 @@ def __init__( self.lineno: int | None = lineno """The starting line number of the object. - See also: [`endlineno`][griffe.Object.endlineno]. + See also: [`endlineno`][griffelib.Object.endlineno]. """ self.endlineno: int | None = endlineno """The ending line number of the object. - See also: [`lineno`][griffe.Object.lineno]. + See also: [`lineno`][griffelib.Object.lineno]. """ self.docstring: Docstring | None = docstring """The object docstring. - See also: [`has_docstring`][griffe.Object.has_docstring], - [`has_docstrings`][griffe.Object.has_docstrings]. + See also: [`has_docstring`][griffelib.Object.has_docstring], + [`has_docstrings`][griffelib.Object.has_docstrings]. """ # TODO: Maybe move these into `Class` and `Function`. @@ -641,16 +646,16 @@ def __init__( self.members: dict[str, Object | Alias] = {} """The object members (modules, classes, functions, attributes, type aliases). - See also: [`inherited_members`][griffe.Object.inherited_members], - [`get_member`][griffe.Object.get_member], - [`set_member`][griffe.Object.set_member], - [`filter_members`][griffe.Object.filter_members]. + See also: [`inherited_members`][griffelib.Object.inherited_members], + [`get_member`][griffelib.Object.get_member], + [`set_member`][griffelib.Object.set_member], + [`filter_members`][griffelib.Object.filter_members]. """ self.labels: set[str] = set() """The object labels (`property`, `dataclass`, etc.). - See also: [`has_labels`][griffe.Object.has_labels].""" + See also: [`has_labels`][griffelib.Object.has_labels].""" self.imports: dict[str, str] = {} """The other objects imported by this object. @@ -673,7 +678,7 @@ def __init__( Exports get expanded by the loader before it expands wildcards and resolves aliases. - See also: [`GriffeLoader.expand_exports`][griffe.GriffeLoader.expand_exports]. + See also: [`GriffeLoader.expand_exports`][griffelib.GriffeLoader.expand_exports]. """ self.aliases: dict[str, Alias] = {} @@ -757,8 +762,8 @@ def source_link(self, value: str | None) -> None: def has_docstring(self) -> bool: """Whether this object has a docstring (empty or not). - See also: [`docstring`][griffe.Object.docstring], - [`has_docstrings`][griffe.Object.has_docstrings]. + See also: [`docstring`][griffelib.Object.docstring], + [`has_docstrings`][griffelib.Object.has_docstrings]. """ return bool(self.docstring) @@ -777,8 +782,8 @@ def has_docstrings(self) -> bool: Inherited members are not considered. Imported members are not considered, unless they are also public. - See also: [`docstring`][griffe.Object.docstring], - [`has_docstring`][griffe.Object.has_docstring]. + See also: [`docstring`][griffelib.Object.docstring], + [`has_docstring`][griffelib.Object.has_docstring]. """ if self.has_docstring: return True @@ -793,12 +798,12 @@ def has_docstrings(self) -> bool: def is_kind(self, kind: str | Kind | set[str | Kind]) -> bool: """Tell if this object is of the given kind. - See also: [`is_module`][griffe.Object.is_module], - [`is_class`][griffe.Object.is_class], - [`is_function`][griffe.Object.is_function], - [`is_attribute`][griffe.Object.is_attribute], - [`is_type_alias`][griffe.Object.is_type_alias], - [`is_alias`][griffe.Object.is_alias]. + See also: [`is_module`][griffelib.Object.is_module], + [`is_class`][griffelib.Object.is_class], + [`is_function`][griffelib.Object.is_function], + [`is_attribute`][griffelib.Object.is_attribute], + [`is_type_alias`][griffelib.Object.is_type_alias], + [`is_alias`][griffelib.Object.is_alias]. Parameters: kind: An instance or set of kinds (strings or enumerations). @@ -824,7 +829,7 @@ def inherited_members(self) -> dict[str, Alias]: This method is part of the consumer API: do not use when producing Griffe trees! - See also: [`members`][griffe.Object.members]. + See also: [`members`][griffelib.Object.members]. """ if not isinstance(self, Class): return {} @@ -844,13 +849,13 @@ def inherited_members(self) -> dict[str, Alias]: def is_module(self) -> bool: """Whether this object is a module. - See also: [`is_init_module`][griffe.Object.is_init_module]. - [`is_class`][griffe.Object.is_class], - [`is_function`][griffe.Object.is_function], - [`is_attribute`][griffe.Object.is_attribute], - [`is_type_alias`][griffe.Object.is_type_alias], - [`is_alias`][griffe.Object.is_alias], - [`is_kind`][griffe.Object.is_kind]. + See also: [`is_init_module`][griffelib.Object.is_init_module]. + [`is_class`][griffelib.Object.is_class], + [`is_function`][griffelib.Object.is_function], + [`is_attribute`][griffelib.Object.is_attribute], + [`is_type_alias`][griffelib.Object.is_type_alias], + [`is_alias`][griffelib.Object.is_alias], + [`is_kind`][griffelib.Object.is_kind]. """ return self.kind is Kind.MODULE @@ -858,12 +863,12 @@ def is_module(self) -> bool: def is_class(self) -> bool: """Whether this object is a class. - See also: [`is_module`][griffe.Object.is_module]. - [`is_function`][griffe.Object.is_function], - [`is_attribute`][griffe.Object.is_attribute], - [`is_type_alias`][griffe.Object.is_type_alias], - [`is_alias`][griffe.Object.is_alias], - [`is_kind`][griffe.Object.is_kind]. + See also: [`is_module`][griffelib.Object.is_module]. + [`is_function`][griffelib.Object.is_function], + [`is_attribute`][griffelib.Object.is_attribute], + [`is_type_alias`][griffelib.Object.is_type_alias], + [`is_alias`][griffelib.Object.is_alias], + [`is_kind`][griffelib.Object.is_kind]. """ return self.kind is Kind.CLASS @@ -871,12 +876,12 @@ def is_class(self) -> bool: def is_function(self) -> bool: """Whether this object is a function. - See also: [`is_module`][griffe.Object.is_module]. - [`is_class`][griffe.Object.is_class], - [`is_attribute`][griffe.Object.is_attribute], - [`is_type_alias`][griffe.Object.is_type_alias], - [`is_alias`][griffe.Object.is_alias], - [`is_kind`][griffe.Object.is_kind]. + See also: [`is_module`][griffelib.Object.is_module]. + [`is_class`][griffelib.Object.is_class], + [`is_attribute`][griffelib.Object.is_attribute], + [`is_type_alias`][griffelib.Object.is_type_alias], + [`is_alias`][griffelib.Object.is_alias], + [`is_kind`][griffelib.Object.is_kind]. """ return self.kind is Kind.FUNCTION @@ -884,12 +889,12 @@ def is_function(self) -> bool: def is_attribute(self) -> bool: """Whether this object is an attribute. - See also: [`is_module`][griffe.Object.is_module]. - [`is_class`][griffe.Object.is_class], - [`is_function`][griffe.Object.is_function], - [`is_type_alias`][griffe.Object.is_type_alias], - [`is_alias`][griffe.Object.is_alias], - [`is_kind`][griffe.Object.is_kind]. + See also: [`is_module`][griffelib.Object.is_module]. + [`is_class`][griffelib.Object.is_class], + [`is_function`][griffelib.Object.is_function], + [`is_type_alias`][griffelib.Object.is_type_alias], + [`is_alias`][griffelib.Object.is_alias], + [`is_kind`][griffelib.Object.is_kind]. """ return self.kind is Kind.ATTRIBUTE @@ -897,12 +902,12 @@ def is_attribute(self) -> bool: def is_type_alias(self) -> bool: """Whether this object is a type alias. - See also: [`is_module`][griffe.Object.is_module]. - [`is_class`][griffe.Object.is_class], - [`is_function`][griffe.Object.is_function], - [`is_attribute`][griffe.Object.is_attribute], - [`is_alias`][griffe.Object.is_alias], - [`is_kind`][griffe.Object.is_kind]. + See also: [`is_module`][griffelib.Object.is_module]. + [`is_class`][griffelib.Object.is_class], + [`is_function`][griffelib.Object.is_function], + [`is_attribute`][griffelib.Object.is_attribute], + [`is_alias`][griffelib.Object.is_alias], + [`is_kind`][griffelib.Object.is_kind]. """ return self.kind is Kind.TYPE_ALIAS @@ -915,7 +920,7 @@ def is_init_method(self) -> bool: def is_init_module(self) -> bool: """Whether this object is an `__init__.py` module. - See also: [`is_module`][griffe.Object.is_module]. + See also: [`is_module`][griffelib.Object.is_module]. """ return False @@ -923,7 +928,7 @@ def is_init_module(self) -> bool: def is_package(self) -> bool: """Whether this object is a package (top module). - See also: [`is_subpackage`][griffe.Object.is_subpackage]. + See also: [`is_subpackage`][griffelib.Object.is_subpackage]. """ return False @@ -931,7 +936,7 @@ def is_package(self) -> bool: def is_subpackage(self) -> bool: """Whether this object is a subpackage. - See also: [`is_package`][griffe.Object.is_package]. + See also: [`is_package`][griffelib.Object.is_package]. """ return False @@ -939,7 +944,7 @@ def is_subpackage(self) -> bool: def is_namespace_package(self) -> bool: """Whether this object is a namespace package (top folder, no `__init__.py`). - See also: [`is_namespace_subpackage`][griffe.Object.is_namespace_subpackage]. + See also: [`is_namespace_subpackage`][griffelib.Object.is_namespace_subpackage]. """ return False @@ -947,14 +952,14 @@ def is_namespace_package(self) -> bool: def is_namespace_subpackage(self) -> bool: """Whether this object is a namespace subpackage. - See also: [`is_namespace_package`][griffe.Object.is_namespace_package]. + See also: [`is_namespace_package`][griffelib.Object.is_namespace_package]. """ return False def has_labels(self, *labels: str) -> bool: """Tell if this object has all the given labels. - See also: [`labels`][griffe.Object.labels]. + See also: [`labels`][griffelib.Object.labels]. Parameters: *labels: Labels that must be present. @@ -967,7 +972,7 @@ def has_labels(self, *labels: str) -> bool: def filter_members(self, *predicates: Callable[[Object | Alias], bool]) -> dict[str, Object | Alias]: """Filter and return members based on predicates. - See also: [`members`][griffe.Object.members]. + See also: [`members`][griffelib.Object.members]. Parameters: *predicates: A list of predicates, i.e. callables accepting a member as argument and returning a boolean. @@ -986,11 +991,11 @@ def filter_members(self, *predicates: Callable[[Object | Alias], bool]) -> dict[ def module(self) -> Module: """The parent module of this object. - See also: [`package`][griffe.Object.package]. + See also: [`package`][griffelib.Object.package]. Examples: - >>> import griffe - >>> markdown = griffe.load("markdown") + >>> import griffelib + >>> markdown = griffelib.load("markdown") >>> markdown["core.Markdown.references"].module Module(PosixPath('~/project/.venv/lib/python3.11/site-packages/markdown/core.py')) >>> # The `module` of a module is itself. @@ -1010,11 +1015,11 @@ def module(self) -> Module: def package(self) -> Module: """The absolute top module (the package) of this object. - See also: [`module`][griffe.Object.module]. + See also: [`module`][griffelib.Object.module]. Examples: - >>> import griffe - >>> markdown = griffe.load("markdown") + >>> import griffelib + >>> markdown = griffelib.load("markdown") >>> markdown["core.Markdown.references"].package Module(PosixPath('~/project/.venv/lib/python3.11/site-packages/markdown/__init__.py')) """ @@ -1027,12 +1032,12 @@ def package(self) -> Module: def filepath(self) -> Path | list[Path]: """The file path (or directory list for namespace packages) where this object was defined. - See also: [`relative_filepath`][griffe.Object.relative_filepath], - [`relative_package_filepath`][griffe.Object.relative_package_filepath]. + See also: [`relative_filepath`][griffelib.Object.relative_filepath], + [`relative_package_filepath`][griffelib.Object.relative_package_filepath]. Examples: - >>> import griffe - >>> markdown = griffe.load("markdown") + >>> import griffelib + >>> markdown = griffelib.load("markdown") >>> markdown.filepath PosixPath('~/project/.venv/lib/python3.11/site-packages/markdown/__init__.py') """ @@ -1042,8 +1047,8 @@ def filepath(self) -> Path | list[Path]: def relative_package_filepath(self) -> Path: """The file path where this object was defined, relative to the top module path. - See also: [`filepath`][griffe.Object.filepath], - [`relative_filepath`][griffe.Object.relative_filepath]. + See also: [`filepath`][griffelib.Object.filepath], + [`relative_filepath`][griffelib.Object.relative_filepath]. Raises: ValueError: When the relative path could not be computed. @@ -1088,8 +1093,8 @@ def relative_filepath(self) -> Path: If this object's file path is not relative to the current working directory, return its absolute path. - See also: [`filepath`][griffe.Object.filepath], - [`relative_package_filepath`][griffe.Object.relative_package_filepath]. + See also: [`filepath`][griffelib.Object.filepath], + [`relative_package_filepath`][griffelib.Object.relative_package_filepath]. Raises: ValueError: When the relative path could not be computed. @@ -1111,11 +1116,11 @@ def path(self) -> str: On regular objects (not aliases), the path is the canonical path. - See also: [`canonical_path`][griffe.Object.canonical_path]. + See also: [`canonical_path`][griffelib.Object.canonical_path]. Examples: - >>> import griffe - >>> markdown = griffe.load("markdown") + >>> import griffelib + >>> markdown = griffelib.load("markdown") >>> markdown["core.Markdown.references"].path 'markdown.core.Markdown.references' """ @@ -1127,7 +1132,7 @@ def canonical_path(self) -> str: The canonical path is the path where the object was defined (not imported). - See also: [`path`][griffe.Object.path]. + See also: [`path`][griffelib.Object.path]. """ if self.parent is None: return self.name @@ -1150,8 +1155,8 @@ def modules_collection(self) -> ModulesCollection: def lines_collection(self) -> LinesCollection: """The lines collection attached to this object or its parents. - See also: [`lines`][griffe.Object.lines], - [`source`][griffe.Object.source]. + See also: [`lines`][griffelib.Object.lines], + [`source`][griffelib.Object.source]. Raises: ValueError: When no modules collection can be found in the object or its parents. @@ -1166,8 +1171,8 @@ def lines_collection(self) -> LinesCollection: def lines(self) -> list[str]: """The lines containing the source of this object. - See also: [`lines_collection`][griffe.Object.lines_collection], - [`source`][griffe.Object.source]. + See also: [`lines_collection`][griffelib.Object.lines_collection], + [`source`][griffelib.Object.source]. """ try: filepath = self.filepath @@ -1189,8 +1194,8 @@ def lines(self) -> list[str]: def source(self) -> str: """The source code of this object. - See also: [`lines`][griffe.Object.lines], - [`lines_collection`][griffe.Object.lines_collection]. + See also: [`lines`][griffelib.Object.lines], + [`lines_collection`][griffelib.Object.lines_collection]. """ return dedent("\n".join(self.lines)) @@ -1240,7 +1245,7 @@ def resolve(self, name: str) -> str: def as_dict(self, *, full: bool = False, **kwargs: Any) -> dict[str, Any]: """Return this object's data as a dictionary. - See also: [`as_json`][griffe.Object.as_json]. + See also: [`as_json`][griffelib.Object.as_json]. Parameters: full: Whether to return full info, or just base info. @@ -1336,7 +1341,7 @@ class Alias(ObjectAliasMixin): - the path is the alias path, not the canonical one - the name can be different from the target's - if the target can be resolved, the kind is the target's kind - - if the target cannot be resolved, the kind becomes [Kind.ALIAS][griffe.Kind] + - if the target cannot be resolved, the kind becomes [Kind.ALIAS][griffelib.Kind] """ is_alias: bool = True @@ -1344,7 +1349,7 @@ class Alias(ObjectAliasMixin): is_collection: bool = False """Always false for aliases. - See also: [`ModulesCollection`][griffe.ModulesCollection]. + See also: [`ModulesCollection`][griffelib.ModulesCollection]. """ def __init__( @@ -1439,7 +1444,7 @@ def __len__(self) -> int: def kind(self) -> Kind: """The target's kind, or `Kind.ALIAS` if the target cannot be resolved. - See also: [`is_kind`][griffe.Alias.is_kind]. + See also: [`is_kind`][griffelib.Alias.is_kind]. """ # custom behavior to avoid raising exceptions try: @@ -1451,8 +1456,8 @@ def kind(self) -> Kind: def has_docstring(self) -> bool: """Whether this alias' target has a non-empty docstring. - See also: [`has_docstrings`][griffe.Alias.has_docstrings], - [`docstring`][griffe.Alias.docstring]. + See also: [`has_docstrings`][griffelib.Alias.has_docstrings], + [`docstring`][griffelib.Alias.docstring]. """ try: return self.final_target.has_docstring @@ -1463,8 +1468,8 @@ def has_docstring(self) -> bool: def has_docstrings(self) -> bool: """Whether this alias' target or any of its members has a non-empty docstring. - See also: [`has_docstring`][griffe.Alias.has_docstring], - [`docstring`][griffe.Alias.docstring]. + See also: [`has_docstring`][griffelib.Alias.has_docstring], + [`docstring`][griffelib.Alias.docstring]. """ try: return self.final_target.has_docstrings @@ -1485,7 +1490,7 @@ def parent(self, value: Module | Class | Alias) -> None: def path(self) -> str: """The dotted path / import path of this object. - See also: [`canonical_path`][griffe.Alias.canonical_path]. + See also: [`canonical_path`][griffelib.Alias.canonical_path]. """ return f"{self.parent.path}.{self.name}" # type: ignore[union-attr] @@ -1499,10 +1504,10 @@ def modules_collection(self) -> ModulesCollection: def members(self) -> dict[str, Object | Alias]: """The target's members (modules, classes, functions, attributes, type aliases). - See also: [`inherited_members`][griffe.Alias.inherited_members], - [`get_member`][griffe.Alias.get_member], - [`set_member`][griffe.Alias.set_member], - [`filter_members`][griffe.Alias.filter_members]. + See also: [`inherited_members`][griffelib.Alias.inherited_members], + [`get_member`][griffelib.Alias.get_member], + [`set_member`][griffelib.Alias.set_member], + [`filter_members`][griffelib.Alias.filter_members]. """ final_target = self.final_target @@ -1525,7 +1530,7 @@ def inherited_members(self) -> dict[str, Alias]: This method is part of the consumer API: do not use when producing Griffe trees! - See also: [`members`][griffe.Alias.members]. + See also: [`members`][griffelib.Alias.members]. """ final_target = self.final_target @@ -1541,7 +1546,7 @@ def inherited_members(self) -> dict[str, Alias]: def as_json(self, *, full: bool = False, **kwargs: Any) -> str: """Return this target's data as a JSON string. - See also: [`as_dict`][griffe.Alias.as_dict]. + See also: [`as_dict`][griffelib.Alias.as_dict]. Parameters: full: Whether to return full info, or just base info. @@ -1589,7 +1594,7 @@ def extra(self) -> dict: def lineno(self) -> int | None: """The starting line number of the target object. - See also: [`endlineno`][griffe.Alias.endlineno]. + See also: [`endlineno`][griffelib.Alias.endlineno]. """ return self.final_target.lineno @@ -1601,7 +1606,7 @@ def lineno(self, lineno: int | None) -> None: def endlineno(self) -> int | None: """The ending line number of the target object. - See also: [`lineno`][griffe.Alias.lineno]. + See also: [`lineno`][griffelib.Alias.lineno]. """ return self.final_target.endlineno @@ -1613,8 +1618,8 @@ def endlineno(self, endlineno: int | None) -> None: def docstring(self) -> Docstring | None: """The target docstring. - See also: [`has_docstring`][griffe.Alias.has_docstring], - [`has_docstrings`][griffe.Alias.has_docstrings]. + See also: [`has_docstring`][griffelib.Alias.has_docstring], + [`has_docstrings`][griffelib.Alias.has_docstrings]. """ return self.final_target.docstring @@ -1631,7 +1636,7 @@ def type_parameters(self) -> TypeParameters: def labels(self) -> set[str]: """The target labels (`property`, `dataclass`, etc.). - See also: [`has_labels`][griffe.Alias.has_labels]. + See also: [`has_labels`][griffelib.Alias.has_labels]. """ return self.final_target.labels @@ -1642,7 +1647,7 @@ def imports(self) -> dict[str, str]: Keys are the names within the object (`from ... import ... as AS_NAME`), while the values are the actual names of the objects (`from ... import REAL_NAME as ...`). - See also: [`is_imported`][griffe.Alias.is_imported]. + See also: [`is_imported`][griffelib.Alias.is_imported]. """ return self.final_target.imports @@ -1661,7 +1666,7 @@ def exports(self) -> list[str | ExprName] | None: Exports get expanded by the loader before it expands wildcards and resolves aliases. - See also: [`GriffeLoader.expand_exports`][griffe.GriffeLoader.expand_exports]. + See also: [`GriffeLoader.expand_exports`][griffelib.GriffeLoader.expand_exports]. """ return self.final_target.exports @@ -1673,12 +1678,12 @@ def aliases(self) -> dict[str, Alias]: def is_kind(self, kind: str | Kind | set[str | Kind]) -> bool: """Tell if this object is of the given kind. - See also: [`is_module`][griffe.Alias.is_module], - [`is_class`][griffe.Alias.is_class], - [`is_function`][griffe.Alias.is_function], - [`is_attribute`][griffe.Alias.is_attribute], - [`is_type_alias`][griffe.Alias.is_type_alias], - [`is_alias`][griffe.Alias.is_alias]. + See also: [`is_module`][griffelib.Alias.is_module], + [`is_class`][griffelib.Alias.is_class], + [`is_function`][griffelib.Alias.is_function], + [`is_attribute`][griffelib.Alias.is_attribute], + [`is_type_alias`][griffelib.Alias.is_type_alias], + [`is_alias`][griffelib.Alias.is_alias]. Parameters: kind: An instance or set of kinds (strings or enumerations). @@ -1695,13 +1700,13 @@ def is_kind(self, kind: str | Kind | set[str | Kind]) -> bool: def is_module(self) -> bool: """Whether this object is a module. - See also: [`is_init_module`][griffe.Alias.is_init_module]. - [`is_class`][griffe.Alias.is_class], - [`is_function`][griffe.Alias.is_function], - [`is_attribute`][griffe.Alias.is_attribute], - [`is_type_alias`][griffe.Alias.is_type_alias], - [`is_alias`][griffe.Alias.is_alias], - [`is_kind`][griffe.Alias.is_kind]. + See also: [`is_init_module`][griffelib.Alias.is_init_module]. + [`is_class`][griffelib.Alias.is_class], + [`is_function`][griffelib.Alias.is_function], + [`is_attribute`][griffelib.Alias.is_attribute], + [`is_type_alias`][griffelib.Alias.is_type_alias], + [`is_alias`][griffelib.Alias.is_alias], + [`is_kind`][griffelib.Alias.is_kind]. """ return self.final_target.is_module @@ -1709,12 +1714,12 @@ def is_module(self) -> bool: def is_class(self) -> bool: """Whether this object is a class. - See also: [`is_module`][griffe.Alias.is_module], - [`is_function`][griffe.Alias.is_function], - [`is_attribute`][griffe.Alias.is_attribute], - [`is_type_alias`][griffe.Alias.is_type_alias], - [`is_alias`][griffe.Alias.is_alias], - [`is_kind`][griffe.Alias.is_kind]. + See also: [`is_module`][griffelib.Alias.is_module], + [`is_function`][griffelib.Alias.is_function], + [`is_attribute`][griffelib.Alias.is_attribute], + [`is_type_alias`][griffelib.Alias.is_type_alias], + [`is_alias`][griffelib.Alias.is_alias], + [`is_kind`][griffelib.Alias.is_kind]. """ return self.final_target.is_class @@ -1722,12 +1727,12 @@ def is_class(self) -> bool: def is_function(self) -> bool: """Whether this object is a function. - See also: [`is_module`][griffe.Alias.is_module], - [`is_class`][griffe.Alias.is_class], - [`is_attribute`][griffe.Alias.is_attribute], - [`is_type_alias`][griffe.Alias.is_type_alias], - [`is_alias`][griffe.Alias.is_alias], - [`is_kind`][griffe.Alias.is_kind]. + See also: [`is_module`][griffelib.Alias.is_module], + [`is_class`][griffelib.Alias.is_class], + [`is_attribute`][griffelib.Alias.is_attribute], + [`is_type_alias`][griffelib.Alias.is_type_alias], + [`is_alias`][griffelib.Alias.is_alias], + [`is_kind`][griffelib.Alias.is_kind]. """ return self.final_target.is_function @@ -1735,12 +1740,12 @@ def is_function(self) -> bool: def is_attribute(self) -> bool: """Whether this object is an attribute. - See also: [`is_module`][griffe.Alias.is_module], - [`is_class`][griffe.Alias.is_class], - [`is_function`][griffe.Alias.is_function], - [`is_type_alias`][griffe.Alias.is_type_alias], - [`is_alias`][griffe.Alias.is_alias], - [`is_kind`][griffe.Alias.is_kind]. + See also: [`is_module`][griffelib.Alias.is_module], + [`is_class`][griffelib.Alias.is_class], + [`is_function`][griffelib.Alias.is_function], + [`is_type_alias`][griffelib.Alias.is_type_alias], + [`is_alias`][griffelib.Alias.is_alias], + [`is_kind`][griffelib.Alias.is_kind]. """ return self.final_target.is_attribute @@ -1748,19 +1753,19 @@ def is_attribute(self) -> bool: def is_type_alias(self) -> bool: """Whether this object is a type alias. - See also: [`is_module`][griffe.Alias.is_module], - [`is_class`][griffe.Alias.is_class], - [`is_function`][griffe.Alias.is_function], - [`is_attribute`][griffe.Alias.is_attribute], - [`is_alias`][griffe.Alias.is_alias], - [`is_kind`][griffe.Alias.is_kind]. + See also: [`is_module`][griffelib.Alias.is_module], + [`is_class`][griffelib.Alias.is_class], + [`is_function`][griffelib.Alias.is_function], + [`is_attribute`][griffelib.Alias.is_attribute], + [`is_alias`][griffelib.Alias.is_alias], + [`is_kind`][griffelib.Alias.is_kind]. """ return self.final_target.is_type_alias def has_labels(self, *labels: str) -> bool: """Tell if this object has all the given labels. - See also: [`labels`][griffe.Alias.labels]. + See also: [`labels`][griffelib.Alias.labels]. Parameters: *labels: Labels that must be present. @@ -1773,9 +1778,9 @@ def has_labels(self, *labels: str) -> bool: def filter_members(self, *predicates: Callable[[Object | Alias], bool]) -> dict[str, Object | Alias]: """Filter and return members based on predicates. - See also: [`members`][griffe.Alias.members], - [`get_member`][griffe.Alias.get_member], - [`set_member`][griffe.Alias.set_member]. + See also: [`members`][griffelib.Alias.members], + [`get_member`][griffelib.Alias.get_member], + [`set_member`][griffelib.Alias.set_member]. Parameters: *predicates: A list of predicates, i.e. callables accepting a member as argument and returning a boolean. @@ -1789,7 +1794,7 @@ def filter_members(self, *predicates: Callable[[Object | Alias], bool]) -> dict[ def module(self) -> Module: """The parent module of this object. - See also: [`package`][griffe.Alias.package]. + See also: [`package`][griffelib.Alias.package]. Raises: ValueError: When the object is not a module and does not have a parent. @@ -1800,7 +1805,7 @@ def module(self) -> Module: def package(self) -> Module: """The absolute top module (the package) of this object. - See also: [`module`][griffe.Alias.module]. + See also: [`module`][griffelib.Alias.module]. """ return self.final_target.package @@ -1808,8 +1813,8 @@ def package(self) -> Module: def filepath(self) -> Path | list[Path]: """The file path (or directory list for namespace packages) where this object was defined. - See also: [`relative_filepath`][griffe.Alias.relative_filepath], - [`relative_package_filepath`][griffe.Alias.relative_package_filepath]. + See also: [`relative_filepath`][griffelib.Alias.relative_filepath], + [`relative_package_filepath`][griffelib.Alias.relative_package_filepath]. """ return self.final_target.filepath @@ -1819,8 +1824,8 @@ def relative_filepath(self) -> Path: If this object's file path is not relative to the current working directory, return its absolute path. - See also: [`filepath`][griffe.Alias.filepath], - [`relative_package_filepath`][griffe.Alias.relative_package_filepath]. + See also: [`filepath`][griffelib.Alias.filepath], + [`relative_package_filepath`][griffelib.Alias.relative_package_filepath]. Raises: ValueError: When the relative path could not be computed. @@ -1831,8 +1836,8 @@ def relative_filepath(self) -> Path: def relative_package_filepath(self) -> Path: """The file path where this object was defined, relative to the top module path. - See also: [`filepath`][griffe.Alias.filepath], - [`relative_filepath`][griffe.Alias.relative_filepath]. + See also: [`filepath`][griffelib.Alias.filepath], + [`relative_filepath`][griffelib.Alias.relative_filepath]. Raises: ValueError: When the relative path could not be computed. @@ -1845,7 +1850,7 @@ def canonical_path(self) -> str: The canonical path is the path where the object was defined (not imported). - See also: [`path`][griffe.Alias.path]. + See also: [`path`][griffelib.Alias.path]. """ return self.final_target.canonical_path @@ -1853,8 +1858,8 @@ def canonical_path(self) -> str: def lines_collection(self) -> LinesCollection: """The lines collection attached to this object or its parents. - See also: [`lines`][griffe.Alias.lines], - [`source`][griffe.Alias.source]. + See also: [`lines`][griffelib.Alias.lines], + [`source`][griffelib.Alias.source]. Raises: ValueError: When no modules collection can be found in the object or its parents. @@ -1865,8 +1870,8 @@ def lines_collection(self) -> LinesCollection: def lines(self) -> list[str]: """The lines containing the source of this object. - See also: [`source`][griffe.Alias.source], - [`lines_collection`][griffe.Alias.lines_collection]. + See also: [`source`][griffelib.Alias.source], + [`lines_collection`][griffelib.Alias.lines_collection]. """ return self.final_target.lines @@ -1874,8 +1879,8 @@ def lines(self) -> list[str]: def source(self) -> str: """The source code of this object. - See also: [`lines`][griffe.Alias.lines], - [`lines_collection`][griffe.Alias.lines_collection]. + See also: [`lines`][griffelib.Alias.lines], + [`lines_collection`][griffelib.Alias.lines_collection]. """ return self.final_target.source @@ -1906,9 +1911,9 @@ def _filepath(self) -> Path | list[Path] | None: def bases(self) -> list[Expr | str]: """The class bases. - See also: [`Class`][griffe.Class], - [`resolved_bases`][griffe.Alias.resolved_bases], - [`mro`][griffe.Alias.mro]. + See also: [`Class`][griffelib.Class], + [`resolved_bases`][griffelib.Alias.resolved_bases], + [`mro`][griffelib.Alias.mro]. """ return cast("Class", self.final_target).bases @@ -1921,8 +1926,8 @@ def keywords(self) -> dict[str, Expr | str]: def decorators(self) -> list[Decorator]: """The class/function decorators. - See also: [`Function`][griffe.Function], - [`Class`][griffe.Class]. + See also: [`Function`][griffelib.Function], + [`Class`][griffelib.Class]. """ return cast("Union[Class, Function]", self.target).decorators @@ -1940,7 +1945,7 @@ def is_init_method(self) -> bool: def is_init_module(self) -> bool: """Whether this module is an `__init__.py` module. - See also: [`is_module`][griffe.Alias.is_module]. + See also: [`is_module`][griffelib.Alias.is_module]. """ return cast("Module", self.final_target).is_init_module @@ -1948,7 +1953,7 @@ def is_init_module(self) -> bool: def is_package(self) -> bool: """Whether this module is a package (top module). - See also: [`is_subpackage`][griffe.Alias.is_subpackage]. + See also: [`is_subpackage`][griffelib.Alias.is_subpackage]. """ return cast("Module", self.final_target).is_package @@ -1956,7 +1961,7 @@ def is_package(self) -> bool: def is_subpackage(self) -> bool: """Whether this module is a subpackage. - See also: [`is_package`][griffe.Alias.is_package]. + See also: [`is_package`][griffelib.Alias.is_package]. """ return cast("Module", self.final_target).is_subpackage @@ -1964,7 +1969,7 @@ def is_subpackage(self) -> bool: def is_namespace_package(self) -> bool: """Whether this module is a namespace package (top folder, no `__init__.py`). - See also: [`is_namespace_subpackage`][griffe.Alias.is_namespace_subpackage]. + See also: [`is_namespace_subpackage`][griffelib.Alias.is_namespace_subpackage]. """ return cast("Module", self.final_target).is_namespace_package @@ -1972,7 +1977,7 @@ def is_namespace_package(self) -> bool: def is_namespace_subpackage(self) -> bool: """Whether this module is a namespace subpackage. - See also: [`is_namespace_package`][griffe.Alias.is_namespace_package]. + See also: [`is_namespace_package`][griffelib.Alias.is_namespace_package]. """ return cast("Module", self.final_target).is_namespace_subpackage @@ -2068,9 +2073,9 @@ def target(self) -> Object | Alias: Upon accessing this property, if the target is not already resolved, a lookup is done using the modules collection to find the target. - See also: [`final_target`][griffe.Alias.final_target], - [`resolve_target`][griffe.Alias.resolve_target], - [`resolved`][griffe.Alias.resolved]. + See also: [`final_target`][griffelib.Alias.final_target], + [`resolve_target`][griffelib.Alias.resolve_target], + [`resolved`][griffelib.Alias.resolved]. """ if not self.resolved: self.resolve_target() @@ -2091,9 +2096,9 @@ def final_target(self) -> Object: This will iterate through the targets until a non-alias object is found. - See also: [`target`][griffe.Alias.target], - [`resolve_target`][griffe.Alias.resolve_target], - [`resolved`][griffe.Alias.resolved]. + See also: [`target`][griffelib.Alias.target], + [`resolve_target`][griffelib.Alias.resolve_target], + [`resolved`][griffelib.Alias.resolved]. """ # Here we quickly iterate on the alias chain, # remembering which path we've seen already to detect cycles. @@ -2114,9 +2119,9 @@ def final_target(self) -> Object: def resolve_target(self) -> None: """Resolve the target. - See also: [`target`][griffe.Alias.target], - [`final_target`][griffe.Alias.final_target], - [`resolved`][griffe.Alias.resolved]. + See also: [`target`][griffelib.Alias.target], + [`final_target`][griffelib.Alias.final_target], + [`resolved`][griffelib.Alias.resolved]. Raises: AliasResolutionError: When the target cannot be resolved. @@ -2173,7 +2178,7 @@ def resolved(self) -> bool: def wildcard(self) -> str | None: """The module on which the wildcard import is performed (if any). - See also: [`GriffeLoader.expand_wildcards`][griffe.GriffeLoader.expand_wildcards]. + See also: [`GriffeLoader.expand_wildcards`][griffelib.GriffeLoader.expand_wildcards]. """ if self.name.endswith("/*"): return self.target_path @@ -2182,7 +2187,7 @@ def wildcard(self) -> str | None: def as_dict(self, *, full: bool = False, **kwargs: Any) -> dict[str, Any]: # noqa: ARG002 """Return this alias' data as a dictionary. - See also: [`as_json`][griffe.Alias.as_json]. + See also: [`as_json`][griffelib.Alias.as_json]. Parameters: full: Whether to return full info, or just base info. @@ -2237,9 +2242,9 @@ def __init__(self, *args: Any, filepath: Path | list[Path] | None = None, **kwar """Initialize the module. Parameters: - *args: See [`griffe.Object`][]. + *args: See [`griffelib.Object`][]. filepath: The module file path (directory for namespace [sub]packages, none for builtin modules). - **kwargs: See [`griffe.Object`][]. + **kwargs: See [`griffelib.Object`][]. """ super().__init__(*args, **kwargs) self._filepath: Path | list[Path] | None = filepath @@ -2276,7 +2281,7 @@ def imports_future_annotations(self) -> bool: def is_init_module(self) -> bool: """Whether this module is an `__init__.py` module. - See also: [`is_module`][griffe.Module.is_module]. + See also: [`is_module`][griffelib.Module.is_module]. """ if isinstance(self.filepath, list): return False @@ -2289,7 +2294,7 @@ def is_init_module(self) -> bool: def is_package(self) -> bool: """Whether this module is a package (top module). - See also: [`is_subpackage`][griffe.Module.is_subpackage]. + See also: [`is_subpackage`][griffelib.Module.is_subpackage]. """ return not bool(self.parent) and self.is_init_module @@ -2297,7 +2302,7 @@ def is_package(self) -> bool: def is_subpackage(self) -> bool: """Whether this module is a subpackage. - See also: [`is_package`][griffe.Module.is_package]. + See also: [`is_package`][griffelib.Module.is_package]. """ return bool(self.parent) and self.is_init_module @@ -2305,7 +2310,7 @@ def is_subpackage(self) -> bool: def is_namespace_package(self) -> bool: """Whether this module is a namespace package (top folder, no `__init__.py`). - See also: [`is_namespace_subpackage`][griffe.Module.is_namespace_subpackage]. + See also: [`is_namespace_subpackage`][griffelib.Module.is_namespace_subpackage]. """ try: return self.parent is None and isinstance(self.filepath, list) @@ -2316,7 +2321,7 @@ def is_namespace_package(self) -> bool: def is_namespace_subpackage(self) -> bool: """Whether this module is a namespace subpackage. - See also: [`is_namespace_package`][griffe.Module.is_namespace_package]. + See also: [`is_namespace_package`][griffelib.Module.is_namespace_package]. """ try: return ( @@ -2333,7 +2338,7 @@ def is_namespace_subpackage(self) -> bool: def as_dict(self, **kwargs: Any) -> dict[str, Any]: """Return this module's data as a dictionary. - See also: [`as_json`][griffe.Module.as_json]. + See also: [`as_json`][griffelib.Module.as_json]. Parameters: **kwargs: Additional serialization options. @@ -2367,19 +2372,19 @@ def __init__( """Initialize the class. Parameters: - *args: See [`griffe.Object`][]. + *args: See [`griffelib.Object`][]. bases: The list of base classes, if any. decorators: The class decorators, if any. keywords: The class keywords arguments, if any. - **kwargs: See [`griffe.Object`][]. + **kwargs: See [`griffelib.Object`][]. """ super().__init__(*args, **kwargs) self.bases: list[Expr | str] = list(bases) if bases else [] """The class bases. - See also: [`resolved_bases`][griffe.Class.resolved_bases], - [`mro`][griffe.Class.mro]. + See also: [`resolved_bases`][griffelib.Class.resolved_bases], + [`mro`][griffelib.Class.mro]. """ self.decorators: list[Decorator] = decorators or [] @@ -2428,8 +2433,8 @@ def resolved_bases(self) -> list[Object]: This method is part of the consumer API: do not use when producing Griffe trees! - See also: [`bases`][griffe.Class.bases], - [`mro`][griffe.Class.mro]. + See also: [`bases`][griffelib.Class.bases], + [`mro`][griffelib.Class.mro]. """ resolved_bases = [] for base in self.bases: @@ -2458,15 +2463,15 @@ def _mro(self, seen: tuple[str, ...] = ()) -> list[Class]: def mro(self) -> list[Class]: """Return a list of classes in order corresponding to Python's MRO. - See also: [`bases`][griffe.Class.bases], - [`resolved_bases`][griffe.Class.resolved_bases]. + See also: [`bases`][griffelib.Class.bases], + [`resolved_bases`][griffelib.Class.resolved_bases]. """ return self._mro()[1:] # Remove self. def as_dict(self, **kwargs: Any) -> dict[str, Any]: """Return this class' data as a dictionary. - See also: [`as_json`][griffe.Class.as_json]. + See also: [`as_json`][griffelib.Class.as_json]. Parameters: **kwargs: Additional serialization options. @@ -2496,11 +2501,11 @@ def __init__( """Initialize the function. Parameters: - *args: See [`griffe.Object`][]. + *args: See [`griffelib.Object`][]. parameters: The function parameters. returns: The function return annotation. decorators: The function decorators, if any. - **kwargs: See [`griffe.Object`][]. + **kwargs: See [`griffelib.Object`][]. """ super().__init__(*args, **kwargs) self.parameters: Parameters = parameters or Parameters() @@ -2561,7 +2566,7 @@ def is_init_method(self) -> bool: def as_dict(self, **kwargs: Any) -> dict[str, Any]: """Return this function's data as a dictionary. - See also: [`as_json`][griffe.Function.as_json]. + See also: [`as_json`][griffelib.Function.as_json]. Parameters: **kwargs: Additional serialization options. @@ -2665,10 +2670,10 @@ def __init__( """Initialize the function. Parameters: - *args: See [`griffe.Object`][]. + *args: See [`griffelib.Object`][]. value: The attribute value, if any. annotation: The attribute annotation, if any. - **kwargs: See [`griffe.Object`][]. + **kwargs: See [`griffelib.Object`][]. """ super().__init__(*args, **kwargs) self.value: str | Expr | None = value @@ -2683,7 +2688,7 @@ def __init__( def as_dict(self, **kwargs: Any) -> dict[str, Any]: """Return this attribute's data as a dictionary. - See also: [`as_json`][griffe.Attribute.as_json]. + See also: [`as_json`][griffelib.Attribute.as_json]. Parameters: **kwargs: Additional serialization options. @@ -2713,9 +2718,9 @@ def __init__( """Initialize the function. Parameters: - *args: See [`griffe.Object`][]. + *args: See [`griffelib.Object`][]. value: The type alias value. - **kwargs: See [`griffe.Object`][]. + **kwargs: See [`griffelib.Object`][]. """ super().__init__(*args, **kwargs) self.value: str | Expr | None = value diff --git a/src/griffe/_internal/py.typed b/packages/griffelib/src/griffelib/_internal/py.typed similarity index 100% rename from src/griffe/_internal/py.typed rename to packages/griffelib/src/griffelib/_internal/py.typed diff --git a/src/griffe/_internal/stats.py b/packages/griffelib/src/griffelib/_internal/stats.py similarity index 97% rename from src/griffe/_internal/stats.py rename to packages/griffelib/src/griffelib/_internal/stats.py index 957cc5c89..59400a510 100644 --- a/src/griffe/_internal/stats.py +++ b/packages/griffelib/src/griffelib/_internal/stats.py @@ -7,11 +7,11 @@ from pathlib import Path from typing import TYPE_CHECKING -from griffe._internal.enumerations import Kind +from griffelib._internal.enumerations import Kind if TYPE_CHECKING: - from griffe._internal.loader import GriffeLoader - from griffe._internal.models import Alias, Object + from griffelib._internal.loader import GriffeLoader + from griffelib._internal.models import Alias, Object class Stats: diff --git a/src/griffe/_internal/tests.py b/packages/griffelib/src/griffelib/_internal/tests.py similarity index 96% rename from src/griffe/_internal/tests.py rename to packages/griffelib/src/griffelib/_internal/tests.py index 912447056..1383bc7aa 100644 --- a/src/griffe/_internal/tests.py +++ b/packages/griffelib/src/griffelib/_internal/tests.py @@ -13,19 +13,19 @@ from textwrap import dedent from typing import TYPE_CHECKING -from griffe._internal.agents.inspector import inspect -from griffe._internal.agents.visitor import visit -from griffe._internal.collections import LinesCollection -from griffe._internal.loader import load -from griffe._internal.models import Module, Object +from griffelib._internal.agents.inspector import inspect +from griffelib._internal.agents.visitor import visit +from griffelib._internal.collections import LinesCollection +from griffelib._internal.loader import load +from griffelib._internal.models import Module, Object if TYPE_CHECKING: from collections.abc import Iterator, Mapping, Sequence - from griffe._internal.collections import ModulesCollection - from griffe._internal.docstrings.parsers import DocstringOptions, DocstringStyle - from griffe._internal.enumerations import Parser - from griffe._internal.extensions.base import Extensions + from griffelib._internal.collections import ModulesCollection + from griffelib._internal.docstrings.parsers import DocstringOptions, DocstringStyle + from griffelib._internal.enumerations import Parser + from griffelib._internal.extensions.base import Extensions _TMPDIR_PREFIX = "griffe_" diff --git a/pyproject.toml b/pyproject.toml index f33dc1fc7..77f2bc30a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [build-system] # pdm-backend is left here as a dependency of the version discovery script currently in use. # It may be removed in the future. See mkdocstrings/griffe#430 -requires = ["hatchling", "pdm-backend"] +requires = ["hatchling", "pdm-backend", "uv-dynamic-versioning>=0.7.0"] build-backend = "hatchling.build" [project] @@ -13,7 +13,7 @@ license-files = ["LICENSE"] readme = "README.md" requires-python = ">=3.10" keywords = ["api", "signature", "breaking-changes", "static-analysis", "dynamic-analysis"] -dynamic = ["version"] +dynamic = ["version", "dependencies", "optional-dependencies"] classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", @@ -36,16 +36,6 @@ classifiers = [ "Topic :: Utilities", "Typing :: Typed", ] -dependencies = [ - "colorama>=0.4", -] - -[project.optional-dependencies] -pypi = [ - "pip>=24.0", - "platformdirs>=4.2", - "wheel>=0.42", -] [project.urls] Homepage = "https://mkdocstrings.github.io/griffe" @@ -58,13 +48,22 @@ Gitter = "https://gitter.im/mkdocstrings/griffe" Funding = "https://github.com/sponsors/pawamoy" [project.scripts] -griffe = "griffe:main" +griffe = "griffecli:main" [tool.hatch.version] source = "code" path = "scripts/get_version.py" expression = "get_version()" +[tool.hatch.metadata.hooks.uv-dynamic-versioning] +# Dependencies are dynamically versioned; {{version}} is substituted at build time. +# This ensures griffe, griffelib, and griffecli versions are always 1:1. +dependencies = ["griffelib=={{version}}", "griffecli=={{version}}"] + +[tool.hatch.metadata.hooks.uv-dynamic-versioning.optional-dependencies] +# The 'pypi' extra re-exports griffelib[pypi] for backward compatibility. +pypi = ["griffelib[pypi]=={{version}}"] + [tool.hatch.build] # Include as much as possible in the source distribution, to help redistributors. ignore-vcs = true @@ -136,3 +135,8 @@ ci = [ [tool.uv] default-groups = ["maintain", "ci", "docs"] +workspace = { members = ["packages/*"] } + +[tool.uv.sources] +griffelib = { workspace = true } +griffecli = { workspace = true } diff --git a/scripts/gen_griffe_json.py b/scripts/gen_griffe_json.py index 150eba043..a1fb98dca 100644 --- a/scripts/gen_griffe_json.py +++ b/scripts/gen_griffe_json.py @@ -5,5 +5,5 @@ python_handler = mkdocs_gen_files.config.plugins["mkdocstrings"].get_handler("python") data = python_handler.collect("griffe", options=python_handler.get_options({})) -with mkdocs_gen_files.open("griffe.json", "w") as fd: +with mkdocs_gen_files.open("griffelib.json", "w") as fd: print(data.as_json(full=True), file=fd) diff --git a/scripts/gen_structure_docs.py b/scripts/gen_structure_docs.py index a33860efe..7f84671ae 100644 --- a/scripts/gen_structure_docs.py +++ b/scripts/gen_structure_docs.py @@ -96,5 +96,5 @@ def render_entrypoint(heading_level: int = 4) -> None: root = Path(os.environ["MKDOCS_CONFIG_DIR"]) src = root / "src" public_api = src / "griffe" - print(f"{'#' * heading_level} `griffe.__main__`\n") + print(f"{'#' * heading_level} `griffelib.__main__`\n") print(_comment_block(public_api / "__main__.py")) diff --git a/src/griffe/__init__.py b/src/griffe/__init__.py index c06aad3a3..09ddc836a 100644 --- a/src/griffe/__init__.py +++ b/src/griffe/__init__.py @@ -1,13 +1,12 @@ -# This top-level module imports all public names from the package, -# and exposes them as public objects. We have tests to make sure -# no object is forgotten in this list. - """Griffe package. Signatures for entire Python programs. Extract the structure, the frame, the skeleton of your project, to generate API documentation or find breaking changes in your API. +This is a backward-compatible package that re-exports all public symbols from +both `griffelib` (the library) and `griffecli` (the CLI). + The entirety of the public API is exposed here, in the top-level `griffe` module. All messages written to standard output or error are logged using the `logging` module. @@ -18,590 +17,12 @@ Raised exceptions throughout the package are part of the public API (you can rely on them). Their actual messages are not part of the public API (they might change without notice). -The following paragraphs will help you discover the package's content. - -## CLI entrypoints - -Griffe provides a command-line interface (CLI) to interact with the package. The CLI entrypoints can be called from Python code. - -- [`griffe.main`][]: Run the main program. -- [`griffe.check`][]: Check for API breaking changes in two versions of the same package. -- [`griffe.dump`][]: Load packages data and dump it as JSON. - -## Loaders - -To load API data, Griffe provides several high-level functions. - -- [`griffe.load`][]: Load and return a Griffe object. -- [`griffe.load_git`][]: Load and return a module from a specific Git reference. -- [`griffe.load_pypi`][]: Load and return a module from a specific package version downloaded using pip. - -## Models - -The data loaded by Griffe is represented by several classes. - -- [`griffe.Module`][]: The class representing a Python module. -- [`griffe.Class`][]: The class representing a Python class. -- [`griffe.Function`][]: The class representing a Python function or method. -- [`griffe.Attribute`][]: The class representing a Python attribute. -- [`griffe.Alias`][]: This class represents an alias, or indirection, to an object declared in another module. - -Additional classes are available to represent other concepts. - -- [`griffe.Decorator`][]: This class represents a decorator. -- [`griffe.Parameters`][]: This class is a container for parameters. -- [`griffe.Parameter`][]: This class represent a function parameter. - -## Agents - -Griffe is able to analyze code both statically and dynamically, using the following "agents". -However most of the time you will only need to use the loaders above. - -- [`griffe.visit`][]: Parse and visit a module file. -- [`griffe.inspect`][]: Inspect a module. - -## Serializers - -Griffe can serizalize data to dictionary and JSON. - -- [`griffe.Object.as_json`][griffe.Object.as_json] -- [`griffe.Object.from_json`][griffe.Object.from_json] -- [`griffe.JSONEncoder`][]: JSON encoder for Griffe objects. -- [`griffe.json_decoder`][]: JSON decoder for Griffe objects. - -## API checks - -Griffe can compare two versions of the same package to find breaking changes. - -- [`griffe.find_breaking_changes`][]: Find breaking changes between two versions of the same API. -- [`griffe.Breakage`][]: Breakage classes can explain what broke from a version to another. - -## Extensions - -Griffe supports extensions. You can create your own extension by subclassing the `griffe.Extension` class. - -- [`griffe.load_extensions`][]: Load configured extensions. -- [`griffe.Extension`][]: Base class for Griffe extensions. - -## Docstrings - -Griffe can parse docstrings into structured data. - -Main class: - -- [`griffe.Docstring`][]: This class represents docstrings. - -Docstring section and element classes all start with `Docstring`. - -Docstring parsers: - -- [`griffe.parse`][]: Parse the docstring. -- [`griffe.parse_auto`][]: Parse a docstring by automatically detecting the style it uses. -- [`griffe.parse_google`][]: Parse a Google-style docstring. -- [`griffe.parse_numpy`][]: Parse a Numpydoc-style docstring. -- [`griffe.parse_sphinx`][]: Parse a Sphinx-style docstring. - -## Exceptions - -Griffe uses several exceptions to signal errors. - -- [`griffe.GriffeError`][]: The base exception for all Griffe errors. -- [`griffe.LoadingError`][]: Exception for loading errors. -- [`griffe.NameResolutionError`][]: Exception for names that cannot be resolved in a object scope. -- [`griffe.UnhandledEditableModuleError`][]: Exception for unhandled editables modules, when searching modules. -- [`griffe.UnimportableModuleError`][]: Exception for modules that cannot be imported. -- [`griffe.AliasResolutionError`][]: Exception for aliases that cannot be resolved. -- [`griffe.CyclicAliasError`][]: Exception raised when a cycle is detected in aliases. -- [`griffe.LastNodeError`][]: Exception raised when trying to access a next or previous node. -- [`griffe.RootNodeError`][]: Exception raised when trying to use siblings properties on a root node. -- [`griffe.BuiltinModuleError`][]: Exception raised when trying to access the filepath of a builtin module. -- [`griffe.ExtensionError`][]: Base class for errors raised by extensions. -- [`griffe.ExtensionNotLoadedError`][]: Exception raised when an extension could not be loaded. -- [`griffe.GitError`][]: Exception raised for errors related to Git. - -# Expressions - -Griffe stores snippets of code (attribute values, decorators, base class, type annotations) as expressions. -Expressions are basically abstract syntax trees (AST) with a few differences compared to the nodes returned by [`ast`][]. -Griffe provides a few helpers to extract expressions from regular AST nodes. - -- [`griffe.get_annotation`][]: Get a type annotation as expression. -- [`griffe.get_base_class`][]: Get a base class as expression. -- [`griffe.get_class_keyword`][]: Get a class keyword as expression. -- [`griffe.get_condition`][]: Get a condition as expression. -- [`griffe.get_expression`][]: Get an expression from an AST node. -- [`griffe.safe_get_annotation`][]: Get a type annotation as expression, safely (returns `None` on error). -- [`griffe.safe_get_base_class`][]: Get a base class as expression, safely (returns `None` on error). -- [`griffe.safe_get_class_keyword`][]: Get a class keyword as expression, safely (returns `None` on error). -- [`griffe.safe_get_condition`][]: Get a condition as expression, safely (returns `None` on error). -- [`griffe.safe_get_expression`][]: Get an expression from an AST node, safely (returns `None` on error). - -The base class for expressions. - -- [`griffe.Expr`][] - -Expression classes all start with `Expr`. - -# Loggers - -If you want to log messages from extensions, get a logger with `get_logger`. -The `logger` attribute is used by Griffe itself. You can use it to temporarily disable Griffe logging. - -- [`griffe.logger`][]: Our global logger, used throughout the library. -- [`griffe.get_logger`][]: Create and return a new logger instance. - -# Helpers - -To test your Griffe extensions, or to load API data from code in memory, Griffe provides the following helpers. - -- [`griffe.temporary_pyfile`][]: Create a Python file containing the given code in a temporary directory. -- [`griffe.temporary_pypackage`][]: Create a package containing the given modules in a temporary directory. -- [`griffe.temporary_visited_module`][]: Create and visit a temporary module with the given code. -- [`griffe.temporary_visited_package`][]: Create and visit a temporary package. -- [`griffe.temporary_inspected_module`][]: Create and inspect a temporary module with the given code. -- [`griffe.temporary_inspected_package`][]: Create and inspect a temporary package. +See the `griffelib` and `griffecli` packages for detailed API documentation. """ -from __future__ import annotations - -from griffe._internal.agents.inspector import Inspector, inspect -from griffe._internal.agents.nodes.assignments import get_instance_names, get_name, get_names -from griffe._internal.agents.nodes.ast import ( - ast_children, - ast_first_child, - ast_kind, - ast_last_child, - ast_next, - ast_next_siblings, - ast_previous, - ast_previous_siblings, - ast_siblings, -) -from griffe._internal.agents.nodes.docstrings import get_docstring -from griffe._internal.agents.nodes.exports import get__all__, safe_get__all__ -from griffe._internal.agents.nodes.imports import relative_to_absolute -from griffe._internal.agents.nodes.parameters import ParametersType, get_parameters -from griffe._internal.agents.nodes.runtime import ObjectNode -from griffe._internal.agents.nodes.values import get_value, safe_get_value -from griffe._internal.agents.visitor import Visitor, builtin_decorators, stdlib_decorators, typing_overload, visit -from griffe._internal.c3linear import c3linear_merge -from griffe._internal.cli import DEFAULT_LOG_LEVEL, check, dump, get_parser, main -from griffe._internal.collections import LinesCollection, ModulesCollection -from griffe._internal.diff import ( - AttributeChangedTypeBreakage, - AttributeChangedValueBreakage, - Breakage, - ClassRemovedBaseBreakage, - ObjectChangedKindBreakage, - ObjectRemovedBreakage, - ParameterAddedRequiredBreakage, - ParameterChangedDefaultBreakage, - ParameterChangedKindBreakage, - ParameterChangedRequiredBreakage, - ParameterMovedBreakage, - ParameterRemovedBreakage, - ReturnChangedTypeBreakage, - find_breaking_changes, -) -from griffe._internal.docstrings.auto import ( - AutoOptions, - DocstringDetectionMethod, - PerStyleOptions, - infer_docstring_style, - parse_auto, -) -from griffe._internal.docstrings.google import GoogleOptions, parse_google -from griffe._internal.docstrings.models import ( - DocstringAdmonition, - DocstringAttribute, - DocstringClass, - DocstringDeprecated, - DocstringElement, - DocstringFunction, - DocstringModule, - DocstringNamedElement, - DocstringParameter, - DocstringRaise, - DocstringReceive, - DocstringReturn, - DocstringSection, - DocstringSectionAdmonition, - DocstringSectionAttributes, - DocstringSectionClasses, - DocstringSectionDeprecated, - DocstringSectionExamples, - DocstringSectionFunctions, - DocstringSectionModules, - DocstringSectionOtherParameters, - DocstringSectionParameters, - DocstringSectionRaises, - DocstringSectionReceives, - DocstringSectionReturns, - DocstringSectionText, - DocstringSectionTypeAliases, - DocstringSectionTypeParameters, - DocstringSectionWarns, - DocstringSectionYields, - DocstringTypeAlias, - DocstringTypeParameter, - DocstringWarn, - DocstringYield, -) -from griffe._internal.docstrings.numpy import NumpyOptions, parse_numpy -from griffe._internal.docstrings.parsers import ( - DocstringOptions, - DocstringStyle, - parse, - parsers, -) -from griffe._internal.docstrings.sphinx import SphinxOptions, parse_sphinx -from griffe._internal.docstrings.utils import docstring_warning, parse_docstring_annotation -from griffe._internal.encoders import JSONEncoder, json_decoder -from griffe._internal.enumerations import ( - BreakageKind, - DocstringSectionKind, - ExplanationStyle, - Kind, - LogLevel, - ObjectKind, - ParameterKind, - Parser, - TypeParameterKind, -) -from griffe._internal.exceptions import ( - AliasResolutionError, - BuiltinModuleError, - CyclicAliasError, - ExtensionError, - ExtensionNotLoadedError, - GitError, - GriffeError, - LastNodeError, - LoadingError, - NameResolutionError, - RootNodeError, - UnhandledEditableModuleError, - UnimportableModuleError, -) -from griffe._internal.expressions import ( - Expr, - ExprAttribute, - ExprBinOp, - ExprBoolOp, - ExprCall, - ExprCompare, - ExprComprehension, - ExprConstant, - ExprDict, - ExprDictComp, - ExprExtSlice, - ExprFormatted, - ExprGeneratorExp, - ExprIfExp, - ExprJoinedStr, - ExprKeyword, - ExprLambda, - ExprList, - ExprListComp, - ExprName, - ExprNamedExpr, - ExprParameter, - ExprSet, - ExprSetComp, - ExprSlice, - ExprSubscript, - ExprTuple, - ExprUnaryOp, - ExprVarKeyword, - ExprVarPositional, - ExprYield, - ExprYieldFrom, - get_annotation, - get_base_class, - get_class_keyword, - get_condition, - get_expression, - safe_get_annotation, - safe_get_base_class, - safe_get_class_keyword, - safe_get_condition, - safe_get_expression, -) -from griffe._internal.extensions.base import ( - Extension, - Extensions, - LoadableExtensionType, - builtin_extensions, - load_extensions, -) -from griffe._internal.extensions.dataclasses import DataclassesExtension -from griffe._internal.extensions.unpack_typeddict import UnpackTypedDictExtension -from griffe._internal.finder import ModuleFinder, NamePartsAndPathType, NamePartsType, NamespacePackage, Package -from griffe._internal.git import GitInfo, KnownGitService -from griffe._internal.importer import dynamic_import, sys_path -from griffe._internal.loader import GriffeLoader, load, load_git, load_pypi -from griffe._internal.logger import Logger, get_logger, logger, patch_loggers -from griffe._internal.merger import merge_stubs -from griffe._internal.mixins import ( - DelMembersMixin, - GetMembersMixin, - ObjectAliasMixin, - SerializationMixin, - SetMembersMixin, -) -from griffe._internal.models import ( - Alias, - Attribute, - Class, - Decorator, - Docstring, - Function, - Module, - Object, - Parameter, - Parameters, - TypeAlias, - TypeParameter, - TypeParameters, -) -from griffe._internal.stats import Stats -from griffe._internal.tests import ( - TmpPackage, - htree, - module_vtree, - temporary_inspected_module, - temporary_inspected_package, - temporary_pyfile, - temporary_pypackage, - temporary_visited_module, - temporary_visited_package, - vtree, -) +from griffecli import * # noqa: F403 +from griffecli import __all__ as __cli_all__ +from griffelib import * # noqa: F403 +from griffelib import __all__ as __lib_all__ -# Regenerate this list with the following Python snippet: -# import griffe -# names = sorted(n for n in dir(griffe) if not n.startswith("_") and n not in ("annotations",)) -# print('__all__ = [\n "' + '",\n "'.join(names) + '",\n]') -__all__ = [ - "DEFAULT_LOG_LEVEL", - "Alias", - "AliasResolutionError", - "Attribute", - "AttributeChangedTypeBreakage", - "AttributeChangedValueBreakage", - "AutoOptions", - "Breakage", - "BreakageKind", - "BuiltinModuleError", - "Class", - "ClassRemovedBaseBreakage", - "CyclicAliasError", - "DataclassesExtension", - "Decorator", - "DelMembersMixin", - "Docstring", - "DocstringAdmonition", - "DocstringAttribute", - "DocstringClass", - "DocstringDeprecated", - "DocstringDetectionMethod", - "DocstringElement", - "DocstringFunction", - "DocstringModule", - "DocstringNamedElement", - "DocstringOptions", - "DocstringParameter", - "DocstringRaise", - "DocstringReceive", - "DocstringReturn", - "DocstringSection", - "DocstringSectionAdmonition", - "DocstringSectionAttributes", - "DocstringSectionClasses", - "DocstringSectionDeprecated", - "DocstringSectionExamples", - "DocstringSectionFunctions", - "DocstringSectionKind", - "DocstringSectionModules", - "DocstringSectionOtherParameters", - "DocstringSectionParameters", - "DocstringSectionRaises", - "DocstringSectionReceives", - "DocstringSectionReturns", - "DocstringSectionText", - "DocstringSectionTypeAliases", - "DocstringSectionTypeParameters", - "DocstringSectionWarns", - "DocstringSectionYields", - "DocstringStyle", - "DocstringTypeAlias", - "DocstringTypeParameter", - "DocstringWarn", - "DocstringYield", - "ExplanationStyle", - "Expr", - "ExprAttribute", - "ExprBinOp", - "ExprBoolOp", - "ExprCall", - "ExprCompare", - "ExprComprehension", - "ExprConstant", - "ExprDict", - "ExprDictComp", - "ExprExtSlice", - "ExprFormatted", - "ExprGeneratorExp", - "ExprIfExp", - "ExprJoinedStr", - "ExprKeyword", - "ExprLambda", - "ExprList", - "ExprListComp", - "ExprName", - "ExprNamedExpr", - "ExprParameter", - "ExprSet", - "ExprSetComp", - "ExprSlice", - "ExprSubscript", - "ExprTuple", - "ExprUnaryOp", - "ExprVarKeyword", - "ExprVarPositional", - "ExprYield", - "ExprYieldFrom", - "Extension", - "ExtensionError", - "ExtensionNotLoadedError", - "Extensions", - "Function", - "GetMembersMixin", - "GitError", - "GitInfo", - "GoogleOptions", - "GriffeError", - "GriffeLoader", - "Inspector", - "JSONEncoder", - "Kind", - "KnownGitService", - "LastNodeError", - "LinesCollection", - "LoadableExtensionType", - "LoadingError", - "LogLevel", - "Logger", - "Module", - "ModuleFinder", - "ModulesCollection", - "NamePartsAndPathType", - "NamePartsType", - "NameResolutionError", - "NamespacePackage", - "NumpyOptions", - "Object", - "ObjectAliasMixin", - "ObjectChangedKindBreakage", - "ObjectKind", - "ObjectNode", - "ObjectRemovedBreakage", - "Package", - "Parameter", - "ParameterAddedRequiredBreakage", - "ParameterChangedDefaultBreakage", - "ParameterChangedKindBreakage", - "ParameterChangedRequiredBreakage", - "ParameterKind", - "ParameterMovedBreakage", - "ParameterRemovedBreakage", - "Parameters", - "ParametersType", - "Parser", - "PerStyleOptions", - "ReturnChangedTypeBreakage", - "RootNodeError", - "SerializationMixin", - "SetMembersMixin", - "SphinxOptions", - "Stats", - "TmpPackage", - "TypeAlias", - "TypeParameter", - "TypeParameterKind", - "TypeParameters", - "UnhandledEditableModuleError", - "UnimportableModuleError", - "UnpackTypedDictExtension", - "Visitor", - "ast_children", - "ast_first_child", - "ast_kind", - "ast_last_child", - "ast_next", - "ast_next_siblings", - "ast_previous", - "ast_previous_siblings", - "ast_siblings", - "builtin_decorators", - "builtin_extensions", - "c3linear_merge", - "check", - "docstring_warning", - "dump", - "dynamic_import", - "find_breaking_changes", - "get__all__", - "get_annotation", - "get_base_class", - "get_class_keyword", - "get_condition", - "get_docstring", - "get_expression", - "get_instance_names", - "get_logger", - "get_name", - "get_names", - "get_parameters", - "get_parser", - "get_value", - "htree", - "infer_docstring_style", - "inspect", - "json_decoder", - "load", - "load_extensions", - "load_git", - "load_pypi", - "logger", - "main", - "merge_stubs", - "module_vtree", - "parse", - "parse_auto", - "parse_docstring_annotation", - "parse_google", - "parse_numpy", - "parse_sphinx", - "parsers", - "patch_loggers", - "relative_to_absolute", - "safe_get__all__", - "safe_get_annotation", - "safe_get_base_class", - "safe_get_class_keyword", - "safe_get_condition", - "safe_get_expression", - "safe_get_value", - "stdlib_decorators", - "sys_path", - "temporary_inspected_module", - "temporary_inspected_package", - "temporary_pyfile", - "temporary_pypackage", - "temporary_visited_module", - "temporary_visited_package", - "typing_overload", - "visit", - "vtree", -] +__all__ = [*__lib_all__, *__cli_all__] # noqa: PLE0604 diff --git a/src/griffe/__main__.py b/src/griffe/__main__.py index a9047c9b9..30c64ab2b 100644 --- a/src/griffe/__main__.py +++ b/src/griffe/__main__.py @@ -1,13 +1,14 @@ -# Entry-point module, in case you use `python -m griffe`. -# -# Why does this file exist, and why `__main__`? For more info, read: -# -# - https://www.python.org/dev/peps/pep-0338/ -# - https://docs.python.org/3/using/cmdline.html#cmdoption-m +"""Entry-point module, in case you use `python -m griffe`. + +Why does this file exist, and why `__main__`? For more info, read: + +- https://www.python.org/dev/peps/pep-0338/ +- https://docs.python.org/3/using/cmdline.html#cmdoption-m +""" import sys -from griffe._internal.cli import main +from griffecli import main if __name__ == "__main__": sys.exit(main(sys.argv[1:])) diff --git a/tests/helpers.py b/tests/helpers.py index 47613ddd0..1ca06eaef 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -6,7 +6,7 @@ import sys from tempfile import gettempdir -from griffe._internal.tests import _TMPDIR_PREFIX +from griffelib._internal.tests import _TMPDIR_PREFIX def clear_sys_modules(name: str | None = None) -> None: diff --git a/tests/test_cli.py b/tests/test_cli.py index a71507a76..fde01915f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -6,7 +6,8 @@ import pytest -from griffe._internal import cli, debug +from griffecli._internal import cli +from griffelib._internal import debug def test_main() -> None: diff --git a/tests/test_docstrings/conftest.py b/tests/test_docstrings/conftest.py index 366727cee..c37dfda55 100644 --- a/tests/test_docstrings/conftest.py +++ b/tests/test_docstrings/conftest.py @@ -6,7 +6,7 @@ import pytest -from griffe._internal.docstrings import google, numpy, sphinx +from griffelib._internal.docstrings import google, numpy, sphinx from tests.test_docstrings.helpers import ParserType, parser if TYPE_CHECKING: diff --git a/tests/test_docstrings/test_google.py b/tests/test_docstrings/test_google.py index 0af072c6d..0685fd73d 100644 --- a/tests/test_docstrings/test_google.py +++ b/tests/test_docstrings/test_google.py @@ -1,4 +1,4 @@ -"""Tests for the [Google-style parser][griffe.docstrings.google].""" +"""Tests for the [Google-style parser][griffelib.docstrings.google].""" from __future__ import annotations diff --git a/tests/test_docstrings/test_numpy.py b/tests/test_docstrings/test_numpy.py index 344856e50..2cbe608c1 100644 --- a/tests/test_docstrings/test_numpy.py +++ b/tests/test_docstrings/test_numpy.py @@ -1,4 +1,4 @@ -"""Tests for the [Numpy-style parser][griffe.docstrings.numpy].""" +"""Tests for the [Numpy-style parser][griffelib.docstrings.numpy].""" from __future__ import annotations diff --git a/tests/test_docstrings/test_sphinx.py b/tests/test_docstrings/test_sphinx.py index 90279e4dd..738cf01a7 100644 --- a/tests/test_docstrings/test_sphinx.py +++ b/tests/test_docstrings/test_sphinx.py @@ -1,4 +1,4 @@ -"""Tests for the [Sphinx-style parser][griffe.docstrings.sphinx].""" +"""Tests for the [Sphinx-style parser][griffelib.docstrings.sphinx].""" from __future__ import annotations diff --git a/tests/test_encoders.py b/tests/test_encoders.py index b8d3eeb47..938688194 100644 --- a/tests/test_encoders.py +++ b/tests/test_encoders.py @@ -73,7 +73,7 @@ def test_namespace_packages() -> None: def test_minimal_light_data_is_enough(symbol: str) -> None: """Test serialization and de-serialization.""" loader = GriffeLoader() - package = loader.load("griffe") + package = loader.load("griffelib") obj = package[symbol] dump_options = {"indent": 2, "sort_keys": True} minimal = obj.as_json(full=False, **dump_options) diff --git a/tests/test_extensions/test_base.py b/tests/test_extensions/test_base.py index 7ca78dee4..5f5caa7a1 100644 --- a/tests/test_extensions/test_base.py +++ b/tests/test_extensions/test_base.py @@ -17,7 +17,7 @@ temporary_visited_module, temporary_visited_package, ) -from griffe._internal.models import Attribute, Class, Function, Module, Object, TypeAlias +from griffelib._internal.models import Attribute, Class, Function, Module, Object, TypeAlias if TYPE_CHECKING: import ast diff --git a/tests/test_finder.py b/tests/test_finder.py index 9b6d34076..d65c492fc 100644 --- a/tests/test_finder.py +++ b/tests/test_finder.py @@ -9,7 +9,7 @@ import pytest from griffe import Module, ModuleFinder, NamespacePackage, Package, temporary_pypackage -from griffe._internal.finder import _handle_editable_module, _handle_pth_file +from griffelib._internal.finder import _handle_editable_module, _handle_pth_file @pytest.mark.parametrize(