def objects_from_index(index_json): modules = set() entries = [] for item in index_json: for name in item['name'].split(' '): module = item['module'] entry = soi.DataObjStr(name="{}.{}".format(module, name), domain='hs', role='hsobj', priority='1', uri=item['link'], dispname=name) entries.append(entry) modules.add(module) for mod in modules: entry = soi.DataObjStr(name=mod, domain='hs', role='hsmod', priority='1', uri="{}.html".format(mod.replace('.', '-')), dispname='-') entries.append(entry) return entries
def test_sphinx_import(workdir): """Ensure that the sphinx importer imports links correctly""" filepath = str(pathlib.Path(workdir.name, "sphinx.db")) inv = soi.Inventory() inv.project = "Python" inv.version = "1.0" inv.objects.append( soi.DataObjStr( name="print", domain="py", priority="1", role="function", uri="builtins.html#$", dispname="-", )) inv.objects.append( soi.DataObjStr( name="enumeration", domain="py", priority="1", role="label", uri="concepts.html#$", dispname="Enumeration", )) with mock.patch("llyfrau.importers.soi.Inventory", return_value=inv) as m_inv: sphinx(filepath, "https://docs.python.org/") m_inv.assert_called_with(url="https://docs.python.org/objects.inv") db = Database(filepath) source = Source.search(db, name="Python v1.0")[0] assert source.name == "Python v1.0 Documentation" assert source.prefix == "https://docs.python.org/" links = Link.search(db, source=source) assert links[0].name == "print" assert links[0].url == "builtins.html#print" assert {t.name for t in links[0].tags} == {"sphinx", "py", "function"} assert links[1].name == "Enumeration" assert links[1].url == "concepts.html#enumeration" assert {t.name for t in links[1].tags} == {"sphinx", "py", "label"}
def test_sphinx_import_complete_url(workdir): """Ensure that if the importer is called with a complete objects.inv url it is used as is. """ filepath = str(pathlib.Path(workdir.name, "sphinx.db")) inv = soi.Inventory() inv.project = "Example" inv.version = "1.0" inv.objects.append( soi.DataObjStr( name="foo", domain="py", priority="1", role="function", uri="foo.html", dispname="-", )) with mock.patch("llyfrau.importers.soi.Inventory", return_value=inv) as m_inv: sphinx(filepath, "https://docs.python.org/3/objects.inv") m_inv.assert_called_with(url="https://docs.python.org/3/objects.inv")
def add_to_inventory(inv, symbol, common_url): name = symbol["name"] uri = symbol["url"].replace(common_url, "") role = symbol["role"] # Intersphinx has no "package" role, we convert it to "module" -> :py:module:`tf.keras` if role == "package": role = "module" print(name, uri, role) inv.objects.append( soi.DataObjStr( uri=uri, name=name, domain="py", role=role, priority="1", dispname=name ) ) if name.startswith("tf."): other_name = "tensorflow." + name[3:] inv.objects.append( soi.DataObjStr( uri=uri, name=other_name, domain="py", role=role, priority="1", dispname=name, ) ) elif name.startswith("tfp."): other_name = "tensorflow_probability." + name[4:] inv.objects.append( soi.DataObjStr( uri=uri, name=other_name, domain="py", role=role, priority="1", dispname=name, ) )
def add_to_inventory(inv, symbol): common_url = "https://www.tensorflow.org/api_docs/python/" name = symbol["name"] uri = symbol["url"].replace(common_url, "") role = symbol["role"] # Intersphinx has no "package" role, we convert it to "module" -> :py:module:`tf.keras` if role == "pacakage": role = "module" print(name, uri, role) inv.objects.append( soi.DataObjStr( uri=uri, name=name, domain="py", role=role, priority="1", dispname="-" ) )
inv = soi.Inventory() inv.project = "constraint" constraint_object_names = [ "Constraint", "Domain", "Problem", "Solver", "Variable", ] for object_name in constraint_object_names: inv.objects.append( soi.DataObjStr( name=f"{inv.project}.{object_name}", domain="py", role="class", priority="1", uri=f"{inv.project}.{object_name}-class.html", dispname="-", )) text = inv.data_file(contract=True) ztext = soi.compress(text) soi.writebytes("constraint.inv", ztext) # -- General configuration --------------------------------------------------- master_doc = "index.md" source_suffix = { ".ipynb": "myst-nb", ".md": "myst-nb", ".rst": "restructuredtext", }
def test_apifail_dataline_bothargstrue(self, misc_info): """Confirm error raised when both expand and contract are True.""" dos = soi.DataObjStr( **soi.p_data.search(misc_info.str_lines[True]).groupdict()) with pytest.raises(ValueError): dos.data_line(expand=True, contract=True)