Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to data files when running in a frozen environment (eg. executable). #152

Closed
fabiocaccamo opened this issue Jan 30, 2024 Discussed in #151 · 1 comment
Closed
Assignees
Labels
enhancement New feature or request

Comments

@fabiocaccamo
Copy link
Owner

fabiocaccamo commented Jan 30, 2024

Discussed in #151

Originally posted by goldelay January 30, 2024
Ciao Fabio, per poter accedere alle informazioni data/municipalities.json etc... su una build eseguibile effettuata con pyinstaller ho dovuto modificare il codice di data.py applicando questa fix:

from __future__ import annotations

from datetime import datetime
from typing import Any

import fsutil

import sys, os


def get_temp_dir():
    if getattr(sys, 'frozen', False):
        # Se l'applicazione è un eseguibile standalone
        return os.path.dirname(sys.executable)
    else:
        # Se l'applicazione è eseguita come script Python
        return os.path.dirname(os.path.abspath(__file__))


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

la function get_temp_dir() serve ovviamente a dirottare le chiamate per caricare i file dalla cartella del componente di python alla root dell'esegiubile nel momento in cui è un eseguibile.

In questo modo copiando la cartella .\data*.json contenuta dentro al tuo componente dentro la root dell'applicazione EXE permette di funzionare riuscendo così ad elaborare i dati per generare e verificare il codice fiscale al di fuori quindi del contesto python/componente.

Spero di esser stato d'aiuto

Saluti
Umberto Neri

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@fabiocaccamo fabiocaccamo added the enhancement New feature or request label Jan 30, 2024
@fabiocaccamo fabiocaccamo self-assigned this Jan 30, 2024
@fabiocaccamo fabiocaccamo moved this to Todo in Open Source Jan 30, 2024
fabiocaccamo added a commit that referenced this issue Feb 15, 2024
@fabiocaccamo
Copy link
Owner Author

@goldelay fixed in 0.9.1 version.

@github-project-automation github-project-automation bot moved this from Todo to Done in Open Source Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

1 participant