A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mkdocstrings.github.io/griffe/reference/api/loaders/ below:

Loaders - Griffe

Loaders¤ Main API¤ load ¤
load(
    objspec: str | Path | None = None,
    /,
    *,
    submodules: bool = True,
    try_relative_path: bool = True,
    extensions: Extensions | None = None,
    search_paths: Sequence[str | Path] | None = None,
    docstring_parser: DocstringStyle | Parser | None = None,
    docstring_options: dict[str, Any] | None = None,
    lines_collection: LinesCollection | None = None,
    modules_collection: ModulesCollection | None = None,
    allow_inspection: bool = True,
    force_inspection: bool = False,
    store_source: bool = True,
    find_stubs_package: bool = False,
    resolve_aliases: bool = False,
    resolve_external: bool | None = None,
    resolve_implicit: bool = False,
) -> Object | Alias

Load and return a Griffe object.

In Griffe's context, loading means:

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, Class, Function, Attribute, and TypeAlias classes for more information.

The main class used to load modules is GriffeLoader. Convenience functions like this one and load_git are also available.

Example
import griffe

module = griffe.load(...)

This is a shortcut for:

from griffe import GriffeLoader

loader = GriffeLoader(...)
module = loader.load(...)

See the documentation for the loader: GriffeLoader.

Parameters:

Returns:

load_git ¤
load_git(
    objspec: str | Path | None = None,
    /,
    *,
    ref: str = "HEAD",
    repo: str | Path = ".",
    submodules: bool = True,
    extensions: Extensions | None = None,
    search_paths: Sequence[str | Path] | None = None,
    docstring_parser: DocstringStyle | Parser | None = None,
    docstring_options: dict[str, Any] | None = None,
    lines_collection: LinesCollection | None = None,
    modules_collection: ModulesCollection | None = None,
    allow_inspection: bool = True,
    force_inspection: bool = False,
    find_stubs_package: bool = False,
    resolve_aliases: bool = False,
    resolve_external: bool | None = None,
    resolve_implicit: bool = False,
) -> Object | Alias

Load and return a module from a specific Git reference.

This function will create a temporary git worktree at the requested reference before loading module with griffe.load.

This function requires that the git executable is installed.

Examples:

from griffe import load_git

old_api = load_git("my_module", ref="v0.1.0", repo="path/to/repo")

Parameters:

Returns:

load_pypi ¤
load_pypi(
    package: str,
    distribution: str,
    version_spec: str,
    *,
    submodules: bool = True,
    extensions: Extensions | None = None,
    search_paths: Sequence[str | Path] | None = None,
    docstring_parser: DocstringStyle | Parser | None = None,
    docstring_options: dict[str, Any] | None = None,
    lines_collection: LinesCollection | None = None,
    modules_collection: ModulesCollection | None = None,
    allow_inspection: bool = True,
    force_inspection: bool = False,
    find_stubs_package: bool = False,
    resolve_aliases: bool = False,
    resolve_external: bool | None = None,
    resolve_implicit: bool = False,
) -> Object | Alias

Load and return a module from a specific package version downloaded using pip.

Sponsors only Insiders 1.1.0.

Parameters:

Advanced API¤ GriffeLoader ¤
GriffeLoader(
    *,
    extensions: Extensions | None = None,
    search_paths: Sequence[str | Path] | None = None,
    docstring_parser: DocstringStyle | Parser | None = None,
    docstring_options: dict[str, Any] | None = None,
    lines_collection: LinesCollection | None = None,
    modules_collection: ModulesCollection | None = None,
    allow_inspection: bool = True,
    force_inspection: bool = False,
    store_source: bool = True,
)

The Griffe loader, allowing to load data from modules.

Parameters:

Methods:

Attributes:

allow_inspection instance-attribute ¤

Whether to allow inspecting (importing) modules for which we can't find sources.

docstring_options instance-attribute ¤

Configured parsing options.

docstring_parser instance-attribute ¤

Selected docstring parser.

extensions instance-attribute ¤

Loaded Griffe extensions.

finder instance-attribute ¤

The module source finder.

force_inspection instance-attribute ¤
force_inspection: bool = force_inspection

Whether to force inspecting (importing) modules, even when sources were found.

ignored_modules class-attribute ¤
ignored_modules: set[str] = {'debugpy', '_pydev'}

Special modules to ignore when loading.

For example, debugpy and _pydev are used when debugging with VSCode and should generally never be loaded.

lines_collection instance-attribute ¤

Collection of source code lines.

modules_collection instance-attribute ¤

Collection of modules.

store_source instance-attribute ¤

Whether to store source code in the lines collection.

expand_exports ¤

Expand exports: try to recursively expand all module exports (__all__ values).

See also: Module.exports.

Parameters:

expand_wildcards ¤

Expand wildcards: try to recursively expand all found wildcards.

See also: Alias.wildcard.

Parameters:

load ¤

Load an object as a Griffe object, given its Python or file path.

Note that this will load the whole object's package, and return only the specified object. The rest of the package can be accessed from the returned object with regular methods and properties (parent, members, etc.).

Examples:

>>> loader.load("griffe.Module")
Alias("Module", "griffe._internal.models.Module")

Parameters:

Raises:

Returns:

resolve_aliases ¤

Resolve aliases.

Parameters:

Returns:

resolve_module_aliases ¤

Follow aliases: try to recursively resolve all found aliases.

Parameters:

Returns:

stats ¤

Compute some statistics.

Returns:

ModulesCollection ¤

Bases: GetMembersMixin, SetMembersMixin, DelMembersMixin


              flowchart TD
              griffe.ModulesCollection[ModulesCollection]
              griffe._internal.mixins.GetMembersMixin[GetMembersMixin]
              griffe._internal.mixins.SetMembersMixin[SetMembersMixin]
              griffe._internal.mixins.DelMembersMixin[DelMembersMixin]

                              griffe._internal.mixins.GetMembersMixin --> griffe.ModulesCollection
                
                griffe._internal.mixins.SetMembersMixin --> griffe.ModulesCollection
                
                griffe._internal.mixins.DelMembersMixin --> griffe.ModulesCollection
                


              click griffe.ModulesCollection href "" "griffe.ModulesCollection"
              click griffe._internal.mixins.GetMembersMixin href "" "griffe._internal.mixins.GetMembersMixin"
              click griffe._internal.mixins.SetMembersMixin href "" "griffe._internal.mixins.SetMembersMixin"
              click griffe._internal.mixins.DelMembersMixin href "" "griffe._internal.mixins.DelMembersMixin"
            

A collection of modules, allowing easy access to members.

Initialize the collection.

Methods:

Attributes:

all_members property ¤

Members of the collection.

This property is overwritten to simply return self.members, as all_members does not make sense for a modules collection.

is_collection class-attribute instance-attribute ¤

Marked as collection to distinguish from objects.

members instance-attribute ¤

Members (modules) of the collection.

__bool__ ¤

A modules collection is always true-ish.

__contains__ ¤

Check if a module is in the collection.

__delitem__ ¤

Delete a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> del griffe_object["foo"]
>>> del griffe_object["path.to.bar"]
>>> del griffe_object[("path", "to", "qux")]
__getitem__ ¤

Get a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> qux = griffe_object[("path", "to", "qux")]
__setitem__ ¤

Set a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Parameters:

Examples:

>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux
del_member ¤

Delete a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> griffe_object.del_member("foo")
>>> griffe_object.del_member("path.to.bar")
>>> griffe_object.del_member(("path", "to", "qux"))
get_member ¤

Get a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> bar = griffe_object[("path", "to", "bar")]
set_member ¤

Set a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Parameters:

Examples:

>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux"), qux)
LinesCollection ¤

A simple dictionary containing the modules source code lines.

Initialize the collection.

Methods:

__bool__ ¤

A lines collection is always true-ish.

__contains__ ¤

Check if a file path is in the collection.

__getitem__ ¤

Get the lines of a file path.

__setitem__ ¤

Set the lines of a file path.

items ¤

Return the collection items.

Returns:

keys ¤

Return the collection keys.

Returns:

values ¤

Return the collection values.

Returns:

Additional API¤ Stats ¤

Load statistics for a Griffe loader.

Parameters:

Methods:

Attributes:

by_kind instance-attribute ¤

Number of objects by kind.

lines instance-attribute ¤
lines = sum((len(lines)) for lines in (values()))

Total number of lines.

loader instance-attribute ¤

The loader to compute stats for.

modules_by_extension instance-attribute ¤
modules_by_extension = modules_by_extension

Number of modules by extension.

packages instance-attribute ¤
packages = len(top_modules)

Number of packages.

time_spent_inspecting instance-attribute ¤
time_spent_inspecting = 0

Time spent inspecting modules.

time_spent_serializing instance-attribute ¤
time_spent_serializing = 0

Time spent serializing objects.

time_spent_visiting instance-attribute ¤

Time spent visiting modules.

as_text ¤

Format the statistics as text.

Returns:

merge_stubs ¤

Merge stubs into a module.

Parameters:

Raises:

Returns:

2024-07-14 2024-07-10

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4