Skip to content

Commit

Permalink
Exclude unnecessary files/folders from dist build (#16100)
Browse files Browse the repository at this point in the history
Fixed #16068

Summary of the issue:

There are some unneeded files/empty folders in the NVDA program directory:

"C:\Program Files (x86)\NVDA\brailleDisplayDrivers\albatross\readme.md"

"C:\Program Files (x86)\NVDA\brailleDisplayDrivers\eurobraille"

"C:\Program Files (x86)\NVDA\documentation_pycache_"

Description of user facing changes

Removed redundant files/folders from the installation directory.

Description of development approach

Override getRecursiveDataFiles funtion.

Abandon list comprehensions with no change in logic.

This is because empty folders are created even if their contents are completely excluded.
  • Loading branch information
hwf1324 authored Jan 30, 2024
1 parent 3c2add5 commit 89e33cd
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions source/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,25 @@
from py2exe.dllfinder import DllFinder # noqa: E402
import wx
import importlib.machinery

# Explicitly put the nvda_dmp dir on the build path so the DMP library is included
sys.path.append(os.path.join("..", "include", "nvda_dmp"))
RT_MANIFEST = 24
manifestTemplateFilePath = "manifest.template.xml"

# py2exe's idea of whether a dll is a system dll appears to be wrong sometimes, so monkey patch it.
orig_determine_dll_type = DllFinder.determine_dll_type


def determine_dll_type(self, imagename):
dll = os.path.basename(imagename).lower()
if dll.startswith("api-ms-win-") or dll in ("powrprof.dll", "mpr.dll", "crypt32.dll"):
# These are definitely system dlls available on all systems and must be excluded.
# Including them can cause serious problems when a binary build is run on a different version of Windows.
return None
return orig_determine_dll_type(self, imagename)


DllFinder.determine_dll_type = determine_dll_type


Expand Down Expand Up @@ -85,11 +90,24 @@ def getLocaleDataFiles():
NVDALocaleGestureMaps=[(os.path.dirname(f), (f,)) for f in glob("locale/*/gestures.ini")]
return list(localeMoFiles)+localeDicFiles+NVDALocaleGestureMaps

def getRecursiveDataFiles(dest,source,excludes=()):
rulesList=[]
rulesList.append((dest,
[f for f in glob("%s/*"%source) if not any(fnmatch.fnmatch(f,exclude) for exclude in excludes) and os.path.isfile(f)]))
[rulesList.extend(getRecursiveDataFiles(os.path.join(dest,dirName),os.path.join(source,dirName),excludes=excludes)) for dirName in os.listdir(source) if os.path.isdir(os.path.join(source,dirName)) and not dirName.startswith('.')]

def getRecursiveDataFiles(dest: str, source: str, excludes: tuple = ()) -> list[tuple[str, list[str]]]:
rulesList: list[tuple[str, list[str]]] = []
for file in glob(f"{source}/*"):
if (
not any(fnmatch.fnmatch(file, exclude) for exclude in excludes)
and os.path.isfile(file)
):
rulesList.append((dest, [file]))
for dirName in os.listdir(source):
if os.path.isdir(os.path.join(source, dirName)) and not dirName.startswith('.'):
rulesList.extend(
getRecursiveDataFiles(
os.path.join(dest, dirName),
os.path.join(source, dirName),
excludes=excludes
)
)
return rulesList


Expand Down Expand Up @@ -239,32 +257,33 @@ def _genManifestTemplate(shouldHaveUIAccess: bool) -> tuple[int, int, bytes]:
(".", glob("../miscDeps/python/*.dll")),
(".", ['message.html']),
(".", [os.path.join(sys.base_prefix, "python3.dll")]),
] + (
getLocaleDataFiles()
+ getRecursiveDataFiles("synthDrivers", "synthDrivers",
excludes=tuple(
"*%s" % ext
for ext in importlib.machinery.SOURCE_SUFFIXES + importlib.machinery.BYTECODE_SUFFIXES
] + (
getLocaleDataFiles()
+ getRecursiveDataFiles(
"synthDrivers",
"synthDrivers",
excludes=tuple(
f"*{ext}" for ext in importlib.machinery.all_suffixes()
) + (
"*.exp",
"*.lib",
"*.pdb",
"__pycache__"
))
+ getRecursiveDataFiles("brailleDisplayDrivers", "brailleDisplayDrivers",
excludes=tuple(
"*%s" % ext
for ext in importlib.machinery.SOURCE_SUFFIXES + importlib.machinery.BYTECODE_SUFFIXES
"*.exp",
"*.lib",
"*.pdb"
))
+ getRecursiveDataFiles(
"brailleDisplayDrivers",
"brailleDisplayDrivers",
excludes=tuple(
f"*{ext}" for ext in importlib.machinery.all_suffixes()
) + (
"__pycache__",
))
"*.md",
)
)
+ getRecursiveDataFiles(
"documentation",
"../user_docs",
excludes=tuple(
f"*{ext}" for ext in importlib.machinery.SOURCE_SUFFIXES + importlib.machinery.BYTECODE_SUFFIXES
f"*{ext}" for ext in importlib.machinery.all_suffixes()
) + (
"__pycache__",
"*.t2t",
"*.t2tconf",
"*.md",
Expand Down

0 comments on commit 89e33cd

Please sign in to comment.