Skip to content

Commit

Permalink
Simplify per review comment
Browse files Browse the repository at this point in the history
#1651 (comment)

This very slightly changes semantics: if `pywin32_system32` is found to
have multiple entries in `__path__` and the first one is not an existing
directory, now the search will continue whereas before it would give up.
  • Loading branch information
wkschwartz committed Jan 20, 2021
1 parent cb51ca4 commit df3e334
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions win32/Lib/pywin32_bootstrap.py
Expand Up @@ -17,22 +17,17 @@
try:
import pywin32_system32
except Exc:
path_iterator = iter([])
pass
else:
# We're guaranteed only that __path__: Iterable[str]
# https://docs.python.org/3/reference/import.html#__path__
path_iterator = iter(pywin32_system32.__path__)

try:
path = next(path_iterator)
except StopIteration:
pass
else:
if os.path.isdir(path):
if hasattr(os, "add_dll_directory"):
os.add_dll_directory(path)
# This is to ensure the pywin32 path is in the beginning to find the
# pywin32 DLLs first and prevent other PATH entries to shadow them
elif not os.environ["PATH"].startswith(path):
os.environ["PATH"] = os.environ["PATH"].replace(os.pathsep + path, "")
os.environ["PATH"] = path + os.pathsep + os.environ["PATH"]
for path in pywin32_system32.__path__:
if os.path.isdir(path):
if hasattr(os, "add_dll_directory"):
os.add_dll_directory(path)
# This is to ensure the pywin32 path is in the beginning to find the
# pywin32 DLLs first and prevent other PATH entries to shadow them
elif not os.environ["PATH"].startswith(path):
os.environ["PATH"] = os.environ["PATH"].replace(os.pathsep + path, "")
os.environ["PATH"] = path + os.pathsep + os.environ["PATH"]
break

0 comments on commit df3e334

Please sign in to comment.