Paths and backends
The paths need no URI and no library beyond pathapi.
GitHubPath, GitLabPath and GiteaPath share a base class: the properties it defines
(owner, repo, ref, instance, repo_path) are listed under each of them.
repopath
pathlib-style, read-only paths for the repository trees of GitHub, GitLab and Gitea.
RepoPath is a path in the repository of a hosting service and GitHubPath,
GitLabPath and GiteaPath are three of its kinds; they read the REST API of
the service and speak no git protocol. They need no URI and no third-party library, so
import repopath needs no extra and never imports uripath. The repo:,
github:, gitlab: and gitea: schemes of uripath are repopath.uri.
RepoPath(*segments, type=None, instance=None, **options)
Bases: TreePath
A path in the repository tree of a hosting service, read-only, over the service's REST API.
RepoPath(*segments, instance=..., type=None, **options) returns a path
of one kind: a GitHubPath, a GitLabPath or a GiteaPath. type names
the kind ("github", "gitlab", "gitea"); without it the kind is detected
from instance (github.com, gitlab.com, codeberg.org), and any other
instance is a ValueError that asks for type=. The segments are the path inside the repository;
the options are those of the kind (owner=, repo=, ref=, token=,
backend=). Every kind is a subclass, so isinstance(path, RepoPath)
holds for all of them; RepoPath.kinds() lists the registered names.
A kind is a subclass whose class body sets TYPE (its name) and
INSTANCES (the instances it is detected for): defining the class
registers it. A name or an instance another class holds is a ValueError
unless the class statement passes replace=True.
A path holds the names below the root of the tree, the tree it is in (the place) and the backend that reaches the service. Nothing connects when a path is built. A path joined from another keeps its place and its backend.
Source code in src/repopath/_kinds.py
181 182 183 184 185 186 187 | |
ALIASES = ()
class-attribute
instance-attribute
INSTANCES = ()
class-attribute
instance-attribute
TYPE = None
class-attribute
instance-attribute
backend
property
The backend that sends the requests of this path.
kind
property
The name of the kind of this path ("github", "gitlab").
is_local()
Whether the tree is on this machine: never. A repository is on a hosting service, so nothing is resolved.
Source code in src/repopath/_kinds.py
319 320 321 322 | |
iterdir()
Source code in src/repopath/_kinds.py
352 353 354 | |
kinds()
staticmethod
The names of the registered kinds, sorted.
Source code in src/repopath/_kinds.py
201 202 203 204 205 | |
GitHubPath(*segments, owner=None, repo=None, ref=None, instance=None, token=None, backend=None)
Bases: HostedRepoPath
A path in a GitHub repository, read-only, through the REST contents API
(GET /repos/{owner}/{repo}/contents/{path}).
GitHubPath("src/mod.py", owner="acme", repo="widgets", ref="v1.2"); see
HostedRepoPath for the keywords. The default instance is github.com
(API at api.github.com); any other is GitHub Enterprise (API at
https://{instance}/api/v3). File bodies are fetched with the raw media
type (skips base64 and its ~1MB inline-content cap) instead of the default
JSON+base64 envelope. A symlink or submodule tree entry is treated as a
plain file. No mtime (would need a separate commits-history call per
path). Needs no third-party library.
Source code in src/repopath/_hosted.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
DEFAULT_INSTANCE = 'github.com'
class-attribute
instance-attribute
INSTANCES = ('github.com', 'www.github.com')
class-attribute
instance-attribute
TYPE = 'github'
class-attribute
instance-attribute
instance
property
The host (and port) of the service, as given.
ref
property
The branch, tag or commit this path reads, or None for the default branch of the repository.
repo
property
The name of the repository.
repo_owner
property
The user, organization or group path that owns the repository.
repo_path
property
The path inside the repository, with no leading or trailing /.
as_uri()
The <kind>://instance/owner/repo/path URI of this path, with
?ref= when it has a ref. It names no token.
Source code in src/repopath/_hosted.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
stat(*, follow_symlinks=True)
Source code in src/repopath/_github.py
123 124 125 126 127 128 129 130 131 132 133 134 | |
GitLabPath(*segments, owner=None, repo=None, ref=None, instance=None, token=None, backend=None)
Bases: HostedRepoPath
A path in a GitLab project's repository, read-only, through the REST
API v4 (the project is the URL-encoded owner/repo).
GitLabPath("src/mod.py", owner="acme", repo="widgets", ref="v1.2"); see
HostedRepoPath for the keywords. A project in a subgroup has the group
path as its owner: owner="acme/team", repo="widgets". The default
instance is gitlab.com; a self-hosted one is just another instance (and
port), always at https://{instance}/api/v4. The tree-listing endpoint
doesn't carry file size, so _scandir() only pre-seeds a stat hint for
tree (directory) entries (size=0 is truthful for a directory, not a
placeholder) -- blob (file) entries get a real stat() lazily instead of
guessing a size that could poison a caller trusting the hint. No mtime.
Needs no third-party library.
Source code in src/repopath/_hosted.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
DEFAULT_INSTANCE = 'gitlab.com'
class-attribute
instance-attribute
INSTANCES = ('gitlab.com', 'www.gitlab.com')
class-attribute
instance-attribute
OWNER_NESTS = True
class-attribute
instance-attribute
TYPE = 'gitlab'
class-attribute
instance-attribute
instance
property
The host (and port) of the service, as given.
ref
property
The branch, tag or commit this path reads, or None for the default branch of the repository.
repo
property
The name of the repository.
repo_owner
property
The user, organization or group path that owns the repository.
repo_path
property
The path inside the repository, with no leading or trailing /.
as_uri()
The <kind>://instance/owner/repo/path URI of this path, with
?ref= when it has a ref. It names no token.
Source code in src/repopath/_hosted.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
stat(*, follow_symlinks=True)
Source code in src/repopath/_gitlab.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
GiteaPath(*segments, owner=None, repo=None, ref=None, instance=None, token=None, backend=None)
Bases: HostedRepoPath
A path in a repository on Gitea or Forgejo (Codeberg runs Forgejo),
read-only, through the REST API under /api/v1.
GiteaPath("src/mod.py", owner="acme", repo="widgets", ref="v1.2",
instance="git.example"); see HostedRepoPath for the keywords. The
default instance is codeberg.org; any other is a self-hosted one, always
at https://{instance}/api/v1. Directories are read through the Git Trees
API in pages of 1,000 (the contents API answers a large directory whole and
slowly), file bodies through the raw route. A symbolic link is a file
whose bytes are its target; a submodule is an empty directory; a file kept
in Git LFS reads as the pointer Git holds, which is the size stat()
states. No mtime. A private repository and a missing one both answer 404.
Needs no third-party library.
Source code in src/repopath/_hosted.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
ALIASES = ('forgejo',)
class-attribute
instance-attribute
DEFAULT_INSTANCE = 'codeberg.org'
class-attribute
instance-attribute
INSTANCES = ('codeberg.org',)
class-attribute
instance-attribute
TYPE = 'gitea'
class-attribute
instance-attribute
instance
property
The host (and port) of the service, as given.
ref
property
The branch, tag or commit this path reads, or None for the default branch of the repository.
repo
property
The name of the repository.
repo_owner
property
The user, organization or group path that owns the repository.
repo_path
property
The path inside the repository, with no leading or trailing /.
as_uri()
The <kind>://instance/owner/repo/path URI of this path, with
?ref= when it has a ref. It names no token.
Source code in src/repopath/_hosted.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
stat(*, follow_symlinks=True)
Source code in src/repopath/_gitea.py
155 156 157 158 159 160 161 162 163 164 165 166 | |
SVNPath(*segments, instance=None, ref=None, username=None, password=None, token=None, backend=None)
Bases: RepoPath
A path in a Subversion repository read over HTTP (mod_dav_svn),
read-only.
SVNPath("trunk/README", instance="https://svn.example.org/repos/project",
ref=1234): instance is the URL of the tree the names are relative to,
normally the root of the repository; ref is a revision number (the head
when omitted, which can move between two requests). stat() is one
PROPFIND, a listing is one PROPFIND with Depth: 1, and the digests
of checksum() come with the stat, without reading the file. A link is a
file whose text is link TARGET: readlink() reads it, and a path that
follows links follows the last name only. username= and password= send
Authorization: Basic, token= a bearer token; backend= shares a
backend between paths.
Source code in src/repopath/_svn.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
INSTANCES = ()
class-attribute
instance-attribute
TYPE = 'svn'
class-attribute
instance-attribute
instance
property
The URL the names are relative to, with no trailing /.
ref
property
The revision this path reads, as text, or None for the head.
repo_path
property
The path below instance, with no leading or trailing /.
as_uri()
svn+https://host/path/to/root/names?ref=REV: the URL of the
instance with the scheme prefixed by svn+, and ?ref= when the path
has a revision. It names no credential.
Source code in src/repopath/_svn.py
232 233 234 235 236 237 238 239 240 241 242 243 244 | |
checksum(algorithm='md5')
The md5 or sha1 digest of the file as the server states it,
without reading the file. A link and any other algorithm raise
NotImplementedError: the stored text of a link is not what a read
returns.
Source code in src/repopath/_svn.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
readlink()
Source code in src/repopath/_svn.py
471 472 473 474 | |
stat(*, follow_symlinks=True)
Source code in src/repopath/_svn.py
466 467 468 469 | |
supported_checksums()
Source code in src/repopath/_svn.py
510 511 | |
SourceForgePath(*segments, project=None, mount=None, ref=None, instance=None, backend=None)
Bases: SVNPath
A path in the Subversion tool of a SourceForge project, read-only.
SourceForgePath("README", project="docutils") asks
https://sourceforge.net/rest/p/docutils/code/ once per backend for the
kind of the tool at mount ("code" unless given) and for the URL it is
served at, and is then an SVNPath on that URL: the names are relative to
the URL SourceForge gives for a checkout (the trunk of the project). A
tool that is not Subversion is NotImplementedError naming its kind, and
a project or tool that does not exist is FileNotFoundError. The reads
are anonymous; backend= shares a backend between paths.
Source code in src/repopath/_sourceforge.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
INSTANCES = (_DEFAULT_INSTANCE, 'www.' + _DEFAULT_INSTANCE)
class-attribute
instance-attribute
TYPE = 'sourceforge'
class-attribute
instance-attribute
instance
property
The host of the site, as given.
mount
property
The mount point of the tool in the project (code by default).
project
property
The name of the project.
ref
property
The revision this path reads, as text, or None for the head.
repo_path
property
The path below instance, with no leading or trailing /.
as_uri()
sourceforge://PROJECT/names, with ?mount=, ?ref= and
?instance= for what is not the default.
Source code in src/repopath/_sourceforge.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
RepoBackend(token=None, session=None, api_base=None, *, transport=None, headers=None, timeout=DEFAULT_TIMEOUT, auth=None, **requests_args)
Bases: HTTPClient, BaseRepoBackend
The transport and the optional bearer token sent on every request.
Unauthenticated works fine for public repositories, subject to the host's
anonymous rate limit (60 requests an hour for github.com). A context
manager: leaving the block closes a transport the backend built.
transport is any object with a send() method as
pathapi.http.HTTPTransport.send(); without one the built-in
HTTPTransport is built on first use. session= (a requests.Session)
and requests_args (verify=, proxies=, ...) select the requests
transport of pathapi-requests; without it they raise ImportError.
headers go with every request, under the request's own. api_base, when
set, overrides the API root a path derives from its instance entirely
(e.g. https://api.github.com or https://{host}/api/v3) -- the seam a
test fake, or a reverse-proxied self-hosted setup, plugs into, since the
derived root is always https; a request that carries an Authorization
header to a plain http:// URL on a host other than loopback warns
(InsecureTransportWarning). Every request gets
timeout=DEFAULT_TIMEOUT ((10, 60) seconds) unless timeout here or in
the call says otherwise; None waits without limit. A GET follows
redirects, dropping the token when the host changes.
Source code in src/repopath/_backend.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
api_base = api_base.rstrip('/') if api_base else None
instance-attribute
auth = auth
instance-attribute
cache = {}
instance-attribute
token = token or None
instance-attribute
request(method, url, headers=None, params=None, *, data=None, timeout=_UNSET, stream=False, allow_redirects=None)
Source code in src/repopath/_backend.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
BaseRepoBackend
Bases: object
Protocol for issuing an authenticated HTTP request against the REST API
of a hosting service. Subclass this to plug in custom auth or session
handling; RepoBackend is the one that sends through pathapi.http.
A backend may carry an api_base (the API root, replacing the one derived
from the instance of a path) and a cache (a dict, to memoize the default
branch of a repository); a path uses either only when the backend has
one.
request(method, url, headers=None, params=None, **kwargs)
Send one request to the API and return its HTTPResponse.
Source code in src/repopath/_backend.py
129 130 131 | |