Skip to content

Commit

Permalink
Rename --no-dll to --exclude
Browse files Browse the repository at this point in the history
`--no-dll` will continue to be supported as an alias
  • Loading branch information
adang1345 committed Aug 13, 2024
1 parent 73ed3ea commit 7fed0c0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 42 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The path separator to use in the following options is `';'` on Windows and `':'`
`delvewheel show`
- `--add-path`: additional path(s) to search for DLLs, path-separator-delimited. These paths are searched before those in the `PATH` environment variable.
- `--include`: name(s) of additional DLL(s) to vendor into the wheel, path-separator-delimited. We do not automatically search for dependencies of these DLLs unless another included DLL depends on them. If you use this option, it is your responsibility to ensure that the additional DLL is found at load time.
- `--no-dll`: name(s) of DLL(s) to specifically exclude from the wheel, path-separator-delimited. Dependencies of these DLLs are also automatically excluded if no other included DLL depends on them.
- `--exclude`: name(s) of DLL(s) to specifically exclude from the wheel, path-separator-delimited. Dependencies of these DLLs are also automatically excluded if no other included DLL depends on them.
- `--ignore-existing`: don't search for or vendor in DLLs that are already in the wheel. We still search for and vendor in dependencies of these DLLs if they are not in the wheel. This flag is meant for simpler integration with other DLL bundling tools/techniques but is not a catch-all. If you use this flag, it is your responsibility to ensure that the DLLs that are already in the wheel are loaded correctly.
- `--analyze-existing`: analyze and vendor in dependencies of DLLs that are already in the wheel. If you use this option, it is your responsibility to ensure that these dependencies are found at load time.
- `-v`: verbosity
Expand All @@ -53,7 +53,7 @@ The path separator to use in the following options is `';'` on Windows and `':'`
`delvewheel repair`
- `--add-path`: additional path(s) to search for DLLs, path-separator-delimited. These paths are searched before those in the `PATH` environment variable.
- `--include`: name(s) of additional DLL(s) to vendor into the wheel, path-separator-delimited. We do not automatically search for or vendor in dependencies of these DLLs unless another included DLL depends on them. We do not mangle the names of these DLLs or their direct dependencies. If you use this option, it is your responsibility to ensure that the additional DLL is found at load time.
- `--no-dll`: name(s) of DLL(s) to specifically exclude from the wheel, path-separator-delimited. Dependencies of these DLLs are also automatically excluded if no other included DLL depends on them.
- `--exclude`: name(s) of DLL(s) to specifically exclude from the wheel, path-separator-delimited. Dependencies of these DLLs are also automatically excluded if no other included DLL depends on them.
- `--ignore-existing`: don't search for or vendor in DLLs that are already in the wheel. Don't mangle the names of these DLLs or their direct dependencies. We still search for and vendor in dependencies of these DLLs if they are not in the wheel. This flag is meant for simpler integration with other DLL bundling tools/techniques but is not a catch-all. If you use this flag, it is your responsibility to ensure that the DLLs that are already in the wheel are loaded correctly.
- `--analyze-existing`: analyze and vendor in dependencies of DLLs that are already in the wheel. These dependencies are name-mangled by default. If you use this option, it is your responsibility to ensure that these dependencies are found at load time.
- `-v`: verbosity
Expand Down
8 changes: 4 additions & 4 deletions delvewheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def main():
subparser.add_argument('wheel', nargs='+', help='wheel(s) to show or repair')
subparser.add_argument('--add-path', default='', metavar='PATHS', help=f'additional path(s) to search for DLLs, {os.pathsep!r}-delimited')
subparser.add_argument('--include', '--add-dll', default='', metavar='DLLS', type=_dll_names, help=f'force inclusion of DLL name(s), {os.pathsep!r}-delimited')
subparser.add_argument('--no-dll', default='', metavar='DLLS', type=_dll_names, help=f'force exclusion of DLL name(s), {os.pathsep!r}-delimited')
subparser.add_argument('--exclude', '--no-dll', default='', metavar='DLLS', type=_dll_names, help=f'force exclusion of DLL name(s), {os.pathsep!r}-delimited')
subparser.add_argument('--ignore-existing', '--ignore-in-wheel', action='store_true', help="don't search for or vendor in DLLs that are already in the wheel")
subparser.add_argument('--analyze-existing', action='store_true', help='analyze and vendor in dependencies of DLLs that are already in the wheel')
subparser.add_argument('-v', action='count', default=0, help='verbosity')
Expand All @@ -67,17 +67,17 @@ def main():
if args.command in ('show', 'repair'):
add_paths = dict.fromkeys(os.path.abspath(path) for path in args.add_path.split(os.pathsep) if path)
include = set(dll_name.lower() for dll_name in args.include.split(os.pathsep) if dll_name)
no_dlls = set(dll_name.lower() for dll_name in args.no_dll.split(os.pathsep) if dll_name)
exclude = set(dll_name.lower() for dll_name in args.exclude.split(os.pathsep) if dll_name)

intersection = include & no_dlls
intersection = include & exclude
if intersection:
raise ValueError(f'Cannot force both inclusion and exclusion of {intersection}')

if add_paths:
os.environ['PATH'] = f'{os.pathsep.join(add_paths)}{os.pathsep}{os.environ["PATH"]}'

for wheel in args.wheel:
wr = WheelRepair(wheel, args.extract_dir, include, no_dlls, args.ignore_existing, args.analyze_existing, args.v, args.test.split(','))
wr = WheelRepair(wheel, args.extract_dir, include, exclude, args.ignore_existing, args.analyze_existing, args.v, args.test.split(','))
if args.command == 'show':
wr.show()
else: # args.command == 'repair'
Expand Down
12 changes: 6 additions & 6 deletions delvewheel/_dll_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ def get_direct_needed(lib_path: str, verbose: int) -> set:
return needed


def get_direct_mangleable_needed(lib_path: str, no_dlls: set, no_mangles: set, verbose: int) -> list:
def get_direct_mangleable_needed(lib_path: str, exclude: set, no_mangles: set, verbose: int) -> list:
"""Given the path to a shared library, return a deterministically-ordered
list containing the lowercase DLL names of all direct dependencies that
belong in the wheel and should be name-mangled.
no_dlls is a set of lowercase additional DLL names that do not belong in
exclude is a set of lowercase additional DLL names that do not belong in
the wheel.
no_mangles is a set of lowercase additional DLL names not to mangle."""
Expand All @@ -348,7 +348,7 @@ def get_direct_mangleable_needed(lib_path: str, no_dlls: set, no_mangles: set, v
for entry in imports:
dll_name = entry.dll.decode('utf-8').lower()
if dll_name not in ignore_names and \
dll_name not in no_dlls and \
dll_name not in exclude and \
not any(r.fullmatch(dll_name) for r in _dll_list.ignore_regexes) and \
dll_name not in no_mangles and \
(lib_name_lower not in _dll_list.ignore_dependency or dll_name not in _dll_list.ignore_dependency[lib_name_lower]) and \
Expand All @@ -358,7 +358,7 @@ def get_direct_mangleable_needed(lib_path: str, no_dlls: set, no_mangles: set, v


def get_all_needed(lib_path: str,
no_dlls: set,
exclude: set,
wheel_dirs: typing.Optional[typing.Iterable],
on_error: str,
include_symbols: bool,
Expand All @@ -378,7 +378,7 @@ def get_all_needed(lib_path: str,
library cannot be found. If on_error is 'ignore', not_found contains the
lowercased DLL names of all dependent DLLs that cannot be found.
no_dlls is a set of DLL names to force exclusion from the wheel. We do not
exclude is a set of DLL names to force exclusion from the wheel. We do not
search for dependencies of these DLLs.
If wheel_dirs is not None, it is an iterable of directories in the wheel
Expand Down Expand Up @@ -412,7 +412,7 @@ def get_all_needed(lib_path: str,
dll_name = entry.dll.decode('utf-8').lower()
if dll_name not in ignore_names and \
not any(r.fullmatch(dll_name) for r in _dll_list.ignore_regexes) and \
dll_name not in no_dlls and \
dll_name not in exclude and \
(lib_name_lower not in _dll_list.ignore_dependency or dll_name not in _dll_list.ignore_dependency[lib_name_lower]):
dll_info = find_library(dll_name, wheel_dirs, lib_arch, include_symbols, include_imports)
if dll_info:
Expand Down
27 changes: 14 additions & 13 deletions delvewheel/_wheel_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class WheelRepair:
_purelib_dir: str # extracted path to .data/purelib directory, is set even if directory does not exist
_platlib_dir: str # extracted path to .data/platlib directory, is set even if directory does not exist
_include: typing.Set[str] # additional DLLs to include
_no_dlls: typing.Set[str] # DLLs to exclude
_exclude: typing.Set[str] # DLLs to exclude
_wheel_dirs: typing.Optional[typing.List[str]] # extracted directories from inside wheel
_ignore_existing: bool # whether to ignore DLLs that are already inside wheel
_analyze_existing: bool # whether to analyze and vendor in dependencies of DLLs that are already in the wheel
Expand All @@ -137,7 +137,7 @@ def __init__(self,
whl_path: str,
extract_dir: typing.Optional[str],
include: typing.Optional[typing.Set[str]],
no_dlls: typing.Optional[typing.Set[str]],
exclude: typing.Optional[typing.Set[str]],
ignore_existing: bool,
analyze_existing: bool,
verbose: int,
Expand All @@ -147,10 +147,11 @@ def __init__(self,
extract_dir: Directory where wheel is extracted. If None, a temporary
directory is created.
include: Set of lowercase DLL names to force inclusion into the wheel
no_dlls: Set of lowercase DLL names to force exclusion from wheel
exclude: Set of lowercase DLL names to force exclusion from wheel
(cannot overlap with include)
ignore_existing: whether to ignore DLLs that are already in the wheel
analyze_existing: whether to analyze and vendor in dependencies of DLLs that are already in the wheel
analyze_existing: whether to analyze and vendor in dependencies of DLLs
that are already in the wheel
verbose: verbosity level, 0 to 2
test: testing options for internal use"""
if not os.path.isfile(whl_path):
Expand Down Expand Up @@ -191,9 +192,9 @@ def __init__(self,
self._platlib_dir = os.path.join(self._data_dir, 'platlib')

self._include = set() if include is None else include
self._no_dlls = set() if no_dlls is None else no_dlls
self._exclude = set() if exclude is None else exclude

# Modify self._no_dlls to include those that are already part of every
# Modify self._exclude to include those that are already part of every
# Python distribution the wheel targets.
abi_tags = whl_name_split[-2].split('.')
platform_tag = whl_name_split[-1]
Expand All @@ -209,7 +210,7 @@ def __init__(self,
else:
ignore_by_abi_platform = set()
break
self._no_dlls |= ignore_by_abi_platform
self._exclude |= ignore_by_abi_platform

python_tags = whl_name_split[-3].split('.')
if abi_tags == ['abi3']:
Expand All @@ -223,7 +224,7 @@ def __init__(self,
else:
ignore_abi3 = set()
break
self._no_dlls |= ignore_abi3
self._exclude |= ignore_abi3

# If ignore_existing is True, save list of all directories in the
# wheel. These directories will be used to search for DLLs that are
Expand Down Expand Up @@ -641,7 +642,7 @@ def show(self) -> None:
if filename_lower.endswith('.pyd') or self._analyze_existing and filename_lower.endswith('.dll'):
extension_module_path = os.path.join(root, filename)
extension_module_paths.append(extension_module_path)
discovered, _, ignored, not_found = _dll_utils.get_all_needed(extension_module_path, self._no_dlls, self._wheel_dirs, 'ignore', False, False, self._verbose)
discovered, _, ignored, not_found = _dll_utils.get_all_needed(extension_module_path, self._exclude, self._wheel_dirs, 'ignore', False, False, self._verbose)
dependency_paths |= discovered
ignored_dll_names |= ignored
not_found_dll_names |= not_found
Expand Down Expand Up @@ -756,7 +757,7 @@ def repair(
elif self._verbose >= 1:
print(f'analyzing package-level extension module {os.path.relpath(extension_module_path, self._extract_dir)}')
extension_module_paths.append(extension_module_path)
discovered, associated, ignored = _dll_utils.get_all_needed(extension_module_path, self._no_dlls, self._wheel_dirs, 'raise', include_symbols, include_imports, self._verbose)[:3]
discovered, associated, ignored = _dll_utils.get_all_needed(extension_module_path, self._exclude, self._wheel_dirs, 'raise', include_symbols, include_imports, self._verbose)[:3]
dependency_paths |= discovered
associated_paths |= associated
ignored_dll_names |= ignored
Expand All @@ -768,7 +769,7 @@ def repair(
for p in dependency_paths_in_wheel:
name_lower = os.path.basename(p).lower()
no_mangles.add(name_lower)
no_mangles.update(_dll_utils.get_direct_mangleable_needed(p, self._no_dlls, no_mangles, self._verbose))
no_mangles.update(_dll_utils.get_direct_mangleable_needed(p, self._exclude, no_mangles, self._verbose))
if name_lower not in self._include:
ignored_dll_names.add(name_lower)
dependency_paths = dependency_paths_outside_wheel
Expand Down Expand Up @@ -855,7 +856,7 @@ def repair(
extension_module_name = os.path.basename(extension_module_path)
if self._verbose >= 1:
print(f'repairing {extension_module_name} -> {extension_module_name}')
needed = _dll_utils.get_direct_mangleable_needed(extension_module_path, self._no_dlls, no_mangles, self._verbose)
needed = _dll_utils.get_direct_mangleable_needed(extension_module_path, self._exclude, no_mangles, self._verbose)
_dll_utils.replace_needed(extension_module_path, needed, name_mangler, strip, self._verbose, self._test)
for lib_name in dependency_names:
lib_path = os.path.join(libs_dir, lib_name)
Expand All @@ -868,7 +869,7 @@ def repair(
print(f'repairing {lib_name} -> {name_mangler[lib_name.lower()]}')
else:
print(f'repairing {lib_name} -> {lib_name}')
needed = _dll_utils.get_direct_mangleable_needed(lib_path, self._no_dlls, no_mangles, self._verbose)
needed = _dll_utils.get_direct_mangleable_needed(lib_path, self._exclude, no_mangles, self._verbose)
_dll_utils.replace_needed(lib_path, needed, name_mangler, strip, self._verbose, self._test)
if lib_name.lower() in name_mangler:
os.rename(lib_path, os.path.join(libs_dir, name_mangler[lib_name.lower()]))
Expand Down
Loading

0 comments on commit 7fed0c0

Please sign in to comment.