Skip to content
Snippets Groups Projects
Commit 3e715e4e authored by Daniel de Leng's avatar Daniel de Leng
Browse files

Merge branch 'python12_update' of...

Merge branch 'python12_update' of gitlab.liu.se:starcraft-ai-course/pycommandcenter into python12_update
parents a6f8ede8 52b79a80
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ Key differences: ...@@ -23,7 +23,7 @@ Key differences:
``` python ``` python
import os import os
from library import * from commandcenter import *
class MyAgent(IDABot): class MyAgent(IDABot):
...@@ -95,10 +95,12 @@ Make sure you have mypy installed. This can be done with: ...@@ -95,10 +95,12 @@ Make sure you have mypy installed. This can be done with:
```terminal ```terminal
pip3 install -r requirements.txt 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 ```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. 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 # How to use the library with PyCharm
......
...@@ -13,7 +13,7 @@ import re ...@@ -13,7 +13,7 @@ import re
sys.path.append('build/python-api-src') #Unix sys.path.append('build/python-api-src') #Unix
sys.path.append('build/python-api-src/Release') #Windows sys.path.append('build/python-api-src/Release') #Windows
import library import commandcenter
def update_pyi_with_docstrings(pyi_path): def update_pyi_with_docstrings(pyi_path):
""" """
...@@ -37,17 +37,17 @@ def update_pyi_with_docstrings(pyi_path): ...@@ -37,17 +37,17 @@ def update_pyi_with_docstrings(pyi_path):
new_lines.append(line) new_lines.append(line)
if not line.strip().endswith("ID:"): if not line.strip().endswith("ID:"):
class_name = re.split(r'[\(: ]', line)[1] 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') 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("__"): if func.startswith("__"):
continue 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 known_def[func] = func_docs
else: else:
class_name = re.split(r'[\(: ]', line)[1] 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] docstring = docstring.split("Members:")[0]
new_lines.append(f' """{docstring}"""\n') new_lines.append(f' """{docstring}"""\n')
...@@ -63,7 +63,7 @@ def update_pyi_with_docstrings(pyi_path): ...@@ -63,7 +63,7 @@ def update_pyi_with_docstrings(pyi_path):
continue continue
else: else:
try: 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 if func_name == "create_computer" or func_name == "create_participants": #Special case with indentation
new_lines.append(f'\n """{func_doc}"""\n') new_lines.append(f'\n """{func_doc}"""\n')
else: else:
...@@ -84,6 +84,6 @@ def update_pyi_with_docstrings(pyi_path): ...@@ -84,6 +84,6 @@ def update_pyi_with_docstrings(pyi_path):
# Path to the generated .pyi file # Path to the generated .pyi file
pyi_file_path = 'build/python-api-src/library.pyi' #Unix pyi_file_path = 'build/python-api-src/commandcenter.pyi' #Unix
#pyi_file_path = 'build/python-api-src/Release/library.pyi' #Windows #pyi_file_path = 'build/python-api-src/Release/commandcenter.pyi' #Windows
update_pyi_with_docstrings(pyi_file_path) update_pyi_with_docstrings(pyi_file_path)
...@@ -17,7 +17,7 @@ link_directories(${PROJECT_BINARY_DIR}/cpp-sc2/bin) ...@@ -17,7 +17,7 @@ link_directories(${PROJECT_BINARY_DIR}/cpp-sc2/bin)
add_definitions(-DSC2API) add_definitions(-DSC2API)
# Create the executable. # Create the executable.
pybind11_add_module(library library.cpp library.h ${BOT_SOURCES} ${LIBRARY_SOURCES}) pybind11_add_module(commandcenter library.cpp library.h ${BOT_SOURCES} ${LIBRARY_SOURCES})
target_link_libraries(library PRIVATE target_link_libraries(commandcenter PRIVATE
sc2api sc2lib sc2utils sc2protocol libprotobuf sc2api sc2lib sc2utils sc2protocol libprotobuf
) )
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace py = pybind11; namespace py = pybind11;
PYBIND11_MODULE(library, m) PYBIND11_MODULE(commandcenter, m)
{ {
m.doc() = "Python API for playing Starcraft II"; m.doc() = "Python API for playing Starcraft II";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment