Skip to content

Commit

Permalink
Added (hopefully) correct relative resource path handling for Nuitka …
Browse files Browse the repository at this point in the history
…and README.MD, updated localization.
  • Loading branch information
Shararamosh committed Oct 29, 2024
1 parent 45e864d commit b26849e
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_executable.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Windows Executables
name: Build Windows Executables with PyInstaller
permissions: write-all
on:
push:
Expand All @@ -14,7 +14,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: 3.11
- name: Install requirements
run: pip install -r requirements.txt
- name: Install PyInstaller
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/build_executable_nuitka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: 3.11
- name: Install requirements
run: |
pip install -r requirements.txt
Expand All @@ -27,9 +27,9 @@ jobs:
onefile: true
enable-plugins: tk-inter
include-data-dir: |
.\localization=localization
.\images=images
windows-icon-from-ico: "images/flatbuffers-logo-clean.png"
localization=localization
images=images
windows-icon-from-ico: images/flatbuffers-logo-clean.png
- name: Run Nuitka for Downloader
uses: Nuitka/Nuitka-Action@main
with:
Expand All @@ -38,9 +38,9 @@ jobs:
onefile: true
enable-plugins: tk-inter
include-data-dir: |
.\localization=localization
.\images=images
windows-icon-from-ico: "images/flatbuffers-downloader-logo-clean.png"
localization=localization
images=images
windows-icon-from-ico: images/flatbuffers-downloader-logo-clean.png
- name: Run Nuitka for Batch Deserializer
uses: Nuitka/Nuitka-Action@main
with:
Expand All @@ -49,9 +49,9 @@ jobs:
onefile: true
enable-plugins: tk-inter
include-data-dir: |
.\localization=localization
.\images=images
windows-icon-from-ico: "images/flatbuffers-batch-logo-clean.png"
localization=localization
images=images
windows-icon-from-ico: images/flatbuffers-batch-logo-clean.png
- name: Move Executables from build to root directory
run: |
move build\flatc_deserializer.exe .
Expand Down
10 changes: 10 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Flatbuffers Deserializer
Set of console tools for batch deserialization of Flatbuffers binary files using pre-defined schemas and downloading latest version of Flatbuffers schema compiler written in Python.
## Requirements:
- [Python 3.11+](https://www.python.org/)
- [Pillow](https://pypi.org/project/pillow/)
- [tqdm](https://pypi.org/project/tqdm/)
- [i18nice[YAML]](https://pypi.org/project/i18nice/)
## Latest Windows releases:
- [PyInstaller](releases/tag/latest)
- [Nuitka](releases/tag/latest-nuitka)
1 change: 0 additions & 1 deletion flatc_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from main import init_app, get_flatc_path, execute_deserialize

if __name__ == "__main__":
sys.tracebacklimit = 0
init_app("images/flatbuffers-logo-clean.png")
parser = argparse.ArgumentParser(prog=t("main.flatc_deserializer_name"),
description=t("main.flatc_deserializer_desc"))
Expand Down
1 change: 0 additions & 1 deletion flatc_deserializer_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from main import init_app, get_flatc_path, execute_deserialize_batch

if __name__ == "__main__":
sys.tracebacklimit = 0
init_app("images/flatbuffers-batch-logo-clean.png")
parser = argparse.ArgumentParser(prog=t("main.flatc_deserializer_batch_name"),
description=t("main.flatc_deserializer_batch_desc"))
Expand Down
1 change: 0 additions & 1 deletion flatc_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from main import init_app, execute_download

if __name__ == "__main__":
sys.tracebacklimit = 0
init_app("images/flatbuffers-downloader-logo-clean.png")
parser = argparse.ArgumentParser(prog=t("main.flatc_downloader_name"),
description=t("main.flatc_downloader_desc"))
Expand Down
10 changes: 5 additions & 5 deletions localization/en_US/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ tkinter_binaries_select: Select binary files
flatc_binary_filetype: Binary Flatbuffers file
tkinter_output_select: Select output directory
files: Files
unsupported_platform: "%s platform is not supported."
unsupported_platform: %s platform is not supported.
executable_not_found: Executable %s not found.
file_not_found: File %s not found.
directory_not_found: Directory %s not found.
file_removed: File %s is removed.
flatc_already_exists: Flatbuffers schema compiler already exists in directory %s.
file_not_executable: File is not executable
file_not_executable: File %s is not executable.
tkinter_fbs_directory_select: Select directory with schema files
tkinter_binary_directory_select: Select directory with binary files
no_schema_files_found: No schema files found in directory %s.
Expand All @@ -23,12 +23,12 @@ schema_file_arg: Schema file
binary_files_arg: Binary files
flatc_path_arg: Path to schema compiler (flatc)
flatc_deserializer_name: Flatbuffers Deserializer
flatc_deserializer_desc: Program for deserialization of Flatbuffers binary files based on single schema.
flatc_deserializer_desc: Tool for deserialization of Flatbuffers binary files based on single schema.
flatc_deserializer_batch_name: Flatbuffers Batch Deserializer
flatc_deserializer_batch_desc: Program for deserialization of Flatbuffers binary files based on multiple schemas.
flatc_deserializer_batch_desc: Tool for deserialization of Flatbuffers binary files based on multiple schemas.
file_failed_to_open: Failed to open file %s.
flatc_downloader_name: Flatbuffers Schema Compiler Downloader
flatc_downloader_desc: Program for downloading latest version of Flatbuffers schema compiler for this platform.
flatc_downloader_desc: Tool for downloading latest version of Flatbuffers schema compiler for this platform.
download_directory_arg: Directory for saving downloaded files
no_files_selected: No files were selected.
no_directory_selected: No directory was selected.
Expand Down
10 changes: 5 additions & 5 deletions localization/ru_RU/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ tkinter_binaries_select: Выбор бинарных файлов
flatc_binary_filetype: Бинарный файл Flatbuffers
tkinter_output_select: Выбор директории вывода
files: Файлы
unsupported_platform: "Платформа %s не поддерживается."
unsupported_platform: Платформа %s не поддерживается.
executable_not_found: Исполняемый файл %s не найден.
file_not_found: Файл %s не найден.
directory_not_found: Директория %s не найдена.
file_removed: Файл %s был удалён.
flatc_already_exists: Компилятор схемы Flatbuffers уже существует в директории %s.
file_not_executable: Файл не является исполняемым
file_not_executable: Файл %s не является исполняемым.
tkinter_fbs_directory_select: Выбор директории с файлами схем
tkinter_binary_directory_select: Выбор директории с бинарными файлами
no_schema_files_found: Файлы схем не были найдены в директории %s.
Expand All @@ -23,12 +23,12 @@ schema_file_arg: Файл схемы
binary_files_arg: Бинарные файлы
flatc_path_arg: Путь к компилятору схемы (flatc)
flatc_deserializer_name: Flatbuffers Deserializer
flatc_deserializer_desc: Программа для десериализации бинарных файлов Flatbuffers, основанных на одной схеме.
flatc_deserializer_desc: Утилита для десериализации бинарных файлов Flatbuffers, основанных на одной схеме.
flatc_deserializer_batch_name: Flatbuffers Batch Deserializer
flatc_deserializer_batch_desc: Программа для десериализации бинарных файлов Flatbuffers, основанных на нескольких схемах.
flatc_deserializer_batch_desc: Утилита для десериализации бинарных файлов Flatbuffers, основанных на нескольких схемах.
file_failed_to_open: Не удалось открыть файл %s.
flatc_downloader_name: Flatbuffers Schema Compiler Downloader
flatc_downloader_desc: Программа для скачивания последней версии компилятора схемы Flatbuffers для данной платформы.
flatc_downloader_desc: Утилита для скачивания последней версии компилятора схемы Flatbuffers для данной платформы.
download_directory_arg: Директория для сохранения скачанных файлов
no_files_selected: Файлы не были выбраны.
no_directory_selected: Директория не была выбрана.
Expand Down
17 changes: 11 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,27 @@
from flatc_funcs import deserialize


def get_resource_path(filename: str) -> str:
def get_resource_path(file_path: str) -> str:
"""
Получение пути к файлу или директории, если используется PyInstaller.
:param filename: Изначальный путь к файлу или директории.
Получение пути к файлу или директории внутри проекта, если используется PyInstaller или Nuitka.
:param file_path: Изначальный путь к файлу или директории.
:return: Изменённый путь к файлу или директории.
"""
if hasattr(sys, "_MEIPASS"):
return os.path.join(getattr(sys, "_MEIPASS"), filename)
return filename
if "NUITKA_ONEFILE_PARENT" in os.environ:
base_path = os.path.dirname(sys.executable)
elif hasattr(sys, "_MEIPASS"):
base_path = getattr(sys, "_MEIPASS")
else:
base_path = os.path.abspath(".")
return os.path.join(base_path, file_path)


def init_app(icon_path: str):
"""
Инициализация приложения (логирование, локализация, модуль Tkinter).
:param icon_path: Путь к иконке для диалоговых окон Tkinter.
"""
sys.tracebacklimit = 0
init_logging()
init_localization()
init_tkinter(icon_path)
Expand Down

0 comments on commit b26849e

Please sign in to comment.