ocebuild.sources#

Methods and Classes for handling external sources.

Submodules#

Package Contents#

Classes#

RequestWrapper

Wrapper for urllib.request.Request to provide a nicer interface.

GitHubResolver

Resolves a GitHub URL based on the class parameters.

DortaniaResolver

Resolves a Dortania build URL based on the class parameters.

PathResolver

Resolves a filepath based on the class parameters.

Functions#

request(→ any)

Simple wrapper over urlopen for skipping SSL verification.

is_latest_build(→ bool)

Checks if the cached build catalog is latest.

has_build(→ bool)

Checks if a plugin has a build.

get_latest_sha(→ str)

Gets the latest build sha for a plugin.

dortania_file_url(→ str)

Formats a Dortania build repo file URL.

dortania_release_url(→ str)

Formats a Dortania build release URL.

github_api_request(→ any)

Gets a GitHub API request.

github_rate_limit(→ int)

Gets the GitHub API rate limit.

get_latest_commit(repository[, branch])

Get the latest commit of a branch in a GitHub repository.

github_suite_id(→ Union[int, None])

Gets the GitHub check suite ID for a given commit.

github_tag_names(→ Union[List[str], Tuple[List[str], ...)

Returns a list of all repository tags.

github_release_catalog(→ dict)

Gets the catalog entry for a given release.

github_file_url(→ str)

Formats a GitHub file URL.

github_archive_url(→ str)

Formats a GitHub archive URL.

github_release_url(→ str)

Formats a GitHub release URL.

github_artifacts_url(→ Union[str, Tuple[str, str], None])

Formats a GitHub artifacts URL.

Attributes#

ResolverType

A type alias for the Resolver classes.

ocebuild.sources.request(url: str | urllib.request.Request, *args, **kwargs) any[source]#

Simple wrapper over urlopen for skipping SSL verification.

Parameters:
  • url – The url to open.

  • *args – Additional arguments to pass to urlopen.

  • **kwargs – Additional keyword arguments to pass to urlopen.

Raises:

HTTPError – If the url could not be retrieved.

Returns:

The response from urlopen wrapped in a RequestWrapper class.

class ocebuild.sources.RequestWrapper(response: any)[source]#

Wrapper for urllib.request.Request to provide a nicer interface.

__enter__() RequestWrapper[source]#
__exit__(*args: object) None[source]#
__getattr__(attr)[source]#
json(*args, **kargs) any[source]#

Return the response as JSON.

text(*args, **kargs) io.TextIOWrapper[source]#

Return the response as text.

ocebuild.sources.is_latest_build() bool[source]#

Checks if the cached build catalog is latest.

ocebuild.sources.has_build(plugin: str) bool[source]#

Checks if a plugin has a build.

ocebuild.sources.get_latest_sha(plugin: str) str[source]#

Gets the latest build sha for a plugin.

ocebuild.sources.dortania_file_url(filepath: str) str[source]#

Formats a Dortania build repo file URL.

Parameters:

file – The remote filepath of the file.

Returns:

The formatted Dortania build repo file URL.

ocebuild.sources.dortania_release_url(plugin: str, commit: str | None = None) str[source]#

Formats a Dortania build release URL.

Parameters:
  • plugin – The plugin to get the release URL for.

  • commit – The commit to get the release URL for. Defaults to the latest build.

Returns:

The formatted Dortania build release URL.

ocebuild.sources.github_api_request(endpoint: str | None = None, url: str | None = None) any[source]#

Gets a GitHub API request.

This method will automatically add the GitHub token from the environment.

Parameters:

endpoint – GitHub API endpoint.

Returns:

API response.

ocebuild.sources.github_rate_limit(kind: str = 'core', raise_error: float = False) int[source]#

Gets the GitHub API rate limit.

Parameters:
  • kind – The kind of GitHub API request to query.

  • raise_error – Raise an exception if the rate limit has been exceeded.

Returns:

Remaining API calls allowed.

Raises:

Exception – If the rate limit has been exceeded.

ocebuild.sources.get_latest_commit(repository: str, branch: str = 'main')[source]#

Get the latest commit of a branch in a GitHub repository.

ocebuild.sources.github_suite_id(repository: str, commit: str, workflow_id: int, status: str | None = 'completed') int | None[source]#

Gets the GitHub check suite ID for a given commit.

Parameters:
  • repository – GitHub repository name.

  • commit – Commit hash.

Returns:

Check suite ID.

ocebuild.sources.github_tag_names(repository: str, get_commits=False) List[str] | Tuple[List[str], List[str]][source]#

Returns a list of all repository tags.

Parameters:
  • repository – GitHub repository name.

  • get_commits – If True, additionally returns a list of commit hashes.

Returns:

List of repository tags.

ocebuild.sources.github_release_catalog(url: str) dict[source]#

Gets the catalog entry for a given release.

Parameters:

url – GitHub release catalog URL.

Returns:

Release catalog.

ocebuild.sources.github_file_url(repository: str, path: str, branch: str = 'main', tag: str | None = None, commit: str | None = None, raw: bool = False) str[source]#

Formats a GitHub file URL.

Parameters:
  • repository – GitHub repository name.

  • path – Relative path to file.

  • branch – Branch name.

  • tag – Tag name.

  • commit – Commit hash.

  • raw – If True, returns the raw URL.

Returns:

URL of the file.

Example

>>> github_file_url('foo/bar', path='file.json')
# -> "https://github.com/foo/bar/blob/main/file.json"
>>> github_file_url('foo/bar', path='file.json', branch='dev')
# -> "https://github.com/foo/bar/blob/dev/file.json"
>>> github_file_url('foo/bar', path='file.json', tag='v1.0.0')
# -> "https://github.com/foo/bar/blob/v1.0.0/file.json"
>>> github_file_url('foo/bar', path='file.json', commit='c0ffee')
# -> "https://github.com/foo/bar/blob/c0ffee/file.json"
>>> github_file_url('foo/bar', path='file.json', raw=True)
# -> "https://raw.githubusercontent.com/foo/bar/main/file.json"
ocebuild.sources.github_archive_url(repository: str, branch: str = 'main', tag: str | None = None, commit: str | None = None) str[source]#

Formats a GitHub archive URL.

Parameters:
  • repository – GitHub repository name.

  • branch – Branch name.

  • tag – Tag name.

  • commit – Commit hash.

Returns:

URL of the archive.

Example

>>> github_archive_url('foo/bar')
# -> "https://github.com/foo/bar/archive/refs/heads/main.tar.gz"
>>> github_archive_url('foo/bar', branch='dev')
# -> "https://github.com/foo/bar/archive/refs/heads/dev.tar.gz"
>>> github_archive_url('foo/bar', tag='v1.0.0')
# -> "https://github.com/foo/bar/archive/refs/tags/v1.0.0.tar.gz"
>>> github_archive_url('foo/bar', commit='c0ffee')
# -> "https://github.com/foo/bar/archive/c0ffee.tar.gz"
ocebuild.sources.github_release_url(repository: str, tag: str | None = None) str[source]#

Formats a GitHub release URL.

Parameters:
  • repository – GitHub repository name.

  • tag – Tag name.

Returns:

URL of the release.

Example

>>> github_release_url('foo/bar')
# -> "https://github.com/foo/bar/releases/latest/v2.0.0"
>>> github_release_url('foo/bar', tag='v1.0.0')
# -> "https://github.com/foo/bar/releases/tag/v1.0.0"
ocebuild.sources.github_artifacts_url(repository: str, branch: str | None = None, workflow: str | None = None, commit: str | None = None, get_commit=False) str | Tuple[str, str] | None[source]#

Formats a GitHub artifacts URL.

Parameters:
  • repository – GitHub repository name.

  • branch – Branch name.

  • tag – Tag name.

  • commit – Commit hash.

  • get_commit – If True, additionally returns the commit hash.

Returns:

URL of the artifacts archive.

ocebuild.sources.ResolverType[source]#

A type alias for the Resolver classes.

class ocebuild.sources.GitHubResolver(repository: str, path: ocebuild.sources.github.Optional[str] = None, branch: ocebuild.sources.github.Optional[str] = None, tag: ocebuild.sources.github.Optional[str] = None, workflow: ocebuild.sources.github.Optional[str] = None, commit: ocebuild.sources.github.Optional[str] = None, *args, tarball: ocebuild.sources.github.Optional[bool] = False, **kwargs)[source]#

Bases: BaseResolver

Resolves a GitHub URL based on the class parameters.

static extract_asset(resolver: ocebuild.sources.github.Union[TGitHubResolver, TDortaniaResolver], name: str, url: str, build: ocebuild.sources.github.Optional[Literal[RELEASE, DEBUG]] = None) str[source]#

Extracts the closest matching asset from a GitHub release url.

resolve(build: ocebuild.sources.github.Optional[Literal[RELEASE, DEBUG]] = None) str[source]#

Returns a URL based on the class parameters.

class ocebuild.sources.DortaniaResolver(commit: ocebuild.sources.github.Optional[str] = None, *args, **kwargs)[source]#

Bases: BaseResolver

Resolves a Dortania build URL based on the class parameters.

static has_build(plugin: str)[source]#
resolve(build: ocebuild.sources.github.Optional[Literal[RELEASE, DEBUG]] = None) str[source]#

Returns a URL based on the class parameters.

class ocebuild.sources.PathResolver(path: ocebuild.third_party.cpython.pathlib.Path, *args, **kwargs)[source]#

Bases: BaseResolver, ocebuild.third_party.cpython.pathlib.Path

Resolves a filepath based on the class parameters.

glob(pattern: str) Generator[TPathResolver, any, None][source]#

Iterates from a directory or from a file’s parent directory.

resolve(strict: bool = False) ocebuild.third_party.cpython.pathlib.Path[source]#

Resolves a filepath based on the class parameters.

If the path exists, the checksum is calculated and stored.

Parameters:

strict – If True, raises an error if the path does not exist.

Returns:

The resolved filepath wrapped in a PathResolver instance.