Mercurial URL Parser - libvcs.parse.hg#

For hg, aka hg(1).

This module is an all-in-one parser and validator for Mercurial URLs.

Note

Do you use Mercurial at your job or project? This module welcomes a champion / maintainer to assure support is top-tier. Stop by the project tracker to make yourself known. We won’t stabilize any APIs until we’re satisfied support is “by the book” and is bullet proofed.

libvcs.parse.hg.DEFAULT_MATCHERS#

Core regular expressions. These are patterns understood by hg(1)

class libvcs.parse.hg.HgURL(url)#

Mercurial repository location. Parses URLs on initialization.

Parameters:

url (str) –

matcher#

name of the Matcher

Type:

str

Examples

>>> HgURL(url='https://hg.mozilla.org/mozilla-central/')
HgURL(url=https://hg.mozilla.org/mozilla-central/,
        scheme=https,
        hostname=hg.mozilla.org,
        path=mozilla-central/,
        matcher=core-hg)
>>> myrepo = HgURL(url='https://hg.mozilla.org/mozilla-central/')
>>> myrepo.hostname
'hg.mozilla.org'
>>> myrepo.path
'mozilla-central/'
>>> HgURL(url='ssh://[email protected]/path/to/repo')
HgURL(url=ssh://[email protected]/path/to/repo,
        scheme=ssh,
        user=username,
        hostname=machinename,
        path=path/to/repo,
        matcher=core-hg)
hostname#
classmethod is_valid(url, is_explicit=False)#

Whether URL is compatible with VCS or not.

Examples

>>> HgURL.is_valid(
...     url='https://hg.mozilla.org/mozilla-central'
... )
True
>>> HgURL.is_valid(url='ssh://[email protected]/cpython')
True
>>> HgURL.is_valid(url='notaurl')
False
Parameters:
  • url (str) –

  • is_explicit (Optional[bool]) –

Return type:

bool

matcher#
matchers#
path#
port#
ref#
scheme#
separator#
to_url()#

Return a hg(1)-compatible URL. Can be used with hg clone.

Examples

>>> hg_url = HgURL(url='https://hg.mozilla.org/mozilla-central')
>>> hg_url
HgURL(url=https://hg.mozilla.org/mozilla-central,
        scheme=https,
        hostname=hg.mozilla.org,
        path=mozilla-central,
        matcher=core-hg)

Switch repo libvcs -> vcspull:

>>> hg_url.path = 'mobile-browser'
>>> hg_url.to_url()
'https://hg.mozilla.org/mobile-browser'

Switch them to localhost:

>>> hg_url.hostname = 'localhost'
>>> hg_url.scheme = 'http'
>>> hg_url.to_url()
'http://localhost/mobile-browser'

Another example, hugin:

>>> hugin = HgURL(url="http://hugin.hg.sourceforge.net:8000/hgroot/hugin/hugin")
>>> hugin
HgURL(url=http://hugin.hg.sourceforge.net:8000/hgroot/hugin/hugin,
        scheme=http,
        hostname=hugin.hg.sourceforge.net,
        port=8000,
        path=hgroot/hugin/hugin,
        matcher=core-hg)
>>> hugin.to_url()
'http://hugin.hg.sourceforge.net:8000/hgroot/hugin/hugin'

SSH URL with a username, graphicsmagic:

>>> graphicsmagick = HgURL(
...     url="ssh://[email protected]//hg/GraphicsMagick"
... )
>>> graphicsmagick
HgURL(url=ssh://[email protected]//hg/GraphicsMagick,
        scheme=ssh,
        user=yourid,
        hostname=hg.GraphicsMagick.org,
        path=/hg/GraphicsMagick,
        matcher=core-hg)
>>> graphicsmagick.to_url()
'ssh://[email protected]//hg/GraphicsMagick'

Switch the username:

>>> graphicsmagick.user = 'lucas'
>>> graphicsmagick.to_url()
'ssh://[email protected]//hg/GraphicsMagick'
Return type:

str

url#
user#
libvcs.parse.hg.PIP_DEFAULT_MATCHERS#

pip-style hg URLs.

Examples of PIP-style hg URLs (via pip.pypa.io):

MyProject @ hg+http://hg.myproject.org/MyProject
MyProject @ hg+https://hg.myproject.org/MyProject
MyProject @ hg+ssh://hg.myproject.org/MyProject
MyProject @ hg+file:///home/user/projects/MyProject

Refs (via pip.pypa.io):

MyProject @ hg+http://hg.example.com/MyProject@da39a3ee5e6b
MyProject @ hg+http://hg.example.com/MyProject@2019
MyProject @ hg+http://hg.example.com/MyProject@v1.0
MyProject @ hg+http://hg.example.com/MyProject@special_feature

Notes

libvcs.parse.hg.RE_PATH =     ((?P<user>\w+)@)?     (?P<hostname>([^/:@]+))     (:(?P<port>\d{1,5}))?     (?P<separator>/)?     (?P<path>       /?(\w[^:.]*)     )? #
libvcs.parse.hg.RE_PIP_SCHEME =     (?P<scheme>       (         hg\+ssh|         hg\+https|         hg\+http|         hg\+file       )     ) #
libvcs.parse.hg.RE_SCHEME =     (?P<scheme>       (         http|https|ssh       )     ) #