From 52b79a80af09d7c341985866c1f75c32dc9689b9 Mon Sep 17 00:00:00 2001 From: David Warnquist <davwa458@student.liu.se> Date: Tue, 2 Jul 2024 22:17:27 +0200 Subject: [PATCH] Refactor: Changed library name to commandcenter --- README.md | 8 +++++--- generate_pydocs.py | 16 ++++++++-------- python-api-src/CMakeLists.txt | 4 ++-- python-api-src/library.cpp | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e8732d22e..ac93db477 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Key differences: ``` python import os -from library import * +from commandcenter import * class MyAgent(IDABot): @@ -95,10 +95,12 @@ Make sure you have mypy installed. This can be done with: ```terminal pip3 install -r requirements.txt ``` -Navigate to where your library.pyd/so is located then run: +Navigate to where your commandcenter.pyd/so is located then run: ```terminal -stubgen -m library -o . +stubgen -m commandcenter -o . ``` +NOTE: stubgen might not work on windows unless you have an active python venv. + After creating the .pyi file run the generate_pydocs.py file according to the instructions in that file. # How to use the library with PyCharm diff --git a/generate_pydocs.py b/generate_pydocs.py index 2ffb6e7dc..fc7ceb6fd 100644 --- a/generate_pydocs.py +++ b/generate_pydocs.py @@ -13,7 +13,7 @@ import re sys.path.append('build/python-api-src') #Unix sys.path.append('build/python-api-src/Release') #Windows -import library +import commandcenter def update_pyi_with_docstrings(pyi_path): """ @@ -37,17 +37,17 @@ def update_pyi_with_docstrings(pyi_path): new_lines.append(line) if not line.strip().endswith("ID:"): class_name = re.split(r'[\(: ]', line)[1] - docstring = inspect.getdoc(getattr(library, class_name)) + docstring = inspect.getdoc(getattr(commandcenter, class_name)) new_lines.append(f' """{docstring}"""\n') - for func in dir(getattr(library, class_name)): + for func in dir(getattr(commandcenter, class_name)): if func.startswith("__"): continue - func_docs = inspect.getdoc(getattr(getattr(library, class_name), func)) + func_docs = inspect.getdoc(getattr(getattr(commandcenter, class_name), func)) known_def[func] = func_docs else: class_name = re.split(r'[\(: ]', line)[1] - docstring = inspect.getdoc(getattr(library, class_name)) + docstring = inspect.getdoc(getattr(commandcenter, class_name)) docstring = docstring.split("Members:")[0] new_lines.append(f' """{docstring}"""\n') @@ -63,7 +63,7 @@ def update_pyi_with_docstrings(pyi_path): continue else: try: - func_doc = inspect.getdoc(getattr(library, func_name)) + func_doc = inspect.getdoc(getattr(commandcenter, func_name)) if func_name == "create_computer" or func_name == "create_participants": #Special case with indentation new_lines.append(f'\n """{func_doc}"""\n') else: @@ -84,6 +84,6 @@ def update_pyi_with_docstrings(pyi_path): # Path to the generated .pyi file -pyi_file_path = 'build/python-api-src/library.pyi' #Unix -#pyi_file_path = 'build/python-api-src/Release/library.pyi' #Windows +pyi_file_path = 'build/python-api-src/commandcenter.pyi' #Unix +#pyi_file_path = 'build/python-api-src/Release/commandcenter.pyi' #Windows update_pyi_with_docstrings(pyi_file_path) diff --git a/python-api-src/CMakeLists.txt b/python-api-src/CMakeLists.txt index 16bb62042..04a634137 100644 --- a/python-api-src/CMakeLists.txt +++ b/python-api-src/CMakeLists.txt @@ -17,7 +17,7 @@ link_directories(${PROJECT_BINARY_DIR}/cpp-sc2/bin) add_definitions(-DSC2API) # Create the executable. -pybind11_add_module(library library.cpp library.h ${BOT_SOURCES} ${LIBRARY_SOURCES}) -target_link_libraries(library PRIVATE +pybind11_add_module(commandcenter library.cpp library.h ${BOT_SOURCES} ${LIBRARY_SOURCES}) +target_link_libraries(commandcenter PRIVATE sc2api sc2lib sc2utils sc2protocol libprotobuf ) diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 22cff691f..1748bcaba 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -2,7 +2,7 @@ namespace py = pybind11; -PYBIND11_MODULE(library, m) +PYBIND11_MODULE(commandcenter, m) { m.doc() = "Python API for playing Starcraft II"; -- GitLab