diff --git a/README.md b/README.md index e8732d22e32256e05cd45c53c4224adec9bc3212..ac93db47711cdd965aabe7605329f8ac5e73a155 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 2ffb6e7dcadccc7583665e4cd9a737d5d6a6b642..fc7ceb6fd29f3a7acf6517ecc0548d2172075b45 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 16bb62042b6a08f6a5c4da7d377e818d045415f6..04a63413751a67a58dceb908e5b284866cd07269 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 22cff691ff11b0832373c5679f3bae36d56e0eaf..1748bcaba315ee092699862c6170b26b8f497f0a 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";