repo_review package¶
Copyright (c) 2022 Henry Schreiner. All rights reserved.
Review repos with a set of checks defined by plugins.
Subpackages¶
Submodules¶
repo_review.checks module¶
- class repo_review.checks.Check(*args, **kwargs)[source]¶
Bases:
ProtocolThis is the check Protocol. Since Python doesn’t support optional Protocol members, the two optional members are required if you want to use this Protocol in a type checker. The members can be specified as class properties if you want.
- check()[source]¶
This is a check. The docstring is used as the failure message if False is returned. Returning None is a skip. Returning True (or an empty string) is a pass. Can be a
classmethod()orstaticmethod(). Can take fixtures.
- repo_review.checks.collect_checks(fixtures)[source]¶
Produces a list of checks based on installed entry points. You must provide the evaluated fixtures so that the check functions have access to the fixtures when they are running.
- repo_review.checks.get_check_url(name, check)[source]¶
Get the url from a check instance. Will return an empty string if missing. Will process string via format.
- Parameters:
- Return type:
- Returns:
The final URL.
Added in version 0.8.
- repo_review.checks.is_allowed(select, ignore, name)[source]¶
Skips the check if the name is in the ignore list or if the name without the number is in the ignore list. If the select list is not empty, only runs the check if the name or name without the number is in the select list.
repo_review.families module¶
- class repo_review.families.Family[source]¶
Bases:
TypedDictA typed Dict that is used to customize the display of families in reports.
- repo_review.families.collect_families(fixtures)[source]¶
Produces a dict mapping family keys to
Familydicts based on installed entry points. You must provide the evaluated fixtures so that the family functions have access to the fixtures when they are running, usually used for descriptions.
repo_review.files module¶
- repo_review.files.collect_prefetch_files()[source]¶
Produces a mapping with keys
"root"and/or"package"to sets of files that should be prefetched.Entry-points whose name is
"package"are collected under the"package"key (resolved relative to the package directory). All other entry-points (name"root"or empty) are collected under"root"(resolved relative to the repository root).
- repo_review.files.prefetch_root()[source]¶
This entry-point lists files that should be prefetched. This is a suggestion for async loading.
- async repo_review.files.process_prefetch_files(start, /, files, *, subdir='')[source]¶
Process pre-fetch files. This runs in parallel with async loading.
filesis a mapping with keys"root"and/or"package". Patterns under"root"are resolved relative to the repository root (start); patterns under"package"are resolved relative to the package directory (start / subdir, orstartwhen subdir is empty).
repo_review.fixtures module¶
- repo_review.fixtures.apply_fixtures(fixtures, func)[source]¶
Given the pre-computed dict of fixtures and a function, fill in any fixtures from that dict that it requests and return the result.
- repo_review.fixtures.collect_fixtures()[source]¶
Produces a dict of fixture callables based on installed entry points. You should call
compute_fixtures()on the result to get the standard dict of fixture results that most other functions in repo-review expect.- Return type:
dict[str,Callable[[Traversable],Any]]- Returns:
A dict of unevaluated fixtures.
- repo_review.fixtures.compute_fixtures(root, package, unevaluated_fixtures)[source]¶
Given the repo
rootTraversable, thepackageTraversable, and the dict of all fixture callables, compute the dict of fixture results.- Parameters:
root (
Traversable) – The root of the repositorypackage (
Traversable) – The path to the package (root / subdir)unevaluated_fixtures (
Mapping[str,Callable[...,Any]]) – The unevaluated mapping of fixture names to callables.
- Return type:
- Returns:
The fully evaluated dict of fixtures.
- repo_review.fixtures.list_all(root)[source]¶
Fixture: Is True when this is trying to produce a list of all checks.
- Parameters:
root (
Traversable) – The root fixture.- Return type:
- Returns:
True only if trying to make a list of all checks/fixtures/families.
Added in version 0.8.
- repo_review.fixtures.pyproject(package)[source]¶
Fixture: The
pyproject.tomlstructure from the package. Returned an empty dict if no pyproject.toml found.- Parameters:
package (
Traversable) – The package fixture.- Return type:
- Returns:
The pyproject.toml dict or an empty dict if no file found.
repo_review.ghpath module¶
- class repo_review.ghpath.EmptyTraversable(*, is_a_dir=True, _fake_name='not-a-real-path')[source]¶
Bases:
TraversableThis is a Traversable representing an empty directory or a non-existent file.
- Parameters:
- joinpath(child)[source]¶
Return Traversable resolved with any descendants applied.
Each descendant should be a path segment relative to self and each may contain multiple levels separated by
posixpath.sep(/).- Parameters:
child (
str)- Return type:
- open(mode='r', encoding='utf-8')[source]¶
- Overloads:
self, mode (Literal[‘r’]), encoding (str | None) → io.StringIO
self, mode (Literal[‘rb’]) → io.BytesIO
mode may be ‘r’ or ‘rb’ to open as text or binary. Return a handle suitable for reading (same as pathlib.Path.open).
When opening as text, accepts encoding parameters such as those accepted by io.TextIOWrapper.
- class repo_review.ghpath.GHPath(*, repo, branch, path='', _info=<factory>, _fetched=<factory>)[source]¶
Bases:
TraversableThis is a Traversable that can be used to navigate a GitHub repo without downloading it.
Will throw an KeyError if the response is not valid.
- Parameters:
Making new paths from this path will propagate the _fetched dict.
- async classmethod async_from_repo(repo, branch, path='')[source]¶
Async constructor that populates _info by fetching the GitHub tree using open_url_async instead of performing synchronous network IO in __post_init__.
Can throw a KeyError.
- glob(pattern)[source]¶
Yield paths matching the given glob-style pattern relative to this GHPath. Patterns support ** recursion via PurePosixPath.match.
- joinpath(child)[source]¶
Return Traversable resolved with any descendants applied.
Each descendant should be a path segment relative to self and each may contain multiple levels separated by
posixpath.sep(/).
- open(mode='r', encoding='utf-8')[source]¶
- Overloads:
self, mode (Literal[‘r’]), encoding (str | None) → io.StringIO
self, mode (Literal[‘rb’]) → io.BytesIO
Open the repo. This doesn’t support the full collection of options, only utf-8 and binary.
- static open_url(url)[source]¶
This method can be overridden manually for WASM. Supports pyodide currently.
- async static open_url_async(url)[source]¶
This method can be overridden manually for WASM. Supports pyodide currently.
- async prefetch()[source]¶
Prefetch a file. If the file doesn’t exist, this does nothing.
- Return type:
repo_review.html module¶
- repo_review.html.to_html(families, processed, status='empty')[source]¶
Convert the results of a repo review (
families,processed) to HTML.- Parameters:
- Return type:
repo_review.processor module¶
- class repo_review.processor.CollectionReturn(fixtures: dict[str, Any], checks: dict[str, Check], families: dict[str, Family])[source]¶
Bases:
NamedTupleReturn type for
collect_all().Added in version 0.8.
- class repo_review.processor.ProcessReturn(families: dict[str, Family], results: list[Result])[source]¶
Bases:
NamedTupleReturn type for
process().
- class repo_review.processor.Result(*, family, name, description, result, skip_reason='', err_msg='', url='')[source]¶
Bases:
objectThis is the returned value from a processed check.
- Parameters:
- err_as_html()[source]¶
Produces HTML from the error message, assuming it is in markdown. Deprecated, use
md_as_html()directly instead.- Return type:
- class repo_review.processor.ResultDict[source]¶
Bases:
TypedDictHelper to get the type in the JSON style returns. Basically identical to
Resultbut in dict form and without the name.
- repo_review.processor.as_simple_dict(results)[source]¶
Convert a results list into a simple dict of dicts structure. The name of the result turns into the key of the outer dict.
- Parameters:
- Return type:
- repo_review.processor.collect_all(root=None, subdir='')¶
Collect all checks. If
rootis not passed orNone, then checks are collected with aEmptyTraversable. Any checks that are returned conditionally based on fixture results might not be collected unlesslist_all()is used.- Parameters:
root (
Traversable|None) – If passed, this is the root of the repo (for fixture computation).Nonewill useEmptyTraversable.subdir (
str) – The subdirectory (for fixture computation).
- Return type:
- Returns:
The collected fixtures, checks, and families. Families is guaranteed to include all families and be in order.
Added in version 0.8.
Changed in version 1.0: Now None is supported.
- repo_review.processor.md_as_html(md_text)[source]¶
Heler function that converts markdown text to HTML. Strips paragraph tags from the result.
- repo_review.processor.process(root, *, select=frozenset({}), ignore=frozenset({}), extend_select=frozenset({}), extend_ignore=frozenset({}), subdir='', collected=None)¶
Process the package and return a dictionary of results.
- Parameters:
root (
Traversable) – The Traversable to the repository to process.select (
Set[str]) – A list of checks to select. All checks selected if empty.subdir (
str) – The path to the package in the subdirectory, if not at the root of the repository.collected (
CollectionReturn|None) – The return from a collection run. Skips collecting checks and rerunning fixtures if given.
- Return type:
- Returns:
The families and a list of checks. Families is guaranteed to include all families and be in order.
repo_review.schema module¶
This accesses the schema for repo-review’s tool section.
repo_review.testing module¶
Helpers for testing repo-review plugins.
- repo_review.testing.compute_check(name, /, **fixtures)[source]¶
A helper function to compute a check given fixtures, intended for testing. Currently, all fixtures are required to be passed in as keyword arguments, transitive fixtures are not supported.
- Parameters:
- Return type:
- Returns:
The computed result.
Added in version 0.10.5.