def haddock_inventory(haddock_dir): """Generate a haddock inventory""" # This is a terrible hack, but otherwise the user has to pass it in, # and I'm not sure where they'd get it from index_html_path = os.path.join(haddock_dir, 'index.html') with open(index_html_path) as index_html: # This working right relies on maximul much quite a bit! match = re.search("<title>(.+)-([0-9.]+).*</title>", index_html.read()) if not match: print("Couldn't get the project and version from the html") sys.exit(1) project = match.group(1) version = match.group(2) index_path = os.path.join(haddock_dir, 'doc-index.json') if not os.path.exists(index_path): print("'doc-index.json' not present in Haddock dir") sys.exit(1) with open(index_path) as doc_index: index_json = json.load(doc_index) inv = inventory_from_index(project, version, index_json) text = inv.data_file(contract=True) ztext = soi.compress(text) soi.writebytes(os.path.join(haddock_dir, 'objects.inv'), ztext)
def test_apifail_writebytes_badoutputfile(self, path_fxn, scratch_path, misc_info): """Confirm OSError raised on bad filename (example of read error).""" b_str = b"This is a binary string!" with pytest.raises(OSError): soi.writebytes(path_fxn(scratch_path / misc_info.invalid_filename), b_str)
def main(): inv = soi.Inventory() inv.project = "TensorFlow-Probability" inv.version = "2.0" with open("./tfp_docs_scraper/core_symbols.json") as fp: symbols = json.load(fp) for symbol in symbols: add_to_inventory(inv, symbol) text = inv.data_file(contract=True) ztext = soi.compress(text) soi.writebytes("objects.inv", ztext) print("All done!")
def main( project="TensorFlow", version="2.0", symbols_file="./tf_docs_scraper/core_symbols.json", common_url="https://www.tensorflow.org/api_docs/python/", inv_file="tf2_py_objects.inv", ): inv = soi.Inventory() inv.project = project inv.version = version with open(symbols_file) as fp: symbols = json.load(fp) for symbol in symbols: add_to_inventory(inv, symbol, common_url) text = inv.data_file(contract=True) ztext = soi.compress(text) soi.writebytes(inv_file, ztext) print("All done!")
def test_api_inventory_many_url_imports( testall_inv_path, res_path, scratch_path, misc_info, sphinx_load_test, pytestconfig, ): """Confirm a plethora of .inv files downloads properly via url arg. This test is SLOW, and so does not run by default. Invoke with `--nonloc` to run it; invoke with `--testall` to test over all .inv files in tests/resource. """ fname = testall_inv_path.name scr_fpath = scratch_path / fname # Drop most unless testall if not pytestconfig.getoption("--testall") and fname != "objects_attrs.inv": pytest.skip("'--testall' not specified") # Construct inventories for comparison mch = misc_info.p_inv.match(fname) proj_name = mch.group(1) inv1 = soi.Inventory(str(res_path / fname)) inv2 = soi.Inventory(url=misc_info.remote_url.format(proj_name)) # Test the things assert inv1 == inv2 # Ensure sphinx likes the regenerated inventory data = inv2.data_file() cmp_data = soi.compress(data) soi.writebytes(scr_fpath, cmp_data) sphinx_load_test(scr_fpath)
"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", } # The master toctree document. master_doc = "index" modindex_common_prefix = [ f"{package}.", ]
# URL is the: url_manual_prefix + url_manual_mapping[#id] import os import sphobjinv as soi import urllib.request # Download the objects.inv file urlretrieve = urllib.request.urlretrieve urlretrieve("https://docs.blender.org/manual/en/dev/objects.inv", "objects.inv") # Decode objects.inv inv = soi.Inventory('objects.inv') objects_data = inv.data_file() soi.writebytes('objects.tmp', objects_data) # TODO leave in memory os.remove("objects.inv") # Write the fire filepath = os.path.join("rna_manual_reference.py") file = open(filepath, "w", encoding="utf-8") fw = file.write fw("# Do not edit this file.") fw(" This file is auto generated from rna_manual_reference_updater.py\n\n") fw("import bpy\n\n") fw("if bpy.app.version_cycle in {'rc', 'release'}:\n") fw(" manual_version = '%d.%d' % bpy.app.version[:2]\n") fw("else:\n") fw(" manual_version = 'dev'\n\n") fw("url_manual_prefix = \"https://docs.blender.org/manual/en/\" + manual_version + \"/\"\n\n"