MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / main

Function main

py/generate.py:968–1024  ·  view source on GitHub ↗

Main entry point.

(browser_protocol_path, js_protocol_path, output_path)

Source from the content-addressed store, hash-verified

966
967
968def main(browser_protocol_path, js_protocol_path, output_path):
969 """Main entry point."""
970 output_path = Path(output_path).resolve()
971 json_paths = [
972 browser_protocol_path,
973 js_protocol_path,
974 ]
975
976 # Generate util.py
977 util_path = output_path / "util.py"
978 with util_path.open("w") as util_file:
979 util_file.write(UTIL_PY)
980
981 # Remove generated code
982 for subpath in output_path.iterdir():
983 if subpath.is_file() and subpath.name not in ("py.typed", "util.py"):
984 subpath.unlink()
985
986 # Parse domains
987 domains = []
988 for json_path in json_paths:
989 logger.info("Parsing JSON file %s", json_path)
990 domains.extend(parse(json_path, output_path))
991 domains.sort(key=operator.attrgetter("domain"))
992
993 # Patch up CDP errors. It's easier to patch that here than it is to modify
994 # the generator code.
995 # 1. DOM includes an erroneous $ref that refers to itself.
996 # 2. Page includes an event with an extraneous backtick in the description.
997 for domain in domains:
998 if domain.domain == "DOM":
999 for cmd in domain.commands:
1000 if cmd.name == "resolveNode":
1001 # Patch 1
1002 cmd.parameters[1].ref = "BackendNodeId"
1003 elif domain.domain == "Page":
1004 for event in domain.events:
1005 if event.name == "screencastVisibilityChanged":
1006 # Patch 2
1007 event.description = event.description.replace("`", "")
1008
1009 for domain in domains:
1010 logger.info("Generating module: %s → %s.py", domain.domain, domain.module)
1011 module_path = output_path / f"{domain.module}.py"
1012 with module_path.open("w") as module_file:
1013 module_file.write(domain.generate_code())
1014
1015 init_path = output_path / "__init__.py"
1016 generate_init(init_path, domains)
1017
1018 # Not generating the docs as we don't want people to directly
1019 # Use the CDP APIs
1020 # docs_path = here.parent / 'docs' / 'api'
1021 # generate_docs(docs_path, domains)
1022
1023 py_typed_path = output_path / "py.typed"
1024 py_typed_path.touch()
1025

Callers 1

generate.pyFile · 0.70

Calls 7

generate_initFunction · 0.85
resolveMethod · 0.80
parseFunction · 0.70
writeMethod · 0.45
infoMethod · 0.45
generate_codeMethod · 0.45
touchMethod · 0.45

Tested by

no test coverage detected