Skip to content

Commit aaeadd4

Browse files
committed
🚧 allow to set Python Path manually
- manipulate PATH and add logs
1 parent 0c83c9f commit aaeadd4

File tree

2 files changed

+82
-15
lines changed

2 files changed

+82
-15
lines changed

gui/app.py

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
report generation.
2020
"""
2121

22+
import os
2223
import sys
2324
import tkinter as tk
2425
from pathlib import Path
@@ -43,14 +44,18 @@
4344
output_dir = (Path.home() / "vuegen_gen" / "reports").resolve()
4445
print("output_dir:", output_dir)
4546
output_dir.mkdir(exist_ok=True, parents=True)
46-
47+
_PATH = f'{os.environ["PATH"]}'
4748
##########################################################################################
4849
# Path to example data dependend on how the GUI is run
4950
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
5051
# PyInstaller bundeled case
5152
path_to_dat = (
5253
app_path.parent / "example_data/Basic_example_vuegen_demo_notebook"
5354
).resolve()
55+
quarto_bin_path = os.path.join(sys._MEIPASS, "quarto_cli", "bin")
56+
quarto_share_path = os.path.join(sys._MEIPASS, "quarto_cli", "share")
57+
_PATH = os.pathsep.join([quarto_bin_path, quarto_share_path, _PATH])
58+
os.environ["PATH"] = _PATH
5459
elif app_path.parent.name == "gui":
5560
# should be always the case for GUI run from command line
5661
path_to_dat = (
@@ -63,9 +68,10 @@
6368
else:
6469
path_to_dat = "docs/example_data/Basic_example_vuegen_demo_notebook"
6570

66-
71+
print(f"{_PATH = }")
6772
##########################################################################################
6873
# callbacks
74+
# using main entry point of vuegen
6975
# def create_run_vuegen(is_dir, config_path, report_type, run_streamlit):
7076
# def inner():
7177
# args = ["vuegen"]
@@ -88,7 +94,7 @@
8894

8995

9096
def create_run_vuegen(
91-
is_dir, config_path, report_type, run_streamlit, output_dir_entry
97+
is_dir, config_path, report_type, run_streamlit, output_dir_entry, python_dir_entry
9298
):
9399
def inner():
94100
kwargs = {}
@@ -105,7 +111,21 @@ def inner():
105111
kwargs["output_dir"] = output_dir_entry.get()
106112
print("kwargs:")
107113
pprint(kwargs)
114+
# os.environ["PYTHONPATH"] = os.pathsep.join(sys.path)
115+
if python_dir_entry.get():
116+
# os.environ["PYTHONHOME"] = python_dir_entry.get()
117+
os.environ["PATH"] = python_dir_entry.get() + os.pathsep + _PATH
118+
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
119+
os.environ["PATH"] = os.pathsep.join(
120+
[
121+
quarto_bin_path,
122+
quarto_share_path,
123+
python_dir_entry.get(),
124+
_PATH,
125+
]
126+
)
108127
try:
128+
os.chdir(kwargs["output_dir"]) # Change the working directory
109129
# Define logger suffix based on report type and name
110130
logger_suffix = f"{report_type.get()}_report_{str(report_name)}"
111131

@@ -114,6 +134,9 @@ def inner():
114134
f"{logger_suffix}",
115135
folder=(Path(kwargs["output_dir"]) / "logs").as_posix(),
116136
)
137+
kwargs["logger"].info("logfile: %s", log_file)
138+
kwargs["logger"].debug("sys.path: %s", sys.path)
139+
kwargs["logger"].debug("PATH (in app): %s ", os.environ["PATH"])
117140
report_generator.get_report(**kwargs)
118141
messagebox.showinfo(
119142
"Success",
@@ -127,7 +150,6 @@ def inner():
127150
f"An error occurred: {e}\n\n{stacktrace}"
128151
f"\n See logs for more details {log_file}",
129152
)
130-
print_completion_message(report_type.get())
131153

132154
return inner
133155

@@ -155,7 +177,7 @@ def select_directory():
155177
##########################################################################################
156178
# APP
157179
app = customtkinter.CTk()
158-
app.geometry("620x500")
180+
app.geometry("620x600")
159181
app.title("VueGen GUI")
160182

161183
row_count = 0
@@ -206,6 +228,7 @@ def select_directory():
206228
# Report type dropdown
207229
# - get list of report types from Enum
208230
report_types = [report_type.value.lower() for report_type in ReportType]
231+
# report_types = report_types[:2] # only streamlit and html for now
209232
ctk_label_report = customtkinter.CTkLabel(
210233
app,
211234
text="Select type of report to generate (using only streamlit for now)",
@@ -247,14 +270,16 @@ def select_directory():
247270
row_count += 1
248271
##########################################################################################
249272
# output directory selection
250-
# ctk_label_outdir = customtkinter.CTkLabel
273+
ctk_label_outdir = customtkinter.CTkLabel(app, text="Select output directory:")
274+
ctk_label_outdir.grid(row=row_count, column=0, columnspan=1, padx=10, pady=5)
275+
row_count += 1
276+
##########################################################################################
251277
output_dir_entry = tk.StringVar(value=str(output_dir))
252278
select_output_dir = create_select_directory(output_dir_entry)
253279
select_output_dir_button = customtkinter.CTkButton(
254280
app, text="Select Output Directory", command=select_output_dir
255281
)
256-
select_output_dir_button.grid(row=row_count, column=2, columnspan=2, padx=5, pady=10)
257-
282+
select_output_dir_button.grid(row=row_count, column=2, columnspan=1, padx=5, pady=10)
258283
ctk_entry_outpath = customtkinter.CTkEntry(
259284
app,
260285
width=400,
@@ -263,16 +288,54 @@ def select_directory():
263288
ctk_entry_outpath.grid(row=row_count, column=0, columnspan=2, padx=10, pady=10)
264289
row_count += 1
265290
##########################################################################################
266-
ctk_label_appath = customtkinter.CTkLabel(
291+
# Python binary selection
292+
# ctk_label_python = customtkinter.CTkLabel
293+
ctk_label_outdir = customtkinter.CTkLabel(app, text="Select Python binary:")
294+
ctk_label_outdir.grid(row=row_count, column=0, columnspan=1, padx=10, pady=5)
295+
row_count += 1
296+
##########################################################################################
297+
python_dir_entry = tk.StringVar(value="")
298+
select_python_bin = create_select_directory(python_dir_entry)
299+
select_python_bin_button = customtkinter.CTkButton(
300+
app, text="Select Python binary", command=select_python_bin
301+
)
302+
select_python_bin_button.grid(row=row_count, column=2, columnspan=1, padx=5, pady=5)
303+
304+
ctk_entry_python = customtkinter.CTkEntry(
305+
app,
306+
width=400,
307+
textvariable=python_dir_entry,
308+
)
309+
ctk_entry_python.grid(row=row_count, column=0, columnspan=2, padx=10, pady=5)
310+
row_count += 1
311+
##########################################################################################
312+
ctk_label_env_path = customtkinter.CTkLabel(app, text="PATH:")
313+
ctk_label_env_path.grid(row=row_count, column=0, columnspan=1, padx=2, pady=5)
314+
env_path = tk.StringVar(value=os.environ.get("PATH", "not found"))
315+
ctk_entry_path_env = customtkinter.CTkEntry(
267316
app,
268-
text=f"App path: {app_path}",
317+
width=400,
318+
textvariable=env_path,
269319
)
270-
ctk_label_appath.grid(row=row_count, column=0, columnspan=2, padx=20, pady=5)
320+
ctk_entry_path_env.grid(row=row_count, column=1, columnspan=2, padx=10, pady=5)
271321
row_count += 1
272322
##########################################################################################
323+
# ctk_label_appath = customtkinter.CTkLabel(
324+
# app,
325+
# text=f"App path: {app_path}",
326+
# wraplength=600,
327+
# )
328+
# ctk_label_appath.grid(row=row_count, column=0, columnspan=3, padx=10, pady=5)
329+
# row_count += 1
330+
##########################################################################################
273331
# Run VueGen button
274332
run_vuegen = create_run_vuegen(
275-
is_dir, config_path, report_type, run_streamlit, output_dir_entry
333+
is_dir=is_dir,
334+
config_path=config_path,
335+
report_type=report_type,
336+
run_streamlit=run_streamlit,
337+
output_dir_entry=output_dir_entry,
338+
python_dir_entry=python_dir_entry,
276339
)
277340
run_button = customtkinter.CTkButton(
278341
app,

src/vuegen/quarto_reportview.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ def __init__(self, report: r.Report, report_type: r.ReportType):
2424
super().__init__(report=report, report_type=report_type)
2525
self.BUNDLED_EXECUTION = False
2626
self.quarto_path = "quarto"
27+
# self.env_vars = os.environ.copy()
2728
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
2829
self.report.logger.info("running in a PyInstaller bundle")
2930
self.BUNDLED_EXECUTION = True
3031
self.report.logger.debug(f"sys._MEIPASS: {sys._MEIPASS}")
31-
self.quarto_path = str(Path(sys._MEIPASS) / "quarto_cli" / "bin" / "quarto")
3232
else:
3333
self.report.logger.info("running in a normal Python process")
3434

35+
self.report.logger.debug("env_vars (QuartoReport): %s", os.environ)
36+
self.report.logger.debug(f"PATH: {os.environ['PATH']}")
37+
self.report.logger.debug(f"sys.path: {sys.path}")
38+
3539
def generate_report(
3640
self, output_dir: Path = BASE_DIR, static_dir: Path = STATIC_FILES_DIR
3741
) -> None:
@@ -179,11 +183,11 @@ def run_report(self, output_dir: str = BASE_DIR) -> None:
179183
r.ReportType.ODT,
180184
]:
181185
subprocess.run(
182-
[self.quarto_path, "install", "tinytex"],
186+
[self.quarto_path, "install", "tinytex", "--no-prompt"],
183187
check=True,
184188
)
185189
subprocess.run(
186-
[self.quarto_path, "install", "chromium"],
190+
[self.quarto_path, "install", "chromium", "--no-prompt"],
187191
check=True,
188192
)
189193
try:

0 commit comments

Comments
 (0)