fix: Add PyInstaller hook to bundle newspaper resource files#719
Draft
fix: Add PyInstaller hook to bundle newspaper resource files#719
Conversation
Co-authored-by: AndyTheFactory <863810+AndyTheFactory@users.noreply.github.com> Agent-Logs-Url: https://github.com/AndyTheFactory/newspaper4k/sessions/49891e36-4f4e-40d4-99a6-893ba439518e
Copilot
AI
changed the title
[WIP] Fix newspaper4k not working with PyInstaller
fix: Add PyInstaller hook to bundle newspaper resource files
Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When frozen with PyInstaller, the
newspaper/resources/directory (stopwords, user-agents, source lists) is not automatically included, causing aFileNotFoundErrorat runtime whenStopWordstries to open e.g.stopwords-en.txt.Proposed Changes:
newspaper/_pyinstaller/__init__.py— Exposesget_hook_dirs()so PyInstaller discovers the hook automatically via thepyinstaller40entry pointnewspaper/_pyinstaller/hook-newspaper.py— Callscollect_data_files("newspaper")to bundle all files undernewspaper/resources/into the frozen apppyproject.toml— Registers the entry point:.specchanges required.How did you test it?
Added
tests/unit/test_pyinstaller_hook.pyverifying:get_hook_dirs()returns a list with one entryhook-newspaper.pyis present in that directoryNotes for the reviewer
The hook uses
collect_data_files("newspaper")which recursively collects all non-.pyfiles from the installed package — this covers bothresources/text/stopwords-*.txtandresources/misc/*.txt. No changes to the runtime resource-loading logic (settings.py/text.py) are needed; PyInstaller places bundled data files such thatPath(__file__).resolve().parentstill resolves correctly inside the frozen binary.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/usr/bin/python python -m pytest tests/unit/ -v -x -q(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.