nitpick.style.fetchers.github module

Support for gh and github schemes.

class nitpick.style.fetchers.github.GitHubFetcher(session: CachedSession | None = None, protocols: tuple[str, ...] = (<Scheme.GH: 'gh'>, <Scheme.GITHUB: 'github'>), domains: tuple[str, ...] = ('github.com', ))[source]

Bases: HttpFetcher

Fetch styles from GitHub repositories.

domains: tuple[str, ...] = ('github.com',)
fetch(url: furl) str

Fetch the style from a web location.

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.GH: 'gh'>, <Scheme.GITHUB: 'github'>)
requires_connection: ClassVar[bool] = True
session: CachedSession | None = None
class nitpick.style.fetchers.github.GitHubURL(owner: str, repository: str, git_reference: str, path: tuple[str, ...] = (), auth_token: str | None = None, query_params: tuple[tuple[str, str], ...] | None = None)[source]

Bases: object

Represent a GitHub URL, created from a URL or from its parts.

property api_url: furl

API URL for this repo.

auth_token: str | None = None
property credentials: tuple[str, str] | tuple[()]

Credentials encoded in this URL.

A tuple of (api_token, '') if present, or empty tuple otherwise.

property default_branch: str

Default GitHub branch.

classmethod from_furl(url: furl) GitHubURL[source]

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

See the code for test_parsing_github_urls() for more examples.

git_reference: str
property git_reference_or_default: str

Return the Git reference if informed, or return the default branch.

property long_protocol_url: furl

Long protocol URL (github).

owner: str
path: tuple[str, ...] = ()
query_params: tuple[tuple[str, str], ...] | None = None
property raw_content_url: furl

Raw content URL for this path.

repository: str
property short_protocol_url: furl

Short protocol URL (gh).

property token: str | None

Token encoded in this URL.

If present and it starts with a $, it will be replaced with the value of the environment corresponding to the remaining part of the string.

property url: furl

Default URL built from attributes.

nitpick.style.fetchers.github.get_default_branch(api_url: str, *, token: str | None = None) str[source]

Get the default branch from the GitHub repo using the API.

For now, for URLs without an authorization token embedded, the request is not authenticated on GitHub, so it might hit a rate limit with: requests.exceptions.HTTPError: 403 Client Error: rate limit exceeded for url

This function is using lru_cache() as a simple memoizer, trying to avoid this rate limit error.