From 8ce4d053ceb0861b56305cdd2e001e864b02f9c2 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Mon, 8 Feb 2021 16:47:54 +0100 Subject: Switch from os.path to pathlib.Path, all source changes but tests With this patch, os.path in Shiboken and Pyside will be completely removed from sources. The rest will be done later. Task-number: PYSIDE-1499 Change-Id: Id01782779487ceec62efdd1f32f65beee0234338 Reviewed-by: Friedemann Kleint --- sources/pyside6/PySide6/support/generate_pyi.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'sources/pyside6/PySide6/support/generate_pyi.py') diff --git a/sources/pyside6/PySide6/support/generate_pyi.py b/sources/pyside6/PySide6/support/generate_pyi.py index 8abab35f0..2810d37e5 100644 --- a/sources/pyside6/PySide6/support/generate_pyi.py +++ b/sources/pyside6/PySide6/support/generate_pyi.py @@ -50,13 +50,14 @@ import io import re import subprocess import argparse +from pathlib import Path from contextlib import contextmanager from textwrap import dedent import logging # Make sure not to get .pyc in Python2. -sourcepath = os.path.splitext(__file__)[0] + ".py" +sourcepath = Path(__file__).parent.resolve() / (Path(__file__).stem + ".py") # Can we use forward references? USE_PEP563 = sys.version_info[:2] >= (3, 7) @@ -215,10 +216,10 @@ def generate_pyi(import_name, outpath, options): Generates a .pyi file. """ plainname = import_name.split(".")[-1] - outfilepath = os.path.join(outpath, plainname + ".pyi") + outfilepath = Path(outpath) / (plainname + ".pyi") top = __import__(import_name) obj = getattr(top, plainname) - if not getattr(obj, "__file__", None) or os.path.isdir(obj.__file__): + if not getattr(obj, "__file__", None) or Path(obj.__file__).is_dir(): raise ModuleNotFoundError(f"We do not accept a namespace as module {plainname}") module = sys.modules[import_name] @@ -269,7 +270,8 @@ def generate_all_pyi(outpath, options): ps = os.pathsep if options.sys_path: # make sure to propagate the paths from sys_path to subprocesses - sys_path = [os.path.normpath(_) for _ in options.sys_path] + normpath = lambda x: os.fspath(Path(x).resolve()) + sys_path = [normpath(_) for _ in options.sys_path] sys.path[0:0] = sys_path pypath = ps.join(sys_path) os.environ["PYTHONPATH"] = pypath @@ -285,7 +287,7 @@ def generate_all_pyi(outpath, options): # Perhaps this can be automated? PySide6.support.signature.mapping.USE_PEP563 = USE_PEP563 - outpath = outpath or os.path.dirname(PySide6.__file__) + outpath = Path(outpath) if outpath and os.fspath(outpath) else Path(PySide6.__file__).parent name_list = PySide6.__all__ if options.modules == ["all"] else options.modules errors = ", ".join(set(name_list) - set(PySide6.__all__)) if errors: @@ -316,7 +318,7 @@ if __name__ == "__main__": if options.quiet: logger.setLevel(logging.WARNING) outpath = options.outpath - if outpath and not os.path.exists(outpath): + if outpath and not Path(outpath).exists(): os.makedirs(outpath) logger.info(f"+++ Created path {outpath}") generate_all_pyi(outpath, options=options) -- cgit v1.2.3