Skip to content

Commit

Permalink
ENH: set local path based on whether pyinstaller is running (#4)
Browse files Browse the repository at this point in the history
* set _here based on whether we are in pyinstaller runtime

* add schemas into the installed binary

* wrap --add-data arg in quotes for windows build

* remove debugging line

* convert a print statement to warning
  • Loading branch information
kaczmarj authored Jun 21, 2023
1 parent a35f863 commit 0f62e0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-binary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
with:
python-version: 3.9
- run: python -m pip install . pyinstaller
- run: pyinstaller --onefile --name wsinfer_zoo-win64 wsinfer_zoo/__main__.py
- run: ./dist/wsinfer_zoo-win64 --help
- run: pyinstaller --onefile --name wsinfer-zoo-win64 --add-data "wsinfer_zoo/schemas;schemas" wsinfer_zoo/__main__.py
- run: ./dist/wsinfer-zoo-win64 --help
- uses: actions/upload-artifact@v2
with:
path: dist/*
Expand All @@ -39,8 +39,8 @@ jobs:
with:
python-version: 3.9
- run: python -m pip install . pyinstaller
- run: pyinstaller --onefile --name wsinfer_zoo-MacOSX-x86_64 wsinfer_zoo/__main__.py
- run: ./dist/wsinfer_zoo-MacOSX-x86_64 --help
- run: pyinstaller --onefile --name wsinfer-zoo-MacOSX-x86_64 --add-data wsinfer_zoo/schemas:schemas wsinfer_zoo/__main__.py
- run: ./dist/wsinfer-zoo-MacOSX-x86_64 --help
- uses: actions/upload-artifact@v2
with:
path: dist/*
11 changes: 9 additions & 2 deletions wsinfer_zoo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import json
from datetime import datetime
from pathlib import Path
import sys
from typing import Any, Dict, List, Optional, Sequence
import warnings

import jsonschema
import requests
Expand All @@ -24,7 +26,12 @@
# The path to the registry file.
WSINFER_ZOO_REGISTRY_DEFAULT_PATH = Path.home() / ".wsinfer-zoo-registry.json"

_here = Path(__file__).parent.resolve()
# In pyinstaller runtime for one-file executables, the root path
# is the path to the executable.
if getattr(sys, "frozen", False) and getattr(sys, "_MEIPASS", False):
_here = Path(sys._MEIPASS).resolve() # type: ignore
else:
_here = Path(__file__).parent.resolve()


class WSInferZooException(Exception):
Expand Down Expand Up @@ -307,4 +314,4 @@ def _download_registry_if_necessary():
r = requests.get(WSINFER_ZOO_REGISTRY_URL)
WSINFER_ZOO_REGISTRY_DEFAULT_PATH.write_bytes(r.content)
except requests.RequestException as e:
print(f"Could not download most recent registry, error: {e}")
warnings.warn(f"Could not download most recent registry, error: {e}")

0 comments on commit 0f62e0d

Please sign in to comment.