Skip to content

Commit a83818f

Browse files
committed
Added packaging support, fixed PyInstaller-compiled GUI opening console window together with GUI.
1 parent 530cb42 commit a83818f

25 files changed

+117
-62
lines changed

.github/workflows/build_executable.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ jobs:
2222
- name: Run PyInstaller for Deserializer, Downloader and Batch Deserializer
2323
run: |
2424
set PYTHONOPTIMIZE=2
25-
pyinstaller --onefile --name="flatc_deserializer" --console --icon=images\flatbuffers-logo-clean.png --add-data="images:images" --add-data="localization:localization" flatc_deserializer.py
26-
pyinstaller --onefile --name="flatc_downloader" --console --icon=images\flatbuffers-downloader-logo-clean.png --add-data="images:images" --add-data="localization:localization" flatc_downloader.py
27-
pyinstaller --onefile --name="flatc_deserializer_batch" --console --icon=images\flatbuffers-batch-logo-clean.png --add-data="images:images" --add-data="localization:localization" flatc_deserializer_batch.py
25+
pyinstaller --onefile --name="flatc_deserializer" --console --icon=src\flatc_deserializer\images\flatbuffers-logo-clean.png --add-data="src\flatc_deserializer\images:images" --add-data="src\flatc_deserializer\localization:localization" deserializer.py
26+
pyinstaller --onefile --name="flatc_downloader" --console --icon=src\flatc_deserializer\images\flatbuffers-downloader-logo-clean.png --add-data="src\flatc_deserializer\images:images" --add-data="src\flatc_deserializer\localization:localization" downloader.py
27+
pyinstaller --onefile --name="flatc_deserializer_batch" --console --icon=src\flatc_deserializer\images\flatbuffers-batch-logo-clean.png --add-data="src\flatc_deserializer\images:images" --add-data="src\flatc_deserializer\localization:localization" deserializer_batch.py
2828
- name: Install additional GUI requirements
2929
run: |
30-
pip install -r requirements_frontend.txt
3130
pip install pywinstyles
3231
- name: Run PyInstaller for GUI
3332
run: |
3433
set PYTHONOPTIMIZE=2
35-
pyinstaller --onefile --noconsole --name="flatc_deserializer_frontend" --console --hiddenimport pywinstyles --icon=images\flatbuffers-logo-clean.png --add-data="images:images" --add-data="localization:localization" flatc_deserializer_frontend.py
34+
pyinstaller --onefile --noconsole --name="flatc_deserializer_frontend" --hiddenimport pywinstyles --icon=src\flatc_deserializer\images\flatbuffers-logo-clean.png --add-data="src\flatc_deserializer\images:images" --add-data="src\flatc_deserializer\localization:localization" deserializer_frontend.py
3635
- name: Move Executables from dist to root directory and delete dist directory
3736
run: |
3837
move dist\flatc_deserializer.exe .

.github/workflows/build_executable_nuitka.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,52 @@ jobs:
2323
uses: Nuitka/Nuitka-Action@main
2424
with:
2525
nuitka-version: main
26-
script-name: flatc_deserializer.py
26+
script-name: src/flatc_deserializer/deserializer.py
27+
output-file: flatc_deserializer
2728
mode: app
2829
enable-plugins: tk-inter
2930
include-data-dir: |
30-
localization=localization
31-
images=images
32-
windows-icon-from-ico: images/flatbuffers-logo-clean.png
31+
src/flatc_deserializer/localization=localization
32+
src/flatc_deserializer/images=images
33+
windows-icon-from-ico: src/flatc_deserializer/images/flatbuffers-logo-clean.png
3334
- name: Run Nuitka for Downloader
3435
uses: Nuitka/Nuitka-Action@main
3536
with:
3637
nuitka-version: main
37-
script-name: flatc_downloader.py
38+
script-name: src/flatc_deserializer/downloader.py
39+
output-file: flatc_downloader
3840
mode: app
3941
enable-plugins: tk-inter
4042
include-data-dir: |
41-
localization=localization
42-
images=images
43-
windows-icon-from-ico: images/flatbuffers-downloader-logo-clean.png
43+
src/flatc_deserializer/localization=localization
44+
src/flatc_deserializer/images=images
45+
windows-icon-from-ico: src/flatc_deserializer/images/flatbuffers-downloader-logo-clean.png
4446
- name: Run Nuitka for Batch Deserializer
4547
uses: Nuitka/Nuitka-Action@main
4648
with:
4749
nuitka-version: main
48-
script-name: flatc_deserializer_batch.py
50+
script-name: src/flatc_deserializer/deserializer_batch.py
51+
output-file: flatc_deserializer_batch
4952
mode: app
5053
enable-plugins: tk-inter
5154
include-data-dir: |
52-
localization=localization
53-
images=images
54-
windows-icon-from-ico: images/flatbuffers-batch-logo-clean.png
55-
- name: Install additional GUI requirements
56-
run: |
57-
pip install -r requirements_frontend.txt
58-
pip install pywinstyles
55+
src/flatc_deserializer/localization=localization
56+
src/flatc_deserializer/images=images
57+
windows-icon-from-ico: src/flatc_deserializer/images/flatbuffers-batch-logo-clean.png
5958
- name: Run Nuitka for GUI
6059
uses: Nuitka/Nuitka-Action@main
6160
with:
6261
nuitka-version: main
63-
script-name: flatc_deserializer_frontend.py
62+
script-name: src/flatc_deserializer/deserializer_frontend.py
63+
output-file: flatc_deserializer_frontend
6464
mode: app
6565
windows-console-mode: disable
6666
enable-plugins: tk-inter
6767
include-package: pywinstyles
6868
include-data-dir: |
69-
localization=localization
70-
images=images
71-
windows-icon-from-ico: images/flatbuffers-logo-clean.png
69+
src/flatc_deserializer/localization=localization
70+
src/flatc_deserializer/images=images
71+
windows-icon-from-ico: src/flatc_deserializer/images/flatbuffers-logo-clean.png
7272
- name: Move Executables from build to root directory
7373
run: |
7474
move build\flatc_deserializer.exe .

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
graft src/flatc_deserializer/images
2+
graft src/flatc_deserializer/localization

README.MD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Set of console tools and single combined GUI for the following:
1111
### GUI only:
1212
- [customtkinter](https://pypi.org/project/customtkinter/)
1313
- [CTkMenuBar](https://pypi.org/project/CTkMenuBar/)
14-
- [CTkMessagebox](https://pypi.org/project/CTkMessagebox/)
14+
#### Optional (Windows only):
15+
- [pywinstyles](https://pypi.org/project/pywinstyles/) - adds drag-and-drop support.
1516
## Latest Windows releases:
1617
- [PyInstaller](https://github.com/Shararamosh/flatc_deserializer/releases/tag/latest)
1718
- [Nuitka](https://github.com/Shararamosh/flatc_deserializer/releases/tag/latest-nuitka)

pyproject.toml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
14
[project]
25
name="flatc_deserializer"
36
dynamic = ["version"]
7+
requires-python = ">= 3.11"
48
dependencies = [
59
"pillow",
610
"tqdm",
7-
"i18nice[YAML]"
11+
"i18nice[YAML]",
12+
"customtkinter",
13+
"CTkMenuBar",
14+
"pywinstyles; os_name == 'nt'"
815
]
916
authors = [{name = "Shararamosh"}]
10-
description = "Program for deserialization of Flatbuffers binary files based on single or multiple schemas."
17+
description = "Console and GUI apps for deserialization of Flatbuffers binary files based on single or multiple schemas."
1118
keywords = [
1219
"json",
1320
"flatbuffers",
@@ -22,10 +29,20 @@ classifiers = [
2229
"Development Status :: 5 - Production/Stable",
2330
"Environment :: Console",
2431
"Intended Audience :: Developers",
32+
"Intended Audience :: End Users/Desktop",
2533
"Natural Language :: English",
2634
"Natural Language :: Russian",
2735
"Operating System :: OS Independent",
28-
"Programming Language :: Python",
36+
"Programming Language :: Python :: 3.11",
2937
"Topic :: File Formats :: JSON",
3038
"Topic :: Utilities"
3139
]
40+
readme = "README.MD"
41+
[project.urls]
42+
Repository = "https://github.com/Shararamosh/flatc_deserializer.git"
43+
[project.scripts]
44+
flatc_downloader = "flatc_deserializer.downloader:main"
45+
flatc_deserializer = "flatc_deserializer.deserializer:main"
46+
flatc_deserializer_batch = "flatc_deserializer.deserializer_batch:main"
47+
[project.gui-scripts]
48+
flatc_deserializer_frontend = "flatc_deserializer.deserializer_frontend:main"

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pillow
22
tqdm
33
i18nice[YAML]
4-
future
5-
argparse
4+
customtkinter
5+
CTkMenuBar
6+
pywinstyles; os_name == 'nt'

requirements_frontend.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

flatc_deserializer.py renamed to src/flatc_deserializer/deserializer.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
import argparse
88
from i18n import t
99

10-
from main import init_app, get_flatc_path, execute_deserialize
10+
from flatc_deserializer.general_funcs import init_app, get_flatc_path, execute_deserialize
1111

12-
if __name__ == "__main__":
13-
init_app("images/flatbuffers-logo-clean.png")
12+
13+
def main() -> int | str:
14+
"""
15+
Запуск скрипта.
16+
:return: Код ошибки или строка об ошибке.
17+
"""
18+
init_app(os.path.join("images", "flatbuffers-logo-clean.png"))
1419
parser = argparse.ArgumentParser(prog=t("main.flatc_deserializer_name"),
1520
description=t("main.flatc_deserializer_desc"))
1621
parser.add_argument("-s", "--schema_path", type=str, default="", help=t("main.schema_file_arg"))
@@ -20,6 +25,10 @@
2025
help=t("main.output_directory_arg"))
2126
parser.add_argument("-f", "--flatc_path", type=str, default="", help=t("main.flatc_path_arg"))
2227
args = parser.parse_args()
23-
sys.exit(execute_deserialize(
28+
return execute_deserialize(
2429
get_flatc_path(os.getcwd(), True, False) if args.flatc_path == "" else args.flatc_path,
25-
args.schema_path, args.binary_paths, args.output_path))
30+
args.schema_path, args.binary_paths, args.output_path)
31+
32+
33+
if __name__ == "__main__":
34+
sys.exit(main())

flatc_deserializer_batch.py renamed to src/flatc_deserializer/deserializer_batch.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
import argparse
99
from i18n import t
1010

11-
from main import init_app, get_flatc_path, execute_deserialize_batch
11+
from flatc_deserializer.general_funcs import init_app, get_flatc_path, execute_deserialize_batch
1212

13-
if __name__ == "__main__":
14-
init_app("images/flatbuffers-batch-logo-clean.png")
13+
14+
def main() -> int | str:
15+
"""
16+
Запуск скрипта.
17+
:return: Код ошибки или строка об ошибке.
18+
"""
19+
init_app(os.path.join("images", "flatbuffers-batch-logo-clean.png"))
1520
parser = argparse.ArgumentParser(prog=t("main.flatc_deserializer_batch_name"),
1621
description=t("main.flatc_deserializer_batch_desc"))
1722
parser.add_argument("-s", "--schemas_path", type=str, default="",
@@ -22,6 +27,10 @@
2227
help=t("main.output_directory_arg"))
2328
parser.add_argument("-f", "--flatc_path", type=str, default="", help=t("main.flatc_path_arg"))
2429
args = parser.parse_args()
25-
sys.exit(execute_deserialize_batch(
30+
return execute_deserialize_batch(
2631
get_flatc_path(os.getcwd(), True, False) if args.flatc_path == "" else args.flatc_path,
27-
args.schemas_path, args.binaries_path, args.output_path))
32+
args.schemas_path, args.binaries_path, args.output_path)
33+
34+
35+
if __name__ == "__main__":
36+
sys.exit(main())

flatc_deserializer_frontend.py renamed to src/flatc_deserializer/deserializer_frontend.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
# pylint: disable=import-error
55
import os
66
import sys
7-
import tkinter.filedialog
87
from collections.abc import Callable
98
from importlib import import_module
10-
from tkinter import ttk, messagebox
9+
from tkinter import ttk, messagebox, filedialog
1110

1211
from PIL.ImageTk import PhotoImage
1312
from PIL import Image
@@ -16,9 +15,9 @@
1615
from customtkinter import CTk, CTkFrame, CTkButton, CTkImage, NSEW, EW, RIGHT
1716
from CTkMenuBar import CTkMenuBar
1817

19-
from main import init_localization, get_resource_path, execute_download, get_flatc_path, \
20-
get_binary_tuples
21-
from flatc_funcs import deserialize
18+
from flatc_deserializer.general_funcs import init_localization, get_resource_path, \
19+
execute_download, get_flatc_path, get_binary_tuples
20+
from flatc_deserializer.flatc_funcs import deserialize
2221

2322

2423
def attempt_apply_dnd(widget_id: int, dnd_event: Callable):
@@ -53,7 +52,7 @@ def __init__(self):
5352
self.geometry(f"{width}x{height}")
5453
self.title(t("main.flatc_deserializer_name"))
5554
self.wm_iconbitmap()
56-
img = Image.open(get_resource_path("images/flatbuffers-logo-clean.png"))
55+
img = Image.open(get_resource_path(os.path.join("images", "flatbuffers-logo-clean.png")))
5756
self.iconphoto(True, PhotoImage(img))
5857
self._create_top_menu()
5958
main_frame = self._create_main_frame()
@@ -72,7 +71,8 @@ def _create_top_menu(self) -> CTkMenuBar:
7271
:return: Created menu.
7372
"""
7473
top_menu = CTkMenuBar(self, bg_color=None)
75-
img = Image.open(get_resource_path("images/flatbuffers-downloader-logo-clean.png"))
74+
img = Image.open(
75+
get_resource_path(os.path.join("images", "flatbuffers-downloader-logo-clean.png")))
7676
flatc_button = top_menu.add_cascade(image=CTkImage(img))
7777
flatc_button.configure(text=t("frontend.download_flatc"))
7878
flatc_button.configure(command=self.flatc_button_pressed)
@@ -241,7 +241,8 @@ def _create_bottom_menu(self) -> CTkMenuBar:
241241
:return: Created menu.
242242
"""
243243
bottom_menu = CTkMenuBar(self, bg_color=None)
244-
img = Image.open(get_resource_path("images/flatbuffers-batch-logo-clean.png"))
244+
img = Image.open(
245+
get_resource_path(os.path.join("images", "flatbuffers-batch-logo-clean.png")))
245246
deserialize_button = bottom_menu.add_cascade(image=CTkImage(img))
246247
deserialize_button.configure(text=t("frontend.deserialize"))
247248
deserialize_button.configure(command=self.deserialize_button_pressed)
@@ -259,7 +260,7 @@ def on_binary_add_click(self):
259260
"""
260261
Triggered when "Add..." button is clicked.
261262
"""
262-
binary_paths = tkinter.filedialog.askopenfilenames(title=t("main.tkinter_binaries_select"))
263+
binary_paths = filedialog.askopenfilenames(title=t("main.tkinter_binaries_select"))
263264
if binary_paths is not None:
264265
self.on_binary_dropped(binary_paths)
265266

@@ -288,7 +289,7 @@ def on_schema_add_click(self):
288289
"""
289290
Triggered when "Add..." button is clicked.
290291
"""
291-
schema_paths = tkinter.filedialog.askopenfilenames(
292+
schema_paths = filedialog.askopenfilenames(
292293
title=t("main.tkinter_fbs_multiple_select"),
293294
filetypes=[(t("main.fbs_filetype"), "*.fbs")])
294295
if schema_paths is not None:
@@ -319,7 +320,7 @@ def on_change_dest_click(self):
319320
for selected_item in selected_items:
320321
file_path = self.dest_binaries_table.set(selected_item, 0)
321322
file_dir, file_name = os.path.split(file_path)
322-
new_file_path = tkinter.filedialog.asksaveasfilename(
323+
new_file_path = filedialog.asksaveasfilename(
323324
title=t("main.save_selected_file"),
324325
defaultextension=".json",
325326
initialdir=file_dir, initialfile=file_name,
@@ -456,8 +457,17 @@ def _deserialize_and_update_table(self, flatc_path: str, schema_path: str, binar
456457
self.dest_binaries_table.update()
457458

458459

459-
if __name__ == "__main__":
460+
def main() -> str | int:
461+
"""
462+
Launching script.
463+
:return: Error code or string with error.
464+
"""
460465
init_localization()
461466
ctk.set_appearance_mode("System")
462467
ctk.set_default_color_theme("blue")
463468
Deserializer().mainloop()
469+
return os.EX_OK
470+
471+
472+
if __name__ == "__main__":
473+
sys.exit(main())
File renamed without changes.

flatc_downloader.py renamed to src/flatc_deserializer/downloader.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@
77
import argparse
88
from i18n import t
99

10-
from main import init_app, execute_download
10+
from flatc_deserializer.general_funcs import init_app, execute_download
1111

12-
if __name__ == "__main__":
13-
init_app("images/flatbuffers-downloader-logo-clean.png")
12+
13+
def main() -> int | str:
14+
"""
15+
Запуск скрипта.
16+
:return: Код ошибки или строка с ошибкой.
17+
"""
18+
init_app(os.path.join("images", "flatbuffers-downloader-logo-clean.png"))
1419
parser = argparse.ArgumentParser(prog=t("main.flatc_downloader_name"),
1520
description=t("main.flatc_downloader_desc"))
1621
parser.add_argument("downloads_directory", nargs="?", type=str, default=os.getcwd(),
1722
help=t("main.download_directory_arg"))
1823
args = parser.parse_args()
19-
sys.exit(execute_download(args.downloads_directory))
24+
return execute_download(args.downloads_directory)
25+
26+
27+
if __name__ == "__main__":
28+
sys.exit(main())
File renamed without changes.

main.py renamed to src/flatc_deserializer/general_funcs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
from tqdm import tqdm
1919
from tqdm.contrib.logging import logging_redirect_tqdm
2020

21-
from flatc_download_funcs import download_flatc
22-
from flatc_funcs import deserialize
21+
from flatc_deserializer.download_funcs import download_flatc
22+
from flatc_deserializer.flatc_funcs import deserialize
2323

2424

2525
def get_resource_path(file_path: str) -> str:
@@ -33,7 +33,7 @@ def get_resource_path(file_path: str) -> str:
3333
elif hasattr(sys, "_MEIPASS"):
3434
base_path = getattr(sys, "_MEIPASS")
3535
else:
36-
base_path = os.path.abspath(".")
36+
base_path = os.path.dirname(__file__)
3737
return os.path.join(base_path, file_path)
3838

3939

0 commit comments

Comments
 (0)