Skip to content

Commit

Permalink
Workaround for PyPi resource issue, but also making it not crash if r…
Browse files Browse the repository at this point in the history
…esources not found (#216)
  • Loading branch information
cfcurtis committed Jun 18, 2024
1 parent b896916 commit d51886e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.8 # old to support Windows 7

- name: Update package index
run: sudo apt-get update
- name: Install wxPython dependencies
Expand All @@ -61,6 +61,10 @@ jobs:
libwebkit2gtk-4.0-dev \
libxtst-dev
- name: Copy resources directory
# PyPi needs to have resources in the same directory as the package
run: cp -r resources pdfstitcher/resources

- name: Compile translation files and build distribution
run: |
python3 build/update_loc.py --compile
Expand Down
6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
recursive-include resources *.ico
recursive-include resources *.mo
recursive-include resources *.po
recursive-include pdfstitcher/resources *.ico
recursive-include pdfstitcher/resources *.mo
recursive-include pdfstitcher/resources *.po
8 changes: 6 additions & 2 deletions pdfstitcher/gui/main_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def __init__(self, *args, **kw):
self.Bind(wx.EVT_CLOSE, self.on_exit)

if sys.platform == "win32" or sys.platform == "linux":
self.SetIcon(wx.Icon(utils.resource_path("stitcher-icon.ico")))
ico = utils.resource_path("stitcher-icon.ico")
if ico.exists():
self.SetIcon(wx.Icon(str(ico)))

if len(sys.argv) > 1:
self.load_file(sys.argv[1])
Expand Down Expand Up @@ -310,8 +312,10 @@ def on_about(self, event):
"""
Show the about info.
"""
ico = utils.resource_path("stitcher-icon.ico")
about_info = wx.adv.AboutDialogInfo()
about_info.SetIcon(wx.Icon(utils.resource_path("stitcher-icon.ico")))
if ico.exists():
about_info.SetIcon(wx.Icon(str(ico)))
about_info.SetName("PDFStitcher")
about_info.SetVersion(utils.VERSION_STRING)
about_info.SetDescription(_("The PDF Stitching app for sewists, by sewists."))
Expand Down
13 changes: 10 additions & 3 deletions pdfstitcher/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,28 @@ def resource_path(relative_path: str) -> Path:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = Path(sys._MEIPASS) / "resources"
else:
# Nuitka places resources adjacent to the executable
# Nuitka and PyPi place resources adjacent to the executable
base_path = Path(__file__).parent.absolute() / "resources"

# If we're running from source, the resources are in the parent directory
if not base_path.exists():
base_path = Path(__file__).parent.parent.absolute() / "resources"

return str(base_path / relative_path)
return base_path / relative_path


def get_valid_langs() -> list:
"""
Get a list of valid languages for the UI.
"""
return ["en"] + [f.name for f in os.scandir(resource_path("locale")) if f.is_dir()]
valid = ["en"]
try:
valid += [f.name for f in os.scandir(resource_path("locale")) if f.is_dir()]
except FileNotFoundError:
# Something weird with resources, but don't crash
pass

return valid


def setup_locale(lang: str = None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pdfstitcher"
version = "1.0.0"
version = "1.0.1"
description = "The open source PDF stitching software for sewists, by sewists."
readme = "README.md"
requires-python = ">=3.8, <3.13"
Expand Down

0 comments on commit d51886e

Please sign in to comment.