Created
May 1, 2018 06:08
-
-
Save ikrima/2c65ccbc1a185b57994eca99e0b638bf to your computer and use it in GitHub Desktop.
generate_python_intellisense.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def gen_intellisense_stubs(): | |
| import pystubgen | |
| import inspect | |
| # This only traverses objects defined in the module | |
| source = pystubgen.make_source(ue) | |
| # Need to manually get freeform functions in module | |
| functions_list = [o[1] for o in inspect.getmembers(ue) if inspect.isroutine(o[1])] | |
| funcDefs = '\n'.join([pystubgen.make_source(funcObj) for funcObj in functions_list]) | |
| # Output | |
| stubFilePath = getScriptsPath() / Path('unreal_engine/__init__.py') | |
| print(os.getcwd()) | |
| if not os.access(str(stubFilePath), os.W_OK): | |
| print(f"p4 edit {str(stubFilePath)}") | |
| os.system(f"p4 edit {str(stubFilePath)} && pause>nul") | |
| with open( str(stubFilePath), 'w', encoding='utf8') as outputFile: | |
| outputFile.write('# Freeform Methods') | |
| outputFile.write(funcDefs) | |
| outputFile.write('\n\n\n') | |
| outputFile.write(source) | |
| def gen_intellisense_stubs_classes(): | |
| class_def_list = [] | |
| for _class in ue.all_classes(): | |
| class_def = [f'class {_class.get_name()}:'] | |
| for function in _class.functions(): | |
| class_def.append(f' def {function}(__unknown_params__):') | |
| class_def.append(f' pass\n') | |
| for _property in _class.properties(): | |
| class_def.append(f' {_property} = "__unknown__"\n') | |
| class_def_list.append('\n'.join(class_def)) | |
| stubFilePath = getScriptsPath() / Path('unreal_engine/classes.py') | |
| with open( str(stubFilePath), 'w', encoding='utf8') as outputFile: | |
| outputFile.write('\n'.join(class_def_list)) | |
| BBEditorUtil.Log('Done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment