def get_sphinx_inventory(url):
    """
    get the sphinx inventory from a url.
    (https://gist.github.com/dahlia/9e3a988a52de6319cd5d)

    Parameters
    ----------

    url : url of the package where find objects.inv file

    Returns
    -------
    
    the inventory : dict

    """
    inv_url = urllib.parse.urljoin(url, 'objects.inv')
    with urllib.request.urlopen(inv_url) as f:
        line = f.readline().rstrip().decode('utf-8')
        if line == '# Sphinx inventory version 1':
            invdata = read_inventory_v1(f, url, urllib.parse.urljoin)
        elif line == '# Sphinx inventory version 2':
            invdata = read_inventory_v2(f, url, urllib.parse.urljoin)
        else:
            raise ValueError(line)
        return invdata
Esempio n. 2
0
def test_read_inventory_v1():
    f = BytesIO(inventory_v1)
    f.readline()
    invdata = read_inventory_v1(f, '/util', posixpath.join)
    assert invdata['py:module']['module'] == \
        ('foo', '1.0', '/util/foo.html#module-module', '-')
    assert invdata['py:class']['module.cls'] == \
        ('foo', '1.0', '/util/foo.html#module.cls', '-')
Esempio n. 3
0
def test_read_inventory_v1():
    f = BytesIO(inventory_v1)
    f.readline()
    invdata = read_inventory_v1(f, '/util', posixpath.join)
    assert invdata['py:module']['module'] == \
        ('foo', '1.0', '/util/foo.html#module-module', '-')
    assert invdata['py:class']['module.cls'] == \
        ('foo', '1.0', '/util/foo.html#module.cls', '-')
Esempio n. 4
0
def get_inventory(url):
    inv_url = urllib.parse.urljoin(url, 'objects.inv')
    with urllib.request.urlopen(inv_url) as f:
        line = f.readline().rstrip().decode('utf-8')
        if line == '# Sphinx inventory version 1':
            invdata = read_inventory_v1(f, url, urllib.parse.urljoin)
        elif line == '# Sphinx inventory version 2':
            invdata = read_inventory_v2(f, url, urllib.parse.urljoin)
        else:
            raise ValueError(line)
        return invdata
Esempio n. 5
0
def get_inventory(url):
    inv_url = urljoin(url, 'objects.inv')
    f = urllib.urlopen(inv_url)
    line = f.readline().rstrip().decode('utf-8')
    if line == '# Sphinx inventory version 1':
        invdata = read_inventory_v1(f, url, urljoin)
    elif line == '# Sphinx inventory version 2':
        invdata = read_inventory_v2(f, url, urljoin)
    else:
        raise ValueError(line)
    return invdata
Esempio n. 6
0
def read_inventory(fp, url):
    """
    Read Sphinx inventory file from URL.
    """
    from sphinx.ext import intersphinx
    join = posixpath.join
    line = fp.readline().rstrip().decode('utf-8')
    if line == '# Sphinx inventory version 1':
        invdata = intersphinx.read_inventory_v1(fp, url, join)
    elif line == '# Sphinx inventory version 2':
        invdata = intersphinx.read_inventory_v2(fp, url, join)
    return invdata
Esempio n. 7
0
def test_read_inventory_v1():
    f = BytesIO(inventory_v1)
    f.readline()
    invdata = read_inventory_v1(f, "/util", posixpath.join)
    assert invdata["py:module"]["module"] == ("foo", "1.0", "/util/foo.html#module-module", "-")
    assert invdata["py:class"]["module.cls"] == ("foo", "1.0", "/util/foo.html#module.cls", "-")