Skip to content

Commit

Permalink
building: PKG: ensure DATA files are excluded when in onedir mode
Browse files Browse the repository at this point in the history
When building PKG for `onedir` build, ensure that `DATA` entries
are put into dependencies list instead of including them in the PKG.
This complements existing behavior for `BINARY` and `EXTENSION`
entries, and prevents a `onedir` build from becoming a broken
`onefile` one if user accidentally passes binaries and data files
TOCs to `EXE` instead of `COLLECT` when manually editing the
spec file.
  • Loading branch information
rokm committed Jun 16, 2023
1 parent 6d5dedb commit a87ed7e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion PyInstaller/building/api.py
Expand Up @@ -300,14 +300,22 @@ def assemble(self):
strict_arch_validation=(typecode == 'EXTENSION'),
)
archive_toc.append((dest_name, src_name, self.cdict.get(typecode, False), self.xformdict[typecode]))
elif typecode in ('DATA', 'ZIPFILE'):
# Same logic as above for BINARY and EXTENSION; if `exclude_binaries` is set, we are in onedir mode;
# we should exclude DATA (and ZIPFILE) entries and instead pass them on via PKG's `dependencies`. This
# prevents a onedir application from becoming a broken onefile one if user accidentally passes datas
# and binaries TOCs to EXE instead of COLLECT.
if self.exclude_binaries:
self.dependencies.append((dest_name, src_name, typecode))
else:
archive_toc.append((dest_name, src_name, self.cdict.get(typecode, False), self.xformdict[typecode]))
elif typecode == 'OPTION':
archive_toc.append((dest_name, '', False, 'o'))
elif typecode in ('PYSOURCE', 'PYMODULE'):
# Collect python script and modules in a TOC that will not be sorted.
bootstrap_toc.append((dest_name, src_name, self.cdict.get(typecode, False), self.xformdict[typecode]))
else:
# PYZ, PKG, DEPENDENCY, SPLASH
# TODO: are DATA and ZIPFILE valid here?
archive_toc.append((dest_name, src_name, self.cdict.get(typecode, False), self.xformdict[typecode]))

# Bootloader has to know the name of Python library. Pass python libname to CArchive.
Expand Down
7 changes: 7 additions & 0 deletions news/7708.bugfix.rst
@@ -0,0 +1,7 @@
When building PKG for ``onedir`` build, ensure that ``DATA`` entries
are put into dependencies list instead of including them in the PKG.
This complements existing behavior for ``BINARY`` and ``EXTENSION``
entries, and prevents a ``onedir`` build from becoming a broken
``onefile`` one if user accidentally passes binaries and data files
TOCs to ``EXE`` instead of `COLLECT` when manually editing the
spec file.

0 comments on commit a87ed7e

Please sign in to comment.