1905 print() |
1903 print() |
1906 print("All dependencies ok.") |
1904 print("All dependencies ok.") |
1907 print() |
1905 print() |
1908 |
1906 |
1909 |
1907 |
1910 def __pyName(py_dir, py_file): |
|
1911 """ |
|
1912 Local function to create the Python source file name for the compiled |
|
1913 .ui file. |
|
1914 |
|
1915 @param py_dir suggested name of the directory |
|
1916 @type str |
|
1917 @param py_file suggested name for the compile source file |
|
1918 @type str |
|
1919 @return tuple of directory name and source file name |
|
1920 @rtype tuple of (str, str) |
|
1921 """ |
|
1922 return py_dir, "Ui_{0}".format(py_file) |
|
1923 |
|
1924 |
|
1925 def __compileOneUi(ui_path, mapFunc=None): |
|
1926 """ |
|
1927 Function to compile a single form file to Python code. |
|
1928 |
|
1929 @param ui_path path of the Qt form file |
|
1930 @type str |
|
1931 @param mapFunc function to change directory and/or name of the resulting Python file |
|
1932 (defaults to None) |
|
1933 @type func (optional) |
|
1934 """ |
|
1935 from PyQt6.uic import compileUi # noqa: I102 |
|
1936 |
|
1937 py_dir, py_file = os.path.split(ui_path[:-3] + ".py") |
|
1938 |
|
1939 # Allow the caller to change the name of the .py file or generate |
|
1940 # it in a different directory. |
|
1941 if mapFunc is not None: |
|
1942 py_dir, py_file = mapFunc(py_dir, py_file) |
|
1943 |
|
1944 # Make sure the destination directory exists. |
|
1945 os.makedirs(py_dir, exist_ok=True) |
|
1946 |
|
1947 py_path = os.path.join(py_dir, py_file) |
|
1948 |
|
1949 with open(py_path, "w", encoding="utf-8") as py_file: |
|
1950 compileUi(ui_path, py_file, execute=False, indent=4) |
|
1951 |
|
1952 |
|
1953 def compileUiDir(root, recurse=False, mapFunc=None, workers=1): |
|
1954 """ |
|
1955 Function to compile all Qt form files of a directory or directory tree |
|
1956 to Python code. |
|
1957 |
|
1958 @param root directory to scan for Qt form files (i.e. files ending with '.ui' |
|
1959 @type str |
|
1960 @param recurse flag indicating to recurse into sub-directories (defaults to False) |
|
1961 @type bool (optional) |
|
1962 @param mapFunc function to change directory and/or name of the resulting Python file |
|
1963 (defaults to None) |
|
1964 @type func (optional) |
|
1965 @param workers number of worker processes to be used to compile (defaults to 1) |
|
1966 @type int (optional) |
|
1967 """ |
|
1968 if recurse: |
|
1969 ui_files = [] |
|
1970 for rootDir, _, files in os.walk(root): |
|
1971 ui_files.extend( |
|
1972 os.path.join(rootDir, ui) for ui in files if ui.endswith(".ui") |
|
1973 ) |
|
1974 else: |
|
1975 ui_files = [ |
|
1976 os.path.join(root, ui) |
|
1977 for ui in os.listdir(root) |
|
1978 if os.path.isfile(os.path.join(root, ui) and ui.endswith(".ui")) |
|
1979 ] |
|
1980 |
|
1981 ProcessPoolExecutor = None |
|
1982 if workers != 1: |
|
1983 try: |
|
1984 from concurrent.futures import ProcessPoolExecutor # noqa: I101, I103 |
|
1985 except NotImplementedError: |
|
1986 workers = 1 |
|
1987 |
|
1988 if workers != 1 and ProcessPoolExecutor is not None: |
|
1989 # If workers == 0, let ProcessPoolExecutor determine worker count. |
|
1990 workers = workers or None |
|
1991 with ProcessPoolExecutor(max_workers=workers) as executor: |
|
1992 executor.map( |
|
1993 partial(__compileOneUi, mapFunc=mapFunc), |
|
1994 ui_files, |
|
1995 ) |
|
1996 else: |
|
1997 for ui_file in ui_files: |
|
1998 __compileOneUi(ui_file, mapFunc=mapFunc) |
|
1999 |
|
2000 |
|
2001 def prepareInfoFile(fileName): |
1908 def prepareInfoFile(fileName): |
2002 """ |
1909 """ |
2003 Function to prepare an Info.py file when installing from source. |
1910 Function to prepare an Info.py file when installing from source. |
2004 |
1911 |
2005 @param fileName name of the Python file containing the info |
1912 @param fileName name of the Python file containing the info |
2411 # Create an install info file |
2318 # Create an install info file |
2412 print("Creating an install info file ...", end="", flush=True) |
2319 print("Creating an install info file ...", end="", flush=True) |
2413 createInstallInfo() |
2320 createInstallInfo() |
2414 print(" Done") |
2321 print(" Done") |
2415 |
2322 |
2416 # Compile .ui files |
|
2417 print("Compiling user interface files ...", end="", flush=True) |
|
2418 # step 1: remove old Ui_*.py files |
|
2419 for root, _, files in os.walk(sourceDir): |
|
2420 for file in [f for f in files if fnmatch.fnmatch(f, "Ui_*.py")]: |
|
2421 os.remove(os.path.join(root, file)) |
|
2422 # step 2: compile the forms |
|
2423 compileUiDir(eric7SourceDir, recurse=True, mapFunc=__pyName, workers=0) |
|
2424 print(" Done") |
|
2425 |
|
2426 if doCompile: |
2323 if doCompile: |
2427 print("Compiling source files ...", end="", flush=True) |
2324 print("Compiling source files ...", end="", flush=True) |
2428 skipRe = re.compile(r"DebugClients[\\/]Python[\\/]") |
2325 skipRe = re.compile(r"DebugClients[\\/]Python[\\/]") |
2429 sys.stdout = io.StringIO() |
2326 sys.stdout = io.StringIO() |
2430 if distDir: |
2327 if distDir: |