Skip to content

Commit

Permalink
CHORE: Auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
For more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 30, 2025
1 parent b911f8d commit 2ca4d8e
Showing 1 changed file with 60 additions and 56 deletions.
116 changes: 60 additions & 56 deletions src/ansys/aedt/core/workflows/project/version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@
import ansys.aedt.core as pyaedt
from ansys.aedt.core.workflows.customize_automation_tab import add_script_to_menu
from ansys.aedt.core.workflows.customize_automation_tab import available_toolkits
from ansys.aedt.core.workflows.misc import ExtensionTheme
from ansys.aedt.core.workflows.misc import get_aedt_version
from ansys.aedt.core.workflows.misc import get_port
from ansys.aedt.core.workflows.misc import get_process_id
from ansys.aedt.core.workflows.misc import ExtensionTheme

import pyedb
import requests

Check warning on line 48 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L40-L48

Added lines #L40 - L48 were not covered by tests

Expand Down Expand Up @@ -119,12 +118,14 @@ def __init__(self, ui, desktop, aedt_version, personal_lib):
self.style = ttk.Style()

Check warning on line 118 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L118

Added line #L118 was not covered by tests

# Define the custom style for TLabel (ttk.Label)
self.style.configure("PyAEDT",
font=("Helvetica", 14, "bold"), # Font style: Helvetica, size 14, bold
foreground="darkblue", # Text color
background="lightyellow", # Background color
padding=(10, 5), # Padding inside the label
anchor="w")
self.style.configure(

Check warning on line 121 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L121

Added line #L121 was not covered by tests
"PyAEDT",
font=("Helvetica", 14, "bold"), # Font style: Helvetica, size 14, bold
foreground="darkblue", # Text color
background="lightyellow", # Background color
padding=(10, 5), # Padding inside the label
anchor="w",
)
self.theme = ExtensionTheme()

Check warning on line 129 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L129

Added line #L129 was not covered by tests

self.theme.apply_light_theme(self.style)
Expand All @@ -150,7 +151,7 @@ def __init__(self, ui, desktop, aedt_version, personal_lib):
main_frame.pack(fill=tk.BOTH, expand=True)
notebook = ttk.Notebook(self.root, style="TNotebook")
main_frame.add(notebook, weight=3)

Check warning on line 153 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L150-L153

Added lines #L150 - L153 were not covered by tests
#notebook.pack(fill="both", expand=True, padx=10, pady=10)
# notebook.pack(fill="both", expand=True, padx=10, pady=10)

tab_basic = ttk.Frame(notebook)
tab_advanced = ttk.Frame(notebook)
Expand All @@ -166,7 +167,6 @@ def __init__(self, ui, desktop, aedt_version, personal_lib):
self.create_ui_advanced(tab_advanced)
self.create_ui_extensions(tab_extensions)

Check warning on line 168 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L164-L168

Added lines #L164 - L168 were not covered by tests


self.clicked_refresh()

Check warning on line 170 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L170

Added line #L170 was not covered by tests

def create_file_menu(self):
Expand All @@ -180,7 +180,7 @@ def create_ui_basic(self, parent):
def create_ui_wheelhouse(frame):
buttons = [

Check warning on line 181 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L179-L181

Added lines #L179 - L181 were not covered by tests
["Update from wheelhouse", self.update_from_wheelhouse],
["Update extensions", self.update_extensions]
["Update extensions", self.update_extensions],
]
for text, cmd in buttons:
button = tk.Button(frame, text=text, width=40, height=2, command=cmd)
Expand Down Expand Up @@ -255,9 +255,7 @@ def create_ui_pyedb(frame):
entry.pack(side="left")

Check warning on line 255 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L251-L255

Added lines #L251 - L255 were not covered by tests

def create_ui_pyaedt_buttons(frame):
buttons = [
["Reset PyAEDT Buttons", self.reset_pyaedt_buttons_in_aedt]
]
buttons = [["Reset PyAEDT Buttons", self.reset_pyaedt_buttons_in_aedt]]
for text, cmd in buttons:
button = tk.Button(frame, text=text, width=40, height=2, command=cmd)
button.pack(side="left", padx=10, pady=10)

Check warning on line 261 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L257-L261

Added lines #L257 - L261 were not covered by tests
Expand Down Expand Up @@ -311,7 +309,7 @@ def toggle_theme():

def update_extensions(self):
response = messagebox.askquestion("Confirm Action", "Are you sure you want to proceed?")
if response == 'yes':
if response == "yes":
toolkits_path = Path(self.personal_lib, "Toolkits")
temp = []
for product in toolkits_path.iterdir():
Expand Down Expand Up @@ -358,7 +356,7 @@ def update_extensions(self):
def update_pyaedt(self):
response = messagebox.askquestion("Disclaimer", DISCLAIMER)

Check warning on line 357 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L356-L357

Added lines #L356 - L357 were not covered by tests

if response == 'yes':
if response == "yes":
url = f"https://pypi.org/pypi/pyaedt/json"
response = requests.get(url)

Check warning on line 361 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L359-L361

Added lines #L359 - L361 were not covered by tests

Expand All @@ -369,8 +367,7 @@ def update_pyaedt(self):
released_version = 0

Check warning on line 367 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L367

Added line #L367 was not covered by tests

if self.pyaedt_version > released_version:
subprocess.run(
[self.python_exe, "-m", "pip", "install", f"pyaedt=={released_version}"], check=True)
subprocess.run([self.python_exe, "-m", "pip", "install", f"pyaedt=={released_version}"], check=True)

Check warning on line 370 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L369-L370

Added lines #L369 - L370 were not covered by tests
else:
subprocess.run([self.python_exe, "-m", "pip", "install", "-U", "pyaedt"], check=True)

Check warning on line 372 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L372

Added line #L372 was not covered by tests

Expand All @@ -383,13 +380,19 @@ def get_pyaedt_branch(self):

response = messagebox.askquestion("Disclaimer", DISCLAIMER)

Check warning on line 381 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L381

Added line #L381 was not covered by tests

if response == 'yes':
if response == "yes":
branch_name = self.pyaedt_branch_name.get()
subprocess.run(

Check warning on line 385 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L383-L385

Added lines #L383 - L385 were not covered by tests
[self.python_exe, "-m", "pip", "install",
#"--force-reinstall",
f"git+https://github.com/ansys/pyaedt.git@{branch_name}"],
check=True)
[
self.python_exe,
"-m",
"pip",
"install",
# "--force-reinstall",
f"git+https://github.com/ansys/pyaedt.git@{branch_name}",
],
check=True,
)
self.clicked_refresh(need_restart=True)

Check warning on line 396 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L396

Added line #L396 was not covered by tests

def get_pyedb_branch(self):
Expand All @@ -399,16 +402,17 @@ def get_pyedb_branch(self):

response = messagebox.askquestion("Disclaimer", DISCLAIMER)

Check warning on line 403 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L403

Added line #L403 was not covered by tests

if response == 'yes':
if response == "yes":
branch_name = self.pyedb_branch_name.get()
subprocess.run(

Check warning on line 407 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L405-L407

Added lines #L405 - L407 were not covered by tests
[self.python_exe, "-m", "pip", "install", f"git+https://github.com/ansys/pyedb.git@{branch_name}"],
check=True)
check=True,
)
self.clicked_refresh(need_restart=True)

Check warning on line 411 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L411

Added line #L411 was not covered by tests

def update_pyedb(self):
response = messagebox.askquestion("Disclaimer", DISCLAIMER)
if response == 'yes':
if response == "yes":
url = f"https://pypi.org/pypi/pyedb/json"
response = requests.get(url)

Check warning on line 417 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L413-L417

Added lines #L413 - L417 were not covered by tests

Expand All @@ -419,8 +423,7 @@ def update_pyedb(self):
released_version = 0

Check warning on line 423 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L423

Added line #L423 was not covered by tests

if self.pyedb_version > released_version:
subprocess.run(
[self.python_exe, "-m", "pip", "install", f"pyedb=={released_version}"], check=True)
subprocess.run([self.python_exe, "-m", "pip", "install", f"pyedb=={released_version}"], check=True)

Check warning on line 426 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L425-L426

Added lines #L425 - L426 were not covered by tests
else:
subprocess.run([self.python_exe, "-m", "pip", "install", "-U", "pyedb"], check=True)

Check warning on line 428 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L428

Added line #L428 was not covered by tests

Expand All @@ -438,23 +441,21 @@ def update_from_wheelhouse(self):
correct_wheelhouse = file_name

Check warning on line 441 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L440-L441

Added lines #L440 - L441 were not covered by tests
# Check Python version
if not wh_python_version == self.python_version:
msg.extend([
f"Wrong Python version",
f"Wheelhouse: {wh_python_version}",
f"Expected version: {self.python_version}",
])
msg.extend(

Check warning on line 444 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L443-L444

Added lines #L443 - L444 were not covered by tests
[
f"Wrong Python version",
f"Wheelhouse: {wh_python_version}",
f"Expected version: {self.python_version}",
]
)
correct_wheelhouse = correct_wheelhouse.replace(wh_python_version, self.python_version)

Check warning on line 451 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L451

Added line #L451 was not covered by tests

if wh_pkg_type != "installer":
correct_wheelhouse = correct_wheelhouse.replace(f'-{wh_pkg_type}-', '-installer-')
msg.extend([
"",
f"This wheelhouse doesn't contain required packages to add PyAEDT buttons."
])
correct_wheelhouse = correct_wheelhouse.replace(f"-{wh_pkg_type}-", "-installer-")
msg.extend(["", f"This wheelhouse doesn't contain required packages to add PyAEDT buttons."])

Check warning on line 455 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L453-L455

Added lines #L453 - L455 were not covered by tests

if msg is not []:
msg.extend(["",
f"Please download {correct_wheelhouse}."])
msg.extend(["", f"Please download {correct_wheelhouse}."])
msg = "\n".join(msg)
messagebox.showerror("Confirm Action", msg)
return

Check warning on line 461 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L457-L461

Added lines #L457 - L461 were not covered by tests
Expand All @@ -469,47 +470,52 @@ def update_from_wheelhouse(self):
zip_ref.extractall(unzipped_path)

Check warning on line 470 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L470

Added line #L470 was not covered by tests

subprocess.run(

Check warning on line 472 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L472

Added line #L472 was not covered by tests
[self.python_exe, "-m", "pip", "install", "--no-cache-dir", "--no-index",
f"--find-links=file:///{str(unzipped_path)}",
"pyaedt[installer]"], check=True)
[
self.python_exe,
"-m",
"pip",
"install",
"--no-cache-dir",
"--no-index",
f"--find-links=file:///{str(unzipped_path)}",
"pyaedt[installer]",
],
check=True,
)
self.clicked_refresh(need_restart=True)

Check warning on line 485 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L485

Added line #L485 was not covered by tests

def reset_pyaedt_buttons_in_aedt(self):
def handle_remove_error(func, path, exc_info):

Check warning on line 488 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L487-L488

Added lines #L487 - L488 were not covered by tests
# Attempt to fix permission issues
import stat

Check warning on line 490 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L490

Added line #L490 was not covered by tests

os.chmod(path, stat.S_IWRITE) # Add write permission
func(path) # Retry the operation

Check warning on line 493 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L492-L493

Added lines #L492 - L493 were not covered by tests

response = messagebox.askquestion("Confirm Action", "Are you sure you want to proceed?")

Check warning on line 495 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L495

Added line #L495 was not covered by tests

if response == 'yes':
if response == "yes":
toolkit_path = os.path.join(self.personal_lib, "Toolkits")

Check warning on line 498 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L497-L498

Added lines #L497 - L498 were not covered by tests

if os.path.isdir(toolkit_path) and os.path.exists(toolkit_path):
msg = [
f"Toolkits path {toolkit_path} already exists.",
"Are you sure you want to reset toolkits?"
]
msg = [f"Toolkits path {toolkit_path} already exists.", "Are you sure you want to reset toolkits?"]
msg = "\n".join(msg)
response = messagebox.askquestion("Confirm Action", msg)
if response == 'yes':
if response == "yes":
shutil.rmtree(toolkit_path, onerror=handle_remove_error)

Check warning on line 505 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L500-L505

Added lines #L500 - L505 were not covered by tests
else:
return

Check warning on line 507 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L507

Added line #L507 was not covered by tests

from ansys.aedt.core.workflows.installer.pyaedt_installer import add_pyaedt_to_aedt

Check warning on line 509 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L509

Added line #L509 was not covered by tests

try:
add_pyaedt_to_aedt(self.aedt_version, self.personal_lib)
messagebox.showinfo("Success", "PyAEDT buttons added in AEDT.")
except subprocess.CalledProcessError as e:
messagebox.showerror("Error", f"Error adding buttons to AEDT: {e}")

Check warning on line 515 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L511-L515

Added lines #L511 - L515 were not covered by tests

def clicked_refresh(self, need_restart=False):
msg = [
f"Venv path: {self.venv_path}",
f"Python version: {self.python_version}"
]
msg = [f"Venv path: {self.venv_path}", f"Python version: {self.python_version}"]
msg = "\n".join(msg)
self.venv_information.set(msg)

Check warning on line 520 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L517-L520

Added lines #L517 - L520 were not covered by tests

Expand Down Expand Up @@ -543,9 +549,7 @@ def get_desktop_info(release_desktop=True):
personal_lib = app.personallib
if release_desktop:
app.release_desktop(close_project, close_on_exit)
return {"desktop": app,
"aedt_version": aedt_version,
"personal_lib": personal_lib}
return {"desktop": app, "aedt_version": aedt_version, "personal_lib": personal_lib}

Check warning on line 552 in src/ansys/aedt/core/workflows/project/version_manager.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/workflows/project/version_manager.py#L548-L552

Added lines #L548 - L552 were not covered by tests


if __name__ == "__main__":
Expand Down

0 comments on commit 2ca4d8e

Please sign in to comment.