Skip to content

Commit 2f86c1e

Browse files
committed
✨ cache python exectutable set previously
- only require users to setup python environment once - 📝 start describing how to use bundled app
1 parent 0c85974 commit 2f86c1e

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

gui/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,18 @@ Windows and macOS specific options:
7676
- maybe a self-contained minimal virtual environment for kernel starting can be added later
7777
- we could add some logic to make sure a correct path is added.
7878
79-
### Create environment using conda
79+
## Using bundle vuegen release
80+
81+
## On Windows
82+
83+
- global quarto and python installations can be used
84+
- quarto can be shipped with app, but maybe it can be deactivated
85+
86+
## On MacOs
87+
88+
- on MacOs the default paths are not set
89+
90+
#### Create environment using conda
8091
8192
```bash
8293
conda create -n vuegen_gui -c conda-forge python=3.12 jupyter
@@ -95,7 +106,7 @@ In the app, set the python environment path to this location, but to the `bin` f
95106
/Users/user/miniforge3/envs/vuegen_gui/bin
96107
```
97108
98-
### virtualenv
109+
#### virtualenv
99110
100111
- tbc
101112

gui/app.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from tkinter import filedialog, messagebox
2929

3030
import customtkinter
31+
import yaml
3132
from PIL import Image
3233

3334
from vuegen import report_generator
@@ -45,6 +46,15 @@
4546
print("output_dir:", output_dir)
4647
output_dir.mkdir(exist_ok=True, parents=True)
4748
_PATH = f'{os.environ["PATH"]}'
49+
### config path for app
50+
config_file = Path(Path.home() / ".vuegen_gui" / "config.yaml").resolve()
51+
if not config_file.exists():
52+
config_file.parent.mkdir(exist_ok=True, parents=True)
53+
config_app = dict(python_dir_entry="")
54+
else:
55+
with open(config_file, "r", encoding="utf-8") as f:
56+
config_app = yaml.safe_load(f)
57+
hash_config_app = hash(yaml.dump(config_app))
4858
##########################################################################################
4959
# Path to example data dependend on how the GUI is run
5060
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
@@ -104,6 +114,8 @@ def inner():
104114
pprint(kwargs)
105115

106116
if python_dir_entry.get():
117+
if python_dir_entry.get() != config_app["python_dir_entry"]:
118+
config_app["python_dir_entry"] = python_dir_entry.get()
107119
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
108120
os.environ["PATH"] = os.pathsep.join(
109121
[
@@ -141,7 +153,12 @@ def inner():
141153
f"\n\nReport in folder:\n{report_dir}"
142154
f"\n\nConfiguration file at:\n{gen_config_path}",
143155
)
156+
global hash_config_app # ! fix this
144157
print_completion_message(report_type.get())
158+
if hash(yaml.dump(config_app)) != hash_config_app:
159+
with open(config_file, "w", encoding="utf-8") as f:
160+
yaml.dump(config_app, f)
161+
hash_config_app = hash(yaml.dump(config_app))
145162
except Exception as e:
146163
stacktrace = traceback.format_exc()
147164
messagebox.showerror(
@@ -305,7 +322,7 @@ def select_directory():
305322
ctk_label_outdir.grid(row=row_count, column=0, columnspan=1, padx=10, pady=5)
306323
row_count += 1
307324
##########################################################################################
308-
python_dir_entry = tk.StringVar(value="")
325+
python_dir_entry = tk.StringVar(value=config_app["python_dir_entry"])
309326
select_python_bin = create_select_directory(python_dir_entry)
310327
select_python_bin_button = customtkinter.CTkButton(
311328
app, text="Select Python binary", command=select_python_bin

0 commit comments

Comments
 (0)