nitpick.style.fetchers.pypackage module

Support for py schemes.

class nitpick.style.fetchers.pypackage.BuiltinStyle(*, py_url: furl, py_url_without_ext: furl, path_from_repo_root: str, path_from_resources_root: str)[source]

Bases: object

A built-in style file in TOML format.

Method generated by attrs for class BuiltinStyle.

files: list[str]
classmethod from_path(resource_path: Path) BuiltinStyle[source]

Create a built-in style from a resource path.

identify_tag: str
name: str
path_from_repo_root: str
path_from_resources_root: str
py_url: furl
py_url_without_ext: furl
pypackage_url: PythonPackageURL
url: str
class nitpick.style.fetchers.pypackage.PythonPackageFetcher(session: CachedSession | None = None, protocols: tuple[str, ...] = (<Scheme.PY: 'py'>, <Scheme.PYPACKAGE: 'pypackage'>), domains: tuple[str, ...] = ())[source]

Bases: StyleFetcher

Fetch a style from an installed Python package.

URL schemes: - py://import/path/of/style/file/<style_file_name> - pypackage://import/path/of/style/file/<style_file_name>

E.g. py://some_package/path/nitpick.toml.

domains: tuple[str, ...] = ()
fetch(url: furl) str[source]

Fetch the style from a Python package.

normalize(url: furl) furl

Normalize a URL.

Produces a canonical URL, meant to be used to uniquely identify a style resource.

  • The base name has .toml appended if not already ending in that extension

  • Individual fetchers can further normalize the path and scheme.

preprocess_relative_url(url: str) str

Preprocess a relative URL.

Only called for urls that lack a scheme (at the very least), being resolved against a base URL that matches this specific fetcher.

protocols: tuple[str, ...] = (<Scheme.PY: 'py'>, <Scheme.PYPACKAGE: 'pypackage'>)
requires_connection: ClassVar[bool] = False
session: CachedSession | None = None
class nitpick.style.fetchers.pypackage.PythonPackageURL(import_path: str, resource_name: str)[source]

Bases: object

Represent a resource file in installed Python package.

property content_path: Path

Raw path of resource file.

classmethod from_furl(url: furl) PythonPackageURL[source]

Create an instance from a parsed URL in any accepted format.

See the code for test_parsing_python_package_urls() for more examples.

import_path: str
resource_name: str
nitpick.style.fetchers.pypackage.builtin_resources_root() Path[source]

Built-in resources root.

nitpick.style.fetchers.pypackage.builtin_styles() Iterable[Path][source]

List the built-in styles.

nitpick.style.fetchers.pypackage.repo_root() Path[source]

Repository root, 3 levels up from the resources root.