Skip to content

Commit

Permalink
Replace distutils.FileList with pathlib (#2138)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Nov 1, 2023
1 parent 22efab5 commit 378fcb7
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
from distutils.command.install_data import install_data
from distutils.command.install_lib import install_lib
from distutils.core import Extension
from pathlib import Path
from tempfile import gettempdir
from typing import Iterable, List, Tuple, Union


# some modules need a static CRT to avoid problems caused by them having a
# manifest.
Expand All @@ -52,7 +55,6 @@

import distutils.util
from distutils.dep_util import newer_group
from distutils.filelist import FileList

build_id_patch = build_id
if not "." in build_id_patch:
Expand Down Expand Up @@ -2122,41 +2124,36 @@ def finalize_options(self):
swig_include_files = "mapilib adsilib".split()


# Helper to allow our script specifications to include wildcards.
def expand_modules(module_dir):
flist = FileList()
flist.findall(module_dir)
flist.include_pattern("*.py", anchor=0)
return [os.path.splitext(name)[0] for name in flist.files]
def expand_modules(module_dir: Union[str, os.PathLike]):
"""Helper to allow our script specifications to include wildcards."""
return [str(path.with_suffix("")) for path in Path(module_dir).rglob("*.py")]


# NOTE: somewhat counter-intuitively, a result list a-la:
# [('Lib/site-packages\\pythonwin', ('pythonwin/license.txt',)),]
# will 'do the right thing' in terms of installing licence.txt into
# 'Lib/site-packages/pythonwin/licence.txt'. We exploit this to
# get 'com/win32com/whatever' installed to 'win32com/whatever'
def convert_data_files(files):
ret = []
def convert_data_files(files: Iterable[str]):
ret: List[Tuple[str, Tuple[str]]] = []
for file in files:
file = os.path.normpath(file)
if file.find("*") >= 0:
flist = FileList()
flist.findall(os.path.dirname(file))
flist.include_pattern(os.path.basename(file), anchor=0)
# We never want CVS
flist.exclude_pattern(re.compile(r".*\\CVS\\"), is_regex=1, anchor=0)
flist.exclude_pattern("*.pyc", anchor=0)
flist.exclude_pattern("*.pyo", anchor=0)
if not flist.files:
files_use = (
str(path)
for path in Path(file).parent.rglob(os.path.basename(file))
# We never want CVS
if not ("\\CVS\\" in file or path.suffix in {".pyc", ".pyo"})
)
if not files_use:
raise RuntimeError("No files match '%s'" % file)
files_use = flist.files
else:
if not os.path.isfile(file):
raise RuntimeError("No file '%s'" % file)
files_use = (file,)
for fname in files_use:
path_use = os.path.dirname(fname)
if path_use.startswith("com/") or path_use.startswith("com\\"):
if path_use.startswith("com\\"):
path_use = path_use[4:]
ret.append((path_use, (fname,)))
return ret
Expand Down

0 comments on commit 378fcb7

Please sign in to comment.