aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/PySide2/support/generate_pyi.py
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside2/PySide2/support/generate_pyi.py')
-rw-r--r--sources/pyside2/PySide2/support/generate_pyi.py43
1 files changed, 41 insertions, 2 deletions
diff --git a/sources/pyside2/PySide2/support/generate_pyi.py b/sources/pyside2/PySide2/support/generate_pyi.py
index f286e34f1..377a53331 100644
--- a/sources/pyside2/PySide2/support/generate_pyi.py
+++ b/sources/pyside2/PySide2/support/generate_pyi.py
@@ -53,6 +53,7 @@ import re
import subprocess
import argparse
import glob
+import math
from contextlib import contextmanager
from textwrap import dedent
import traceback
@@ -183,6 +184,33 @@ def find_imports(text):
return [imp for imp in PySide2.__all__ if imp + "." in text]
+_cache = {}
+
+def check_if_skipable(outfilepath):
+ # A file can be skipped if it exists, and if it's file time is not
+ # older than this script or any of its dependencies.
+ def _do_find_newest_module():
+ newest = 0
+ for obj in sys.modules.values():
+ if getattr(obj, "__file__", None) and os.path.isfile(obj.__file__):
+ sourcepath = os.path.splitext(obj.__file__)[0] + ".py"
+ if os.path.exists(sourcepath):
+ newest = max(os.path.getmtime(sourcepath), newest)
+ return newest
+
+ def find_newest_module():
+ cache_name = "newest_module"
+ if cache_name not in _cache:
+ _cache[cache_name] = _do_find_newest_module()
+ return _cache[cache_name]
+
+ if os.path.exists(outfilepath):
+ stamp = os.path.getmtime(outfilepath)
+ if stamp >= find_newest_module():
+ return True
+ return False
+
+
def generate_pyi(import_name, outpath, options):
"""
Generates a .pyi file.
@@ -198,7 +226,7 @@ def generate_pyi(import_name, outpath, options):
pid = os.getpid()
plainname = import_name.split(".")[-1]
outfilepath = os.path.join(outpath, plainname + ".pyi")
- if options.skip and os.path.exists(outfilepath):
+ if options.skip and check_if_skipable(outfilepath):
logger.debug("{pid}:Skipped existing: {op}"
.format(op=os.path.basename(outfilepath), **locals()))
return -1
@@ -291,7 +319,17 @@ def generate_all_pyi(outpath, options):
valid = check = 0
if not outpath:
outpath = os.path.dirname(PySide2.__file__)
- lockdir = os.path.join(outpath, "generate_pyi.lockfile")
+ lockdir = os.path.join(outpath, "generate_pyi.lockdir")
+
+ pyi_var = "GENERATE_PYI_RECURSE {}".format(math.pi) # should not be set by anybody
+ if not os.environ.get(pyi_var, ""):
+ # To catch a possible crash, we run as a subprocess:
+ os.environ[pyi_var] = "yes"
+ ret = subprocess.call([sys.executable] + sys.argv)
+ if ret and os.path.exists(lockdir):
+ os.rmdir(lockdir)
+ sys.exit(ret)
+ # We are the subprocess. Do the real work.
with single_process(lockdir) as locked:
if locked:
if is_ci:
@@ -343,3 +381,4 @@ if __name__ == "__main__":
else:
parser_run.print_help()
sys.exit(1)
+# eof