|
25 | 25 | # Originally by Thomas Heller, started in 2000 or so. |
26 | 26 | import glob |
27 | 27 | import os |
| 28 | +from collections.abc import Iterable |
| 29 | +from pathlib import Path |
28 | 30 | import platform |
29 | 31 | import re |
30 | 32 | import shutil |
31 | 33 | import subprocess |
32 | 34 | import sys |
33 | | -from typing import Union |
| 35 | +from typing import List, Tuple, Union |
34 | 36 | import winreg |
35 | 37 |
|
36 | 38 | # setuptools must be imported before distutils for markh in some python versions. |
@@ -2123,66 +2125,42 @@ def finalize_options(self): |
2123 | 2125 | swig_include_files = "mapilib adsilib".split() |
2124 | 2126 |
|
2125 | 2127 |
|
2126 | | -def findall_files( |
2127 | | - dir: Union[str, os.PathLike], |
2128 | | - include_pattern: Union[re.Pattern, None] = None, |
2129 | | - exclude_pattern: Union[re.Pattern, None] = None, |
2130 | | -): |
2131 | | - """ |
2132 | | - Find all files under 'dir' and return the list of full filenames. |
2133 | | - Filters by `include_pattern` then excludes `exclude_pattern` |
2134 | | -
|
2135 | | - Re-implemented and simplified from `distutils.filelist.findall` |
2136 | | - """ |
2137 | | - files = filter( |
2138 | | - os.path.isfile, |
2139 | | - ( |
2140 | | - os.path.join(base, file) |
2141 | | - for base, dirs, files in os.walk(dir, followlinks=True) |
2142 | | - for file in files |
2143 | | - ), |
2144 | | - ) |
2145 | | - if include_pattern: |
2146 | | - files = filter(include_pattern.search, files) |
2147 | | - if exclude_pattern: |
2148 | | - files = filter(lambda file: not exclude_pattern.search(file), files) |
2149 | | - return files |
2150 | | - |
2151 | | - |
2152 | | -def expand_modules(module_dir: Union[str, os.PathLike[str]]): |
| 2128 | +def expand_modules(module_dir: Union[str, os.PathLike]): |
2153 | 2129 | """Helper to allow our script specifications to include wildcards.""" |
2154 | | - files = findall_files(module_dir, include_pattern=re.compile(r"(?s:[^\\]*\.py)\Z")) |
2155 | | - return [os.path.splitext(name)[0] for name in files] |
| 2130 | + return [ |
| 2131 | + str(path.relative_to(module_dir).with_suffix("")) |
| 2132 | + for path in Path(module_dir).rglob("*.py") |
| 2133 | + ] |
2156 | 2134 |
|
2157 | 2135 |
|
2158 | 2136 | # NOTE: somewhat counter-intuitively, a result list a-la: |
2159 | 2137 | # [('Lib/site-packages\\pythonwin', ('pythonwin/license.txt',)),] |
2160 | 2138 | # will 'do the right thing' in terms of installing licence.txt into |
2161 | 2139 | # 'Lib/site-packages/pythonwin/licence.txt'. We exploit this to |
2162 | 2140 | # get 'com/win32com/whatever' installed to 'win32com/whatever' |
2163 | | -def convert_data_files(files): |
2164 | | - ret = [] |
| 2141 | +def convert_data_files(files: Iterable[str]): |
| 2142 | + ret: List[Tuple[str, Tuple[str]]] = [] |
2165 | 2143 | for file in files: |
2166 | | - file = os.path.normpath(file) |
2167 | 2144 | if file.find("*") >= 0: |
2168 | | - files = findall_files( |
2169 | | - os.path.dirname(file), |
2170 | | - include_pattern=re.compile(f"(?s:{os.path.basename(file)})\\Z"), |
2171 | | - # We never want CVS, .pyc and .pyo |
2172 | | - exclude_pattern=re.compile(r".*\\CVS\\|(?s:[^\\]*\.py[co])\Z)"), |
| 2145 | + files_use = ( |
| 2146 | + str(path) |
| 2147 | + for path in Path(file).parent.rglob(os.path.basename(file)) |
| 2148 | + if path.suffix not in {".pyc", ".pyo"} |
2173 | 2149 | ) |
2174 | | - if not files: |
| 2150 | + # We never want CVS. This is done in a separate step to have the normalized slashes |
| 2151 | + files_use = [file for file in files_use if not "\\CVS\\" in file] |
| 2152 | + if not files_use: |
2175 | 2153 | raise RuntimeError("No files match '%s'" % file) |
2176 | | - files_use = files |
2177 | 2154 | else: |
2178 | 2155 | if not os.path.isfile(file): |
2179 | 2156 | raise RuntimeError("No file '%s'" % file) |
2180 | 2157 | files_use = (file,) |
2181 | 2158 | for fname in files_use: |
2182 | 2159 | path_use = os.path.dirname(fname) |
2183 | | - if path_use.startswith("com/") or path_use.startswith("com\\"): |
| 2160 | + if path_use.startswith("com\\"): |
2184 | 2161 | path_use = path_use[4:] |
2185 | 2162 | ret.append((path_use, (fname,))) |
| 2163 | + print("DEBUG convert_data_files ret:", ret) |
2186 | 2164 | return ret |
2187 | 2165 |
|
2188 | 2166 |
|
@@ -2246,6 +2224,7 @@ def convert_optional_data_files(files): |
2246 | 2224 | ] |
2247 | 2225 |
|
2248 | 2226 | py_modules = expand_modules("win32\\lib") |
| 2227 | +print("DEBUG py_modules:", py_modules) |
2249 | 2228 | ext_modules = ( |
2250 | 2229 | win32_extensions + com_extensions + pythonwin_extensions + other_extensions |
2251 | 2230 | ) |
|
0 commit comments