Skip to content

Commit 4a165b2

Browse files
committed
url(docs): Add Attributes to Rule and URL parsers
why: Autodoc renders every dataclass field, so the parsed URL fields shipped bare in the API reference. Rule's per-field docstrings also sat one field below what they described, so readers matched "Weight: Higher is more likely to win" to is_explicit. what: - Move Rule's field docstrings into an Attributes section, paired with the field each describes, and cover defaults and weight - Document the parsed fields of GitBaseURL, HgBaseURL, SvnBaseURL, including which sentinel each carries when a rule captures nothing - Document region and rev on GitAWSCodeCommitURL, and rev on the pip URL parsers
1 parent ea86957 commit 4a165b2

4 files changed

Lines changed: 154 additions & 10 deletions

File tree

src/libvcs/url/base.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,32 @@ def is_valid(cls, url: str, is_explicit: bool | None = None) -> bool:
2828

2929
@dataclasses.dataclass(repr=False)
3030
class Rule(SkipDefaultFieldsReprMixin):
31-
"""A Rule represents an eligible pattern mapping to URL."""
31+
"""A Rule represents an eligible pattern mapping to URL.
32+
33+
Attributes
34+
----------
35+
label : str
36+
Computer readable name / ID. Keys the rule inside a
37+
:class:`RuleMap` and is recorded on a matched URL's ``rule``.
38+
description : str
39+
Human readable description of the URL shape the rule covers.
40+
pattern : Pattern[str]
41+
Regex pattern. Its named groups are assigned onto the URL object's
42+
fields of the same name.
43+
defaults : dict[str, str]
44+
Values to apply to fields the pattern left unset, e.g. the
45+
``hostname`` and ``scheme`` a bare prefix such as ``github:`` implies.
46+
is_explicit : bool
47+
Is the match unambiguous with other VCS systems? e.g. git+ prefix
48+
weight : int
49+
Weight: Higher is more likely to win
50+
"""
3251

3352
label: str
34-
"""Computer readable name / ID"""
3553
description: str
36-
"""Human readable description"""
3754
pattern: Pattern[str]
38-
"""Regex pattern"""
3955
defaults: dict[str, str] = dataclasses.field(default_factory=dict)
40-
"""Is the match unambiguous with other VCS systems? e.g. git+ prefix"""
4156
is_explicit: bool = False
42-
"""Weight: Higher is more likely to win"""
4357
weight: int = 0
4458

4559

src/libvcs/url/git.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,32 @@ class GitBaseURL(
294294
):
295295
"""Git repository location. Parses URLs on initialization.
296296
297+
Attributes
298+
----------
299+
url : str
300+
Location as given, kept verbatim. Every other field is filled from it
301+
by the first :class:`~libvcs.url.base.Rule` that matches.
302+
scheme : str | None
303+
Transport scheme, e.g. ``https`` or ``ssh``. ``None`` for scp-style
304+
locations such as ``git@github.com:vcs-python/libvcs.git``, which
305+
carry no scheme.
306+
user : str | None
307+
User in front of the hostname, e.g. ``git``. ``None`` when the URL
308+
omits one; :meth:`to_url` falls back to ``git`` for scp-style output.
309+
hostname : str | None
310+
Server hosting the repository, e.g. ``github.com``.
311+
port : int | None
312+
Port the URL specifies, or ``None`` to use the transport's default.
313+
path : str | None
314+
Server-side path to the repository with the suffix split off, e.g.
315+
``vcs-python/libvcs``.
316+
suffix : str | None
317+
Trailing ``.git`` split off the path, or ``None`` when the URL has
318+
none. :meth:`to_url` re-appends it.
319+
rule : str | None
320+
:attr:`~libvcs.url.base.Rule.label` of the rule that matched, or
321+
``None`` when no rule did and the remaining fields stayed unset.
322+
297323
Examples
298324
--------
299325
>>> GitBaseURL(url='https://github.com/vcs-python/libvcs.git')
@@ -454,7 +480,21 @@ class GitAWSCodeCommitURL(
454480
URLProtocol,
455481
SkipDefaultFieldsReprMixin,
456482
):
457-
"""Supports AWS CodeCommit git URLs."""
483+
"""Supports AWS CodeCommit git URLs.
484+
485+
Parses the fields of :class:`GitBaseURL` plus the two below.
486+
487+
Attributes
488+
----------
489+
region : str | None
490+
AWS region from a ``codecommit::<region>://`` URL, e.g.
491+
``us-east-1``. ``None`` for region-less GRC URLs and for the HTTPS
492+
and SSH forms, which carry the region inside the hostname.
493+
rev : str | None
494+
Commit-ish (tag, branch, ref) trailing the URL as ``@rev``, or
495+
``None`` when the URL names no revision. :meth:`to_url` re-appends
496+
it.
497+
"""
458498

459499
# AWS CodeCommit Region
460500
region: str | None = None
@@ -589,7 +629,17 @@ class GitPipURL(
589629
URLProtocol,
590630
SkipDefaultFieldsReprMixin,
591631
):
592-
"""Supports pip git URLs."""
632+
"""Supports pip git URLs.
633+
634+
Parses the fields of :class:`GitBaseURL` plus the one below.
635+
636+
Attributes
637+
----------
638+
rev : str | None
639+
Commit-ish (tag, branch, ref) from a pip-style ``@rev``, e.g.
640+
``v0.10.0``. ``None`` when the URL names no revision.
641+
:meth:`to_url` re-appends it.
642+
"""
593643

594644
# commit-ish (rev): tag, branch, ref
595645
rev: str | None = None

src/libvcs/url/hg.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,38 @@ class HgBaseURL(
154154
):
155155
"""Mercurial repository location. Parses URLs on initialization.
156156
157+
Attributes
158+
----------
159+
url : str
160+
Location as given, kept verbatim. Every other field is filled from it
161+
by the first :class:`~libvcs.url.base.Rule` that matches.
162+
scheme : str | None
163+
Transport scheme, e.g. ``https``, ``ssh``, or ``hg+file``. ``None``
164+
when the matched rule captured none.
165+
user : str | None
166+
User in front of the hostname, e.g. ``hg``. ``None`` when the URL
167+
omits one; :meth:`to_url` falls back to ``hg`` for scp-style output.
168+
hostname : str
169+
Server hosting the repository, e.g. ``hg.mozilla.org``. Empty when
170+
the matched rule captures no host, as with ``hg+file://`` URLs.
171+
port : int | None
172+
Port the URL specifies, or ``None`` to use the transport's default.
173+
separator : str
174+
Character sitting between the host (and port) and the path, ``/``
175+
unless the URL used ``:`` or ``,``. :meth:`to_url` re-emits it.
176+
path : str
177+
Server-side path to the repository, e.g. ``mozilla-central/``. Empty
178+
when the URL carries no path.
179+
suffix : str | None
180+
Trailing ``.git``-style decoration split off the path, or ``None``
181+
when the URL has none.
182+
ref : str | None
183+
Commit-ish (tag, branch, ref, revision) for callers to set; the
184+
bundled rules capture no ref, so parsing leaves it ``None``.
185+
rule : str | None
186+
:attr:`~libvcs.url.base.Rule.label` of the rule that matched, or
187+
``None`` when no rule did and the remaining fields stayed unset.
188+
157189
Examples
158190
--------
159191
>>> HgBaseURL(url='https://hg.mozilla.org/mozilla-central/')
@@ -341,7 +373,16 @@ class HgPipURL(
341373
URLProtocol,
342374
SkipDefaultFieldsReprMixin,
343375
):
344-
"""Supports pip hg URLs."""
376+
"""Supports pip hg URLs.
377+
378+
Parses the fields of :class:`HgBaseURL` plus the one below.
379+
380+
Attributes
381+
----------
382+
rev : str | None
383+
Commit-ish (tag, branch, ref) from a pip-style ``@rev``, e.g.
384+
``v1.0``. ``None`` when the URL names no revision.
385+
"""
345386

346387
# commit-ish (rev): tag, branch, ref
347388
rev: str | None = None

src/libvcs/url/svn.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,36 @@ class SvnBaseURL(
150150
):
151151
"""SVN repository location. Parses URLs on initialization.
152152
153+
Attributes
154+
----------
155+
url : str
156+
Location as given, kept verbatim. Every other field is filled from it
157+
by the first :class:`~libvcs.url.base.Rule` that matches.
158+
scheme : str | None
159+
Transport scheme, e.g. ``https``, ``svn+ssh``, or ``svn+file``.
160+
``None`` for scp-style locations, which carry no scheme.
161+
user : str | None
162+
User in front of the hostname, e.g. ``svn``. ``None`` when the URL
163+
omits one.
164+
hostname : str
165+
Server hosting the repository, e.g. ``svn.debian.org``. Empty when
166+
the matched rule captures no host, as with ``svn+file://`` URLs.
167+
port : int | None
168+
Port the URL specifies, or ``None`` to use the transport's default.
169+
separator : str
170+
Character sitting between the host (and port) and the path, ``/``
171+
unless the URL used ``:`` or ``,``. :meth:`to_url` re-emits it.
172+
path : str
173+
Server-side path to the repository, e.g.
174+
``svn/aliothproj/path/in/project``. Empty when the URL carries no
175+
path.
176+
ref : str | None
177+
Commit-ish (tag, branch, revision) for callers to set; the bundled
178+
rules capture no ref, so parsing leaves it ``None``.
179+
rule : str | None
180+
:attr:`~libvcs.url.base.Rule.label` of the rule that matched, or
181+
``None`` when no rule did and the remaining fields stayed unset.
182+
153183
Examples
154184
--------
155185
>>> SvnBaseURL(
@@ -279,7 +309,16 @@ class SvnPipURL(
279309
URLProtocol,
280310
SkipDefaultFieldsReprMixin,
281311
):
282-
"""Supports pip svn URLs."""
312+
"""Supports pip svn URLs.
313+
314+
Parses the fields of :class:`SvnBaseURL` plus the one below.
315+
316+
Attributes
317+
----------
318+
rev : str | None
319+
Commit-ish (tag, branch, revision) from a pip-style ``@rev``, e.g.
320+
``2019``. ``None`` when the URL names no revision.
321+
"""
283322

284323
# commit-ish (rev): tag, branch, ref
285324
rev: str | None = None

0 commit comments

Comments
 (0)