Skip to content

Commit

Permalink
fix action plugins and long path under Windows (#551)
Browse files Browse the repository at this point in the history
PyInstaller doesn't support pkgutil.iter_modules out of the box but there is a workaround:
pyinstaller/pyinstaller#1905

FIX: support long paths under Windows 10 v1607 or later, once enabled in registry/GPO (see Windows README for details), closes #236
  • Loading branch information
ericzolf committed Apr 8, 2021
1 parent 68d5b47 commit 8ebb48d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/Windows-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ and copy the four enclosed files to the same directory as *rdiff-backup.exe*.

You will need to follow either method only once.

> **NOTE:** you might want to [enable long paths support in Windows 10 v1607 or later](https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation#enable-long-paths-in-windows-10-version-1607-and-later)
## Additional Issues

Currently, *rdiff-backup*'s `--include` and `--exclude` options do not support
Expand Down
15 changes: 13 additions & 2 deletions src/rdiffbackup/actions_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_discovered_actions():
# and we complete/overwrite with modules delivered in the namespace
discovered_action_plugins.update({
name: importlib.import_module(name)
for finder, name, ispkg
for name
in _iter_namespace(rdiffbackup.actions)
})
# then we create the dictionary of {action_name: ActionClass}
Expand Down Expand Up @@ -90,7 +90,18 @@ def _iter_namespace(nsp):
# returned name an absolute name instead of a relative one. This allows
# import_module to work without having to do additional modification to
# the name.
return pkgutil.iter_modules(nsp.__path__, nsp.__name__ + ".")
prefix = nsp.__name__ + "."
for pkg in pkgutil.iter_modules(nsp.__path__, prefix):
yield pkg[1] # pkg is (finder, name, ispkg)
# special handling when the package is bundled with PyInstaller
# See https://github.com/pyinstaller/pyinstaller/issues/1905
toc = set() # table of content
for importer in pkgutil.iter_importers(nsp.__name__.partition(".")[0]):
if hasattr(importer, 'toc'):
toc |= importer.toc
for name in toc:
if name.startswith(prefix):
yield name


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions tools/hook-rdiffbackup.actions_mgr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('rdiffbackup.actions')
1 change: 1 addition & 0 deletions tools/win_build_rdiffbackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ py_ver_brief=${PYTHON_VERSION%.[0-9]}
${PYEXE} setup.py bdist_wheel
${PYINST} --onefile --distpath build/${ver_name}-${bits} \
--paths=build/lib.win32-${py_ver_brief} \
--additional-hooks-dir=tools
--console build/scripts-${py_ver_brief}/rdiff-backup \
--add-data=src/rdiff_backup.egg-info/PKG-INFO\;rdiff_backup.egg-info
4 changes: 3 additions & 1 deletion tools/windows/playbook-build-rdiff-backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
- name: compile rdiff-backup into an executable using pyinstaller
win_command: >
pyinstaller --onefile
--paths=build/lib.{{ python_win_bits }}-{{ python_version }} --paths={{ librsync_install_dir }}/lib
--paths=build/lib.{{ python_win_bits }}-{{ python_version }}
--paths={{ librsync_install_dir }}/lib
--paths={{ librsync_install_dir }}/bin
--additional-hooks-dir=tools
--console build/scripts-{{ python_version }}/rdiff-backup
--add-data src/rdiff_backup.egg-info/PKG-INFO;rdiff_backup.egg-info
environment:
Expand Down

0 comments on commit 8ebb48d

Please sign in to comment.