From cedcc36418503cf2f6b31bae6e2215d878c4761d Mon Sep 17 00:00:00 2001 From: Tom Rothamel Date: Sat, 4 Jan 2025 23:33:41 -0500 Subject: [PATCH] Update .gitignore and .vscode/settings.json when generating pyi files. Also check in some missing pyis. --- .gitignore | 45 ++++++++++++++++++++-- .vscode/settings.json | 66 ++++++++++++++++++++++++-------- scripts/generate_pyi.py | 52 +++++++++++++++++++++++++ scripts/pyi/android/__init__.pyi | 17 ++++++++ scripts/pyi/emscripten.pyi | 7 ++++ scripts/pyi/jnius.pyi | 3 ++ 6 files changed, 171 insertions(+), 19 deletions(-) create mode 100644 scripts/pyi/android/__init__.pyi create mode 100644 scripts/pyi/emscripten.pyi create mode 100644 scripts/pyi/jnius.pyi diff --git a/.gitignore b/.gitignore index d6e3a0269..13a66a459 100644 --- a/.gitignore +++ b/.gitignore @@ -13,12 +13,8 @@ ehthumbs_vista.db # Python related files. *.pyc *.pyo -*.pyi *.egg-info -!/renpy/cslots.pyi -!/renpy/astsupport.pyi - # Editor/tool files. *~ *.bak @@ -137,3 +133,44 @@ CubismSdkForNative-4-*.zip /cg /.vscode/launch.json /.vscode/tasks.json + + +# Pyi Files (generated by scripts/generate_pyi.py) +renpy/audio/filter.pyi +renpy/audio/renpysound.pyi +renpy/display/accelerator.pyi +renpy/display/matrix.pyi +renpy/display/quaternion.pyi +renpy/display/render.pyi +renpy/encryption.pyi +renpy/gl2/gl2draw.pyi +renpy/gl2/gl2mesh.pyi +renpy/gl2/gl2mesh2.pyi +renpy/gl2/gl2mesh3.pyi +renpy/gl2/gl2model.pyi +renpy/gl2/gl2polygon.pyi +renpy/gl2/gl2shader.pyi +renpy/gl2/gl2texture.pyi +renpy/gl2/live2dmodel.pyi +renpy/lexersupport.pyi +renpy/pydict.pyi +renpy/style.pyi +renpy/style.pyi +renpy/styledata/style_activate_functions.pyi +renpy/styledata/style_functions.pyi +renpy/styledata/style_hover_functions.pyi +renpy/styledata/style_idle_functions.pyi +renpy/styledata/style_insensitive_functions.pyi +renpy/styledata/style_selected_activate_functions.pyi +renpy/styledata/style_selected_functions.pyi +renpy/styledata/style_selected_hover_functions.pyi +renpy/styledata/style_selected_idle_functions.pyi +renpy/styledata/style_selected_insensitive_functions.pyi +renpy/styledata/styleclass.pyi +renpy/styledata/stylesets.pyi +renpy/text/ftfont.pyi +renpy/text/hbfont.pyi +renpy/text/textsupport.pyi +renpy/text/texwrap.pyi +renpy/uguu/gl.pyi +renpy/uguu/uguu.pyi diff --git a/.vscode/settings.json b/.vscode/settings.json index 78f488a60..e9a780312 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,16 +1,16 @@ { "files.watcherExclude": { - "**/renpy/0old/**" : true, - "**/renpy/atom/**" : true, - "**/renpy/cubism/**" : true, - "**/renpy/dists/**" : true, - "**/renpy/dl/**" : true, - "**/renpy/doc/**" : true, - "**/renpy/doc-web/**" : true, - "**/renpy/jedit/**" : true, - "**/renpy/renpy*.app/**" : true, - "**/renpy/tmp/**" : true, - "**/renpy/web/**" : true, + "**/renpy/0old/**": true, + "**/renpy/atom/**": true, + "**/renpy/cubism/**": true, + "**/renpy/dists/**": true, + "**/renpy/dl/**": true, + "**/renpy/doc/**": true, + "**/renpy/doc-web/**": true, + "**/renpy/jedit/**": true, + "**/renpy/renpy*.app/**": true, + "**/renpy/tmp/**": true, + "**/renpy/web/**": true }, "files.exclude": { "0old": true, @@ -41,9 +41,45 @@ "web3": true, "**/*.rpa": true, "**/*.rpymc": true, - "**/cache/": true + "**/cache/": true, + "renpy/audio/filter.pyi": true, + "renpy/audio/renpysound.pyi": true, + "renpy/display/accelerator.pyi": true, + "renpy/display/matrix.pyi": true, + "renpy/display/quaternion.pyi": true, + "renpy/display/render.pyi": true, + "renpy/encryption.pyi": true, + "renpy/gl2/gl2draw.pyi": true, + "renpy/gl2/gl2mesh.pyi": true, + "renpy/gl2/gl2mesh2.pyi": true, + "renpy/gl2/gl2mesh3.pyi": true, + "renpy/gl2/gl2model.pyi": true, + "renpy/gl2/gl2polygon.pyi": true, + "renpy/gl2/gl2shader.pyi": true, + "renpy/gl2/gl2texture.pyi": true, + "renpy/gl2/live2dmodel.pyi": true, + "renpy/lexersupport.pyi": true, + "renpy/pydict.pyi": true, + "renpy/style.pyi": true, + "renpy/styledata/style_activate_functions.pyi": true, + "renpy/styledata/style_functions.pyi": true, + "renpy/styledata/style_hover_functions.pyi": true, + "renpy/styledata/style_idle_functions.pyi": true, + "renpy/styledata/style_insensitive_functions.pyi": true, + "renpy/styledata/style_selected_activate_functions.pyi": true, + "renpy/styledata/style_selected_functions.pyi": true, + "renpy/styledata/style_selected_hover_functions.pyi": true, + "renpy/styledata/style_selected_idle_functions.pyi": true, + "renpy/styledata/style_selected_insensitive_functions.pyi": true, + "renpy/styledata/styleclass.pyi": true, + "renpy/styledata/stylesets.pyi": true, + "renpy/text/ftfont.pyi": true, + "renpy/text/hbfont.pyi": true, + "renpy/text/textsupport.pyi": true, + "renpy/text/texwrap.pyi": true, + "renpy/uguu/gl.pyi": true, + "renpy/uguu/uguu.pyi": true }, - "python.languageServer": "Pylance", "python.analysis.typeCheckingMode": "basic", "python.analysis.diagnosticMode": "workspace", @@ -244,5 +280,5 @@ } } ] - }, -} + } +} \ No newline at end of file diff --git a/scripts/generate_pyi.py b/scripts/generate_pyi.py index c7f57b48b..87c52029b 100755 --- a/scripts/generate_pyi.py +++ b/scripts/generate_pyi.py @@ -11,6 +11,7 @@ import pathlib import textwrap import inspect import types +import json ROOT = pathlib.Path(__file__).parent.parent.absolute() sys.path.insert(0, str(ROOT)) @@ -28,6 +29,8 @@ class FakeScript: renpy.game.script = FakeScript() +generated_files = [ ] + def python_signature(o): """ Given a callabale object, try to return a python-style type signature. @@ -270,6 +273,8 @@ def generate_module(module : types.ModuleType, package : bool): generate_namespace(f, "", module) + generated_files.append(fn) + def is_extension(m : types.ModuleType): """ @@ -307,9 +312,49 @@ def should_generate(name, m : Any): return False +def manage_gitignore(): + + gitignore = ROOT / ".gitignore" + + old_lines = gitignore.read_text().split("\n") + new_lines = [ ] + + for l in old_lines: + + if l.endswith(".pyi"): + continue + + new_lines.append(l) + + if l == "# Pyi Files (generated by scripts/generate_pyi.py)": + new_lines.extend(generated_files) + + gitignore.write_text("\n".join(new_lines)) + +def manage_vscode(): + + settings = ROOT / ".vscode" / "settings.json" + + with open(settings) as f: + j = json.load(f) + + files_exclude = j["files.exclude"] + + files_exclude = { k : v for k, v in files_exclude.items() if not k.endswith(".pyi") } + + for i in generated_files: + files_exclude[str(i)] = True + + j["files.exclude"] = files_exclude + + with open(settings, "w") as f: + json.dump(j, f, indent=4) + def main(): + global generated_files + packages = set() for name in tuple(sys.modules): @@ -323,6 +368,13 @@ def main(): generate_module(v, k in packages) + generated_files.sort() + generated_files = [ str(i.relative_to(ROOT)) for i in generated_files ] + generated_files = [ i for i in generated_files if i.startswith("renpy/") ] + + manage_gitignore() + manage_vscode() + for fn in (ROOT / "scripts" / "pyi").glob("**/*.pyi"): dfn = ROOT / "typings" / fn.relative_to(ROOT / "scripts" / "pyi") text = fn.read_text() diff --git a/scripts/pyi/android/__init__.pyi b/scripts/pyi/android/__init__.pyi new file mode 100644 index 000000000..3f06618fe --- /dev/null +++ b/scripts/pyi/android/__init__.pyi @@ -0,0 +1,17 @@ +from typing import Any + +import android.apk + +expansion = android.apk.APK + +def init(): ... + +activity : Any + +def vibrate(s) -> None:... + +def get_dpi() -> int: ... + +def open_url(url : str) -> None: ... + +def wakelock(active : bool) -> None: ... diff --git a/scripts/pyi/emscripten.pyi b/scripts/pyi/emscripten.pyi new file mode 100644 index 000000000..1c41a7db7 --- /dev/null +++ b/scripts/pyi/emscripten.pyi @@ -0,0 +1,7 @@ +def run_script(s) -> None: ... +def run_script_int(s) -> int: ... +def run_script_string(s) -> str: ... + +def sleep(n : float) -> None: ... + +def syncfs() -> None: ... diff --git a/scripts/pyi/jnius.pyi b/scripts/pyi/jnius.pyi new file mode 100644 index 000000000..81d1a572e --- /dev/null +++ b/scripts/pyi/jnius.pyi @@ -0,0 +1,3 @@ +from typing import Any + +def autoclass(name : str) -> Any: ...