Support for gh and github schemes.

class cachy.cache_manager.CacheManager, cache_option: str, protocols: Tuple[str, ...] = ('gh', 'github'), domains: Tuple[str, ...] = ('',))[source]


Fetch styles from GitHub repositories.

cache_manager: CacheManager
cache_option: str
domains: Tuple[str, ...] = ('',)
fetch(url) Tuple[Optional[pathlib.Path], str]

Fetch a style form cache or from a specific fetcher.

protocols: Tuple[str, ...] = ('gh', 'github')
requires_connection = True

Bases: enum.Enum

Protocols for the GitHUb scheme.

LONG = 'github'
SHORT = 'gh'
class str, repository: str, git_reference: str, path: str, auth_token: str)[source]

Bases: object

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

property api_url: str

API URL for this repo.

auth_token: str
property credentials: Tuple

Credentials encoded in this URL.

A tuple of (api_token, '') if present, or empty tuple otherwise. If the value of api_token begins with $, it will be replaced with the value of the environment corresponding to the remaining part of the string.

property default_branch: str

Default GitHub branch.

This property performs a HTTP request and it’s memoized with lru_cache().

git_reference: str
property git_reference_or_default: str

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

property long_protocol_url: str

Long protocol URL (github).

owner: str
classmethod parse_url(url: str)[source]

Create an instance by parsing a URL string in any accepted format.

See the code for test_parsing_github_urls() for more examples.

path: str
property raw_content_url: str

Raw content URL for this path.

repository: str
property short_protocol_url: str

Short protocol URL (gh).

property url: str

Default URL built from attributes. str) str[source]

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

For now, 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.

Another option for the future: perform an authenticated request to GitHub. That would require a requests.Session and some user credentials.