diff --git a/generate_pydocs.py b/generate_pydocs.py index ab6bfca8aa13a49f67614b5bc2686d4a1a1fd279..2ffb6e7dcadccc7583665e4cd9a737d5d6a6b642 100644 --- a/generate_pydocs.py +++ b/generate_pydocs.py @@ -3,8 +3,7 @@ This file inserts the docs of each class and method into the pyi file for autoco Before running make sure you have created the pyi according to the README. You might need to change the pyi_path. Then simply run this file. -After running all the docs should have been inserted but YOU'RE NOT DONE YET. -You need to fix the intedention at the two bottom function of the pyi file. +After running all the docs should have been inserted. Now you're done and can enjoy working autocompletion of this library. """ @@ -45,6 +44,12 @@ def update_pyi_with_docstrings(pyi_path): continue func_docs = inspect.getdoc(getattr(getattr(library, class_name), func)) known_def[func] = func_docs + + else: + class_name = re.split(r'[\(: ]', line)[1] + docstring = inspect.getdoc(getattr(library, class_name)) + docstring = docstring.split("Members:")[0] + new_lines.append(f' """{docstring}"""\n') elif line.strip().startswith('def '): new_lines.append(line[:-4]) @@ -59,7 +64,10 @@ def update_pyi_with_docstrings(pyi_path): else: try: func_doc = inspect.getdoc(getattr(library, func_name)) - new_lines.append(f'\n """{func_doc}"""\n') + if func_name == "create_computer" or func_name == "create_participants": #Special case with indentation + new_lines.append(f'\n """{func_doc}"""\n') + else: + new_lines.append(f'\n """{func_doc}"""\n') new_lines.append(f' {line[-4:]}') continue except AttributeError: diff --git a/python-api-src/lib_tech_tree.cpp b/python-api-src/lib_tech_tree.cpp index 096629189782cdd016eb9ee68de454f860995fc4..b982844682e7bbb31159836d5c35411ff247cf8a 100644 --- a/python-api-src/lib_tech_tree.cpp +++ b/python-api-src/lib_tech_tree.cpp @@ -10,19 +10,22 @@ void define_tech_tree(py::module & m) .def_readonly("gas_cost", &TypeData::gasCost, "gas cost of the item") .def_readonly("supply_cost", &TypeData::supplyCost, "supply cost of the item") .def_readonly("build_time", &TypeData::buildTime, "build time of the item in seconds (should be 32 game updates per tick, can someone verify this?)") - .def_readonly("is_unit", &TypeData::isUnit) - .def_readonly("is_building", &TypeData::isBuilding) - .def_readonly("is_worker", &TypeData::isWorker) - .def_readonly("is_refinery", &TypeData::isRefinery) - .def_readonly("is_supply_provider", &TypeData::isSupplyProvider) - .def_readonly("is_resource_depot", &TypeData::isResourceDepot) - .def_readonly("is_addon", &TypeData::isAddon) + .def_readonly("is_unit", &TypeData::isUnit, "is the item a unit") + .def_readonly("is_building", &TypeData::isBuilding, "is the item a building") + .def_readonly("is_worker", &TypeData::isWorker, "is the item a worker") + .def_readonly("is_refinery", &TypeData::isRefinery, "is the item a refinery") + .def_readonly("is_supply_provider", &TypeData::isSupplyProvider, "is the item a supply provider") + .def_readonly("is_resource_depot", &TypeData::isResourceDepot, "is the item a resource depot") + .def_readonly("is_addon", &TypeData::isAddon, "is the item an addon") .def_readonly("build_ability", &TypeData::buildAbility, "the ability that creates this item") .def_readonly("warp_ability", &TypeData::warpAbility, "the ability that creates this item via warp-in") .def_readonly("what_builds", &TypeData::whatBuilds, "any of these units can build the item") .def_readonly("required_units", &TypeData::requiredUnits, "owning ONE of these is required to make -> List[UnitType]") .def_readonly("required_upgrades", &TypeData::requiredUpgrades, "having ALL of these is required to make -> List[UPGRADE_ID]") - .def_readonly("required_addons", &TypeData::requiredAddons, "a unit of this type must be present next to the producer -> List[UnitType]"); + .def_readonly("required_addons", &TypeData::requiredAddons, "a unit of this type must be present next to the producer -> List[UnitType]") + .doc() = R"( + Allows you to get information about a unit type or upgrade. This is a read-only class. + )"; py::class_<TechTree>(m, "TechTree") .def("get_data", py::overload_cast<const UnitType &>(&TechTree::getData, py::const_))