diff --git a/nwb-guide.spec b/nwb-guide.spec index 25d76a291..d4868ee6d 100644 --- a/nwb-guide.spec +++ b/nwb-guide.spec @@ -10,7 +10,7 @@ import scipy from PyInstaller.utils.hooks import collect_data_files from PyInstaller.utils.hooks import collect_all -datas = [('./src/paths.config.json', './src'), ('./package.json', '.')] +datas = [('./src/paths.config.json', '.'), ('./package.json', '.')] binaries = [] hiddenimports = [ 'email_validator', diff --git a/package.json b/package.json index 739dcf06e..17393fe59 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "test:pipelines": "vitest pipelines", "test:server": "pytest src/pyflask/tests/ -s -vv", "wait5s": "node -e \"setTimeout(() => process.exit(0),5000)\"", - "test:executable": "concurrently -n EXE,TEST --kill-others --success first \"node tests/testPyinstallerExecutable.js --port 3434 --forever\" \"npm run wait5s && pytest pyflask/tests/ -s --target http://localhost:3434\"", + "test:executable": "concurrently -n EXE,TEST --kill-others --success first \"node tests/testPyinstallerExecutable.js --port 3434 --forever\" \"npm run wait5s && pytest src/pyflask/tests/ -s --target http://localhost:3434\"", "test:coverage": "npm run coverage:app && npm run coverage:server", "coverage:app": "npm run test:app -- --coverage", "coverage:server": "pytest src/pyflask/tests/ -s --cov=pyflask --cov-report=xml", diff --git a/src/pyflask/app.py b/src/pyflask/app.py index af363291f..65d3498bc 100644 --- a/src/pyflask/app.py +++ b/src/pyflask/app.py @@ -27,6 +27,7 @@ GUIDE_ROOT_FOLDER, STUB_SAVE_FOLDER_PATH, resource_path, + is_packaged ) app = Flask(__name__) @@ -42,7 +43,7 @@ LOG_FILE_PATH = Path(LOG_FOLDER, f"{timestamp}.log") # Initialize API -package_json_file_path = resource_path("../package.json") +package_json_file_path = resource_path("package.json" if is_packaged() else "../package.json") with open(file=package_json_file_path) as fp: package_json = json.load(fp=fp) diff --git a/src/pyflask/manageNeuroconv/info/__init__.py b/src/pyflask/manageNeuroconv/info/__init__.py index edde04113..d91d25519 100644 --- a/src/pyflask/manageNeuroconv/info/__init__.py +++ b/src/pyflask/manageNeuroconv/info/__init__.py @@ -4,4 +4,5 @@ GUIDE_ROOT_FOLDER, STUB_SAVE_FOLDER_PATH, resource_path, + is_packaged ) diff --git a/src/pyflask/manageNeuroconv/info/urls.py b/src/pyflask/manageNeuroconv/info/urls.py index bf8a65116..d1b15aab1 100644 --- a/src/pyflask/manageNeuroconv/info/urls.py +++ b/src/pyflask/manageNeuroconv/info/urls.py @@ -3,6 +3,14 @@ import sys from pathlib import Path +def is_packaged(): + deployed = True + try: + sys._MEIPASS # PyInstaller creates a temp folder and stores path in _MEIPASS + except Exception: + deployed = False + + return deployed def resource_path(relative_path): """Get absolute path to resource, works for dev and for PyInstaller""" @@ -20,6 +28,7 @@ def resource_path(relative_path): path_config = resource_path( "paths.config.json" ) # NOTE: Must have pyflask for running the GUIDE as a whole, but errors for just the server + f = path_config.open() data = json.load(f) GUIDE_ROOT_FOLDER = Path(Path.home(), data["root"])