Skip to content

Commit

Permalink
Allow access to data files when running in a frozen environment (eg.…
Browse files Browse the repository at this point in the history
… PyInstaller executable). #152
  • Loading branch information
fabiocaccamo committed Feb 15, 2024
1 parent 842be28 commit 107348f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions codicefiscale/data.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
from __future__ import annotations

import os
import sys
from datetime import datetime
from typing import Any

import fsutil


def get_data_basedir() -> str:
if getattr(sys, "frozen", False):
# standalone executable (eg. PyInstaller)
return os.path.dirname(sys.executable)
return __file__


def get_data(filename: str) -> Any:
return fsutil.read_file_json(fsutil.join_path(__file__, f"data/{filename}"))
return fsutil.read_file_json(
fsutil.join_path(get_data_basedir(), f"data/{filename}")
)


def get_municipalities_data() -> Any:
Expand Down

0 comments on commit 107348f

Please sign in to comment.