Skip to content

Commit 64f688d

Browse files
committed
Very much similar to v1.7.1, except that modifications were made to be able to create standalone package.
1 parent 13ae742 commit 64f688d

File tree

6 files changed

+343
-10
lines changed

6 files changed

+343
-10
lines changed

lib/Sisyphus/Configuration/_Configuration.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
import subprocess
2424
import tempfile
2525
import re
26-
import OpenSSL
26+
#import OpenSSL
27+
try:
28+
import OpenSSL # pyOpenSSL
29+
except Exception:
30+
OpenSSL = None
2731
import requests
2832
from datetime import datetime
2933
from copy import deepcopy

lib/Sisyphus/Gui/Dashboard/__main__.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from threading import Timer
55
from dash import Dash, html
66
import dash_bootstrap_components as dbc
7+
from pathlib import Path
78

89

910
import os, sys, io, contextlib
@@ -34,12 +35,54 @@
3435
register_overlay_callbacks,
3536
)
3637

38+
def get_path(rel: str) -> str:
39+
"""
40+
Resolve a path relative to the runtime root.
41+
42+
Frozen (PyInstaller onedir):
43+
<dist>/HWDBTools/_internal/<rel>
44+
45+
Non-frozen (repo checkout):
46+
<repo_root>/<rel>
47+
"""
48+
rel = rel.lstrip("/").replace("\\", "/")
49+
50+
if getattr(sys, "frozen", False):
51+
# In onedir, the EXE lives in <dist>/HWDBTools/
52+
# and _internal is a sibling folder.
53+
runtime_root = Path(sys.executable).resolve().parent / "_internal"
54+
return str(runtime_root / rel)
55+
56+
# Non-frozen: infer repo root from this file location:
57+
# lib/Sisyphus/Gui/Dashboard/__main__.py -> repo root is 5 parents up
58+
# (__main__.py -> Dashboard -> Gui -> Sisyphus -> lib -> PROJECT_ROOT)
59+
runtime_root = Path(__file__).resolve().parents[4]
60+
return str(runtime_root / rel)
61+
3762
#------------- create the website and interface -------
38-
app = Dash(
39-
__name__,
63+
dash_kwargs = dict(
4064
external_stylesheets=[dbc.themes.BOOTSTRAP],
41-
suppress_callback_exceptions=True
65+
suppress_callback_exceptions=True,
66+
)
67+
68+
if getattr(sys, "frozen", False):
69+
# Frozen: our spec places Dashboard assets into _internal/assets/
70+
dash_kwargs.update(
71+
assets_folder=get_path("assets"),
72+
assets_url_path="/assets", # optional; Dash default is already "/assets"
4273
)
74+
75+
app = Dash(__name__, **dash_kwargs)
76+
77+
#------------- create the website and interface -------
78+
#app = Dash(
79+
# __name__,
80+
# external_stylesheets=[dbc.themes.BOOTSTRAP],
81+
# suppress_callback_exceptions=True,
82+
# assets_folder=get_path("assets"),
83+
# assets_url_path="/assets",
84+
# )
85+
4386
app.title = "HWDB Dashboard"
4487
app.layout = layout
4588
# Force Dash to validate the layout before callback registration

lib/Sisyphus/HWDBUtility/Upload/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from Sisyphus import RestApiV1 as ra
1717
from shutil import get_terminal_size
1818

19+
import multiprocessing as mp
20+
1921

2022
def main(argv=None):
2123
logger.info(f"Starting {__name__}")
@@ -38,4 +40,5 @@ def main(argv=None):
3840
logger.info(f"Finished {__name__} and exiting.")
3941

4042
if __name__ == "__main__":
43+
mp.freeze_support()
4144
main(argv=config.remaining_args)

lib/Sisyphus/Utils/Fonts.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"""
1111

1212
import Sisyphus
13+
from Sisyphus import get_path
1314

1415
import os, sys
1516
from PIL import ImageFont
@@ -98,7 +99,11 @@
9899
#}}}
99100
}
100101

101-
def list_fonts(fonts=known_fonts, name="", subdir=Sisyphus.project_root):
102+
def list_fonts(fonts=known_fonts, name="", subdir=None):
103+
# Base directory: runtime root (works frozen + non-frozen)
104+
if subdir is None:
105+
subdir = get_path("") # runtime root; resources/... will be appended below
106+
102107
if "_subdir" in fonts.keys():
103108
subdir = os.path.join(subdir, fonts["_subdir"])
104109
if "_file" in fonts.keys():
@@ -107,6 +112,15 @@ def list_fonts(fonts=known_fonts, name="", subdir=Sisyphus.project_root):
107112
if key.startswith("_"):
108113
continue
109114
yield from list_fonts(fonts[key], " ".join([name, key]).strip(), subdir)
115+
#def list_fonts(fonts=known_fonts, name="", subdir=Sisyphus.project_root):
116+
# if "_subdir" in fonts.keys():
117+
# subdir = os.path.join(subdir, fonts["_subdir"])
118+
# if "_file" in fonts.keys():
119+
# yield name, os.path.realpath(os.path.join(subdir, fonts["_file"]))
120+
# for key, value in fonts.items():
121+
# if key.startswith("_"):
122+
# continue
123+
# yield from list_fonts(fonts[key], " ".join([name, key]).strip(), subdir)
110124

111125

112126
def get_font(name, size):

lib/Sisyphus/__init__.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,46 @@
66
Author: Alex Wagner <[email protected]>, Dept. of Physics and Astronomy
77
"""
88

9-
import os
9+
from pathlib import Path
10+
import os, sys
1011

1112
#version = 'v1.3.0.rel.2025.07.21a'
12-
version = 'v1.7.1.rel.2026.01.18a'
13+
version = 'v1.7.2.rel.2026.02.17a'
14+
1315

1416
project_root = os.path.realpath(os.path.join(os.path.dirname(__file__), "../.."))
1517

16-
def get_path(path):
17-
"""Get a path relative to the project root"""
18-
return os.path.realpath(os.path.join(project_root, path))
18+
def _runtime_root() -> Path:
19+
# Frozen (PyInstaller): _MEIPASS points to the extracted runtime dir.
20+
# In onedir builds, that means ".../dist/HWDBTools/_internal"
21+
if getattr(sys, "frozen", False):
22+
return Path(getattr(sys, "_MEIPASS", Path(sys.executable).resolve().parent / "_internal"))
23+
24+
# Non-frozen: keep our existing behavior
25+
if "project_root" in globals():
26+
return Path(project_root)
27+
28+
# Fallback: walk upward from this file until we find a repo marker!
29+
here = Path(__file__).resolve()
30+
for p in [here] + list(here.parents):
31+
if (p / "lib").is_dir() and (p / "resources").is_dir():
32+
return p
33+
return here.parent
34+
35+
36+
_RUNTIME_ROOT = _runtime_root()
37+
38+
39+
def get_path(rel: str) -> str:
40+
rel = rel.lstrip("/").replace("\\", "/")
41+
return str(_RUNTIME_ROOT / rel)
42+
43+
#def get_path(path):
44+
# """Get a path relative to the project root"""
45+
# return os.path.realpath(os.path.join(project_root, path))
46+
47+
48+
1949

2050
def display_header():
2151
import Sisyphus.Configuration as Config

0 commit comments

Comments
 (0)