Skip to content

Commit

Permalink
add pyinstaller support (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz87 authored Jun 1, 2022
1 parent ca88b5c commit 19d3c23
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion schwifty/registry.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import itertools
import json
import pathlib
import sys
from collections import defaultdict
from typing import Any
from typing import Callable
from typing import Dict
from typing import List
from typing import Tuple
from typing import Union
from pathlib import Path


try:
from importlib.abc import Traversable
from importlib.resources import files
except ImportError:
from importlib_resources import files # type: ignore
from importlib_resources.abc import Traversable # type: ignore


_registry: Dict[str, Union[Dict, List[Dict]]] = {}
Expand Down Expand Up @@ -41,7 +45,12 @@ def has(name: str) -> bool:
def get(name: str) -> Union[Dict, List[Dict]]:
if not has(name):
data = None
directory = files(__package__) / f"{name}_registry"
package_path: Union[Traversable, Path]
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
package_path = Path(getattr(sys, "_MEIPASS"))
else:
package_path = files(__package__)
directory = package_path / f"{name}_registry"
assert isinstance(directory, pathlib.Path)
for entry in sorted(directory.glob("*.json")):
with entry.open(encoding="utf-8") as fp:
Expand Down

0 comments on commit 19d3c23

Please sign in to comment.