mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Updated path tracking
This commit is contained in:
19
src/frontend/lib/runtime_paths.py
vendored
19
src/frontend/lib/runtime_paths.py
vendored
@@ -6,11 +6,6 @@ from importlib import resources
|
|||||||
|
|
||||||
ASSET_TOPS = ("static", "templates")
|
ASSET_TOPS = ("static", "templates")
|
||||||
|
|
||||||
def _inside_zipapp() -> bool:
|
|
||||||
# zipapps can be a single file (…/pyshelf.pyz) or an executable file without .pyz
|
|
||||||
# When invoked, sys.argv[0] is the archive path; treat non-directory as zipapp
|
|
||||||
return not Path(sys.argv[0]).is_dir()
|
|
||||||
|
|
||||||
def assets_root() -> Path:
|
def assets_root() -> Path:
|
||||||
"""
|
"""
|
||||||
Directory that *contains* static/ and templates/.
|
Directory that *contains* static/ and templates/.
|
||||||
@@ -19,15 +14,11 @@ def assets_root() -> Path:
|
|||||||
2) ./pyshelf (sibling dir next to the archive) when running as zipapp
|
2) ./pyshelf (sibling dir next to the archive) when running as zipapp
|
||||||
3) frontend/ (package dir) when running from source/unpacked tree
|
3) frontend/ (package dir) when running from source/unpacked tree
|
||||||
"""
|
"""
|
||||||
env = os.environ.get("PYSHELF_ASSETS")
|
# env = os.environ.get("PYSHELF_ASSETS")
|
||||||
if env:
|
# Check if system assets directory exists
|
||||||
return Path(env)
|
sys_path = Path("/etc/pyShelf/src/frontend")
|
||||||
|
if sys_path.is_dir():
|
||||||
if _inside_zipapp():
|
return sys_path.resolve()
|
||||||
# e.g. /opt/pyshelf/pyshelf -> use /opt/pyshelf/pyshelf{,/static,/templates}
|
|
||||||
base = Path(sys.argv[0]).resolve()
|
|
||||||
# strip suffix like ".pyz" if present to get a nice folder name
|
|
||||||
return base.with_suffix("")
|
|
||||||
|
|
||||||
# Dev/regular run: __file__ = …/frontend/lib/runtime_paths.py => parents[1] == …/frontend
|
# Dev/regular run: __file__ = …/frontend/lib/runtime_paths.py => parents[1] == …/frontend
|
||||||
return Path(__file__).resolve().parents[1]
|
return Path(__file__).resolve().parents[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user