Skip to content

Commit 5953781

Browse files
Added build config to repo, with resources now stored in executable
1 parent 864be40 commit 5953781

2 files changed

Lines changed: 50 additions & 10 deletions

File tree

build_config.spec

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
block_cipher = None
4+
5+
a = Analysis(['src\\multi_stat_analysis\\__main__.py'],
6+
pathex=['src\\multi_stat_analysis'],
7+
binaries=[],
8+
datas=[('C:/workspace/Multiscale-Statistical-Analysis/resources/*', 'resources')],
9+
hiddenimports=['scipy.special.cython_special',
10+
'pkg_resources.py2_warn',
11+
'pyimod03_importers',
12+
'pyi_rth_pkgres'],
13+
hookspath=[],
14+
runtime_hooks=[],
15+
excludes=[],
16+
win_no_prefer_redirects=False,
17+
win_private_assemblies=False,
18+
cipher=block_cipher,
19+
noarchive=False)
20+
21+
pyz = PYZ(a.pure, a.zipped_data,
22+
cipher=block_cipher)
23+
24+
exe = EXE(pyz,
25+
a.scripts,
26+
a.binaries,
27+
a.zipfiles,
28+
a.datas,
29+
[],
30+
name='MultiscaleStatisticalAnalysis',
31+
debug=False,
32+
bootloader_ignore_signals=False,
33+
strip=False,
34+
upx=False,
35+
upx_exclude=[],
36+
runtime_tmpdir=None,
37+
console=False )

src/multi_stat_analysis/MountainsImporter/ImportUtils.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
from typing import Optional
55
from ctypes import wintypes, windll, create_unicode_buffer, pointer
66

7-
_DEFAULT_TIMEOUT = 60.0
8-
_resource_paths = {}
9-
107
class ResourceFiles:
8+
DIRECTORY = "resources"
9+
1110
SSFA_TEMPLATE = "ssfa-template.mnt"
1211

1312
START_MNTS_BTN = "start-mountains.png"
@@ -24,6 +23,15 @@ def append_to_path(end_str, prefix=os.getcwd()):
2423
"""Joins the given end string to the end of the file path prefix."""
2524
return os.path.join(os.sep, prefix, end_str)
2625

26+
_DEFAULT_TIMEOUT = 60.0
27+
_resource_paths = {}
28+
# Find base path for resources
29+
try:
30+
# PyInstaller creates a temp folder and stores path in _MEIPASS
31+
_resource_base_path = append_to_path(ResourceFiles.DIRECTORY, sys._MEIPASS)
32+
except Exception:
33+
_resource_base_path = append_to_path(ResourceFiles.DIRECTORY)
34+
2735
def resource_abs_path(relative_path):
2836
"""Get absolute path to resources, works for normal file handling and for PyInstaller.
2937
Based on answer from stackoverflow page:
@@ -34,13 +42,8 @@ def resource_abs_path(relative_path):
3442
if relative_path in _resource_paths:
3543
return _resource_paths[relative_path]
3644

37-
try:
38-
# PyInstaller creates a temp folder and stores path in _MEIPASS
39-
base_path = sys._MEIPASS
40-
except Exception:
41-
base_path = append_to_path("resources")
42-
43-
path = append_to_path(relative_path, base_path)
45+
global _resource_base_path
46+
path = append_to_path(relative_path, _resource_base_path)
4447
if not os.path.exists(path):
4548
raise FileNotFoundError("Could not find resource " + path)
4649
_resource_paths[relative_path] = path

0 commit comments

Comments
 (0)