|
| 1 | +(parse)= |
| 2 | + |
| 3 | +# Parser - `libvcs.parse` |
| 4 | + |
| 5 | +VCS URL parser for python. |
| 6 | + |
| 7 | +## Parsing capabilities |
| 8 | + |
| 9 | +:::{warning} |
| 10 | + |
| 11 | +The APIs and structures themselves are still unstable APIs. If you are missing a field or use case, |
| 12 | +please file an issue. |
| 13 | + |
| 14 | +::: |
| 15 | + |
| 16 | +1. Detect VCS URLs |
| 17 | + |
| 18 | + - git: {meth}`libvcs.parse.git.GitURL.is_valid()` |
| 19 | + - hg: {meth}`libvcs.parse.hg.HgURL.is_valid()` |
| 20 | + - svn: {meth}`libvcs.parse.svn.SvnURL.is_valid()` |
| 21 | + |
| 22 | +- Parse results of URL to a structure |
| 23 | + |
| 24 | + _Compare to {class}`urllib.parse.ParseResult`_ |
| 25 | + |
| 26 | + - {class}`libvcs.parse.git.GitURL` |
| 27 | + - {class}`libvcs.parse.hg.HgURL` |
| 28 | + - {class}`libvcs.parse.svn.SvnURL` |
| 29 | + |
| 30 | +3. Convert input VCS to _usable_ URLs |
| 31 | + |
| 32 | + - git: {meth}`libvcs.parse.git.GitURL.to_url()` |
| 33 | + - hg: {meth}`libvcs.parse.hg.HgURL.to_url()` |
| 34 | + - svn: {meth}`libvcs.parse.svn.SvnURL.to_url()` |
| 35 | + |
| 36 | + `pip` knows what a certain URL string means, but `git clone` won't. |
| 37 | + |
| 38 | + e.g. `pip install git+https://github.com/django/django.git@3.2` works great with `pip`. |
| 39 | + |
| 40 | + ```console |
| 41 | + $ pip install git+https://github.com/django/django.git@3.2 |
| 42 | + ... |
| 43 | + Successfully installed Django-3.2 |
| 44 | + |
| 45 | + ``` |
| 46 | + |
| 47 | + but `git clone` can't use that: |
| 48 | + |
| 49 | + ```console |
| 50 | + $ git clone git+https://github.com/django/django.git@3.2 # Fail |
| 51 | + ... |
| 52 | + Cloning into django.git@3.2''...' |
| 53 | + git: 'remote-git+https' is not a git command. See 'git --help'. |
| 54 | + ``` |
| 55 | + |
| 56 | + It needs something like this: |
| 57 | + |
| 58 | + ```console |
| 59 | + $ git clone https://github.com/django/django.git --branch 3.2 |
| 60 | + ``` |
| 61 | + |
| 62 | + But before we get there, we don't know if we want a URL yet. We return a structure, e.g. |
| 63 | + `GitURL`. |
| 64 | + |
| 65 | +- Common result primitives across VCS, e.g. `GitURL`. |
| 66 | + |
| 67 | + Compare to a {class}`urllib.parse.ParseResult` in `urlparse` |
| 68 | + |
| 69 | + This is where fun can happen, or you can just parse a URL. |
| 70 | + |
| 71 | +- Allow mutating / replacing parse of a vcs (e.g. just the hostname) |
| 72 | +- Support common cases with popular VCS systems |
| 73 | +- Support extending parsing for users needing to do so |
| 74 | + |
| 75 | +## Scope |
| 76 | + |
| 77 | +### Out of the box |
| 78 | + |
| 79 | +The ambition for this is to build extendable parsers for package-like URLs, e.g. |
| 80 | + |
| 81 | +- Vanilla VCS URLs |
| 82 | + |
| 83 | + - any URL supported by the VCS binary, e.g. `git(1)`, `svn(1)`, `hg(1)`. |
| 84 | + |
| 85 | +- [pip]-style urls [^pip-url] |
| 86 | + - branches |
| 87 | + - tags |
| 88 | +- [NPM]-style urls[^npm-url] |
| 89 | + - branches |
| 90 | + - tags |
| 91 | + |
| 92 | +[pip]: https://pip.pypa.io/en/stable/ |
| 93 | + |
| 94 | +[^pip-url]: PIP-style URLs |
| 95 | + |
| 96 | + https://pip.pypa.io/en/stable/topics/vcs-support/ |
| 97 | + |
| 98 | +[npm]: https://docs.npmjs.com/ |
| 99 | + |
| 100 | +[^npm-url]: NPM style URLs |
| 101 | + |
| 102 | + https://docs.npmjs.com/about-packages-and-modules#npm-package-git-url-formats |
| 103 | + |
| 104 | +### Extendability |
| 105 | + |
| 106 | +Patterns can be registered. [Similar behavior](https://stackoverflow.com/a/6264214/1396928) exists |
| 107 | +in {mod}`urlparse` (undocumented). |
| 108 | + |
| 109 | +- Any formats not covered by the stock |
| 110 | +- Custom urls |
| 111 | + |
| 112 | + - For orgs on , e.g: |
| 113 | + |
| 114 | + - `python:mypy` -> `git@github.com:python/mypy.git` |
| 115 | + - `inkscape:inkscape` -> `git@gitlab.com:inkscape/inkscape.git` |
| 116 | + |
| 117 | + - For out of domain trackers, e.g. |
| 118 | + |
| 119 | + Direct to site: |
| 120 | + |
| 121 | + - `cb:python-vcs/libtmux` -> `https://codeberg.org/vcs-python/libvcs` |
| 122 | + - `kde:plasma/plasma-sdk` -> `git@invent.kde.org:plasma/plasma-sdk.git` |
| 123 | + |
| 124 | + Aside: Note [KDE's git docs] use of [`url.<base>.insteadOf`] and [`url.<base>.pushInsteadOf`] |
| 125 | + |
| 126 | + Direct to site + org / group: |
| 127 | + |
| 128 | + - `gnome:gedit` -> `git@gitlab.gnome.org:GNOME/gedit.git` |
| 129 | + - `openstack:openstack` -> `https://opendev.org/openstack/openstack.git` |
| 130 | + - `mozilla:central` -> `https://hg.mozilla.org/mozilla-central/` |
| 131 | + |
| 132 | +[kde's git docs]: https://community.kde.org/Infrastructure/Git#Pushing |
| 133 | +[`url.<base>.insteadof`]: |
| 134 | + https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf |
| 135 | +[`url.<base>.pushinsteadof`]: |
| 136 | + https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtpushInsteadOf |
| 137 | + |
| 138 | +From there, `GitURL` can be used downstream directly by other projects. |
| 139 | + |
| 140 | +In our case, `libvcs`s' own {ref}`cmd` and {ref}`projects`, as well as a {ref}`vcspull:index` |
| 141 | +configuration, will be able to detect and accept various URL patterns. |
| 142 | + |
| 143 | +## Location objects |
| 144 | + |
| 145 | +Compare to {class}`urllib.parse.ParseResult`. These are structures that break the VCS location into |
| 146 | +parse so they can be filled, replaced [^api-unstable], and exported into a URL specifier compatible |
| 147 | +with the VCS. |
| 148 | + |
| 149 | +[^api-unstable]: Provisional API only |
| 150 | + |
| 151 | + It's not determined if Location will be mutable or if modifications will return a new object. |
| 152 | + |
| 153 | +## Explore |
| 154 | + |
| 155 | +```{toctree} |
| 156 | +:caption: API |
| 157 | +
|
| 158 | +git |
| 159 | +svn |
| 160 | +hg |
| 161 | +base |
| 162 | +``` |
0 commit comments