Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@
# Common content for every RST file such us links
rst_epilog = ""
links_filepath = pathlib.Path(__file__).parent.absolute() / "links.rst"
with open(links_filepath) as links_file:
rst_epilog += links_file.read()
rst_epilog += links_filepath.read_text(encoding="utf-8")

# -- Autosectionlabel configuration ------------------------------------------
autosectionlabel_maxdepth = 6
Expand Down Expand Up @@ -279,9 +278,11 @@ def get_sha256_from_file(filepath: pathlib.Path):

"""
sha256_hash = hashlib.sha256()
with open(filepath, "rb") as file:
while chunk := file.read(8192):
sha256_hash.update(chunk)

file_bytes = filepath.read_bytes()
for i in range(0, len(file_bytes), 8192):
sha256_hash.update(file_bytes[i : i + 8192])

return sha256_hash.hexdigest()


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ select = [
# "F", # pyflakes, see https://beta.ruff.rs/docs/rules/#pyflakes-f
# "I", # isort, see https://beta.ruff.rs/docs/rules/#isort-i
"N", # pep8-naming, see https://beta.ruff.rs/docs/rules/#pep8-naming-n
# "PTH", # flake8-use-pathlib, https://beta.ruff.rs/docs/rules/#flake8-use-pathlib-pth
"PTH", # flake8-use-pathlib, https://beta.ruff.rs/docs/rules/#flake8-use-pathlib-pth
"TD", # flake8-todos, https://docs.astral.sh/ruff/rules/#flake8-todos-td
]
ignore = [
Expand Down
11 changes: 6 additions & 5 deletions src/ansys/stk/core/stkdesktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
__all__ = ["STKDesktop", "STKDesktopApplication"]

import os
import pathlib
import socket
import typing
import atexit
Expand Down Expand Up @@ -209,12 +210,12 @@ def start_application(visible:bool=False, \

clsid_stk12application = "{7ADA6C22-FA34-4578-8BE8-65405A55EE15}"
executable = read_registry_key(f"CLSID\\{clsid_stk12application}\\LocalServer32", silent_exception=True)
if executable is None or not os.path.exists(executable):
bin_dir = winreg_stk_binary_dir()
if bin_dir is not None:
executable = os.path.join(bin_dir, "UiApplication.exe")
if executable is None or not pathlib.Path(executable).exists():
bin_dir = pathlib.Path(winreg_stk_binary_dir()).resolve()
if bin_dir.exists():
executable = bin_dir / "AgUiApplication.exe"
else:
raise STKInitializationError(f"Could not find UiApplication.exe. Verify STK 12 installation.")
raise STKInitializationError(f"Could not find AgUiApplication.exe. Verify STK 12 installation.")
cmd_line = [f"{executable}", "/pers", "STK", "/grpcServer", "On", "/grpcHost", grpc_host, "/grpcPort", str(grpc_port)]
if STKDesktop._disable_pop_ups:
cmd_line.append("/Automation")
Expand Down
7 changes: 4 additions & 3 deletions src/ansys/stk/core/stkengine/tkcontrols.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
__all__ = ["GlobeControl", "MapControl", "GfxAnalysisControl"]

import os
import pathlib
from tkinter import Frame
if os.name == "nt":
from ctypes import (CDLL, POINTER, WinDLL, WinError, c_char_p, cdll, create_unicode_buffer,
Expand Down Expand Up @@ -66,10 +67,10 @@ def _get_jni_core_path(self):
if err != 0:
errormsg += f" ({WinError(err)})"
raise STKRuntimeError(errormsg)
stkx_dll_path = c_path.value
stkx_dll_path = pathlib.Path(c_path.value).resolve()

jni_core_dll_path = os.path.join(os.path.dirname(stkx_dll_path), "AgJNICore.dll")
return jni_core_dll_path
jni_core_dll_path = stkx_dll_path.parent / "AgJNICore.dll"
return str(jni_core_dll_path)
def create_container(self, progid):
return self.AgPythonCreateContainer(LPVOID(None), LPVOID(None), LPCWSTR(progid))
def attach_container(self, container, winid, display):
Expand Down
18 changes: 10 additions & 8 deletions src/ansys/stk/core/stkruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import atexit
import os
import pathlib
import socket

# The subprocess module is needed to start the backend.
Expand Down Expand Up @@ -139,22 +140,23 @@ def start_application(grpc_host:str="localhost", \
ld_env = os.getenv('LD_LIBRARY_PATH')
if ld_env:
for path in ld_env.split(':'):
if os.path.exists(os.path.join(path, "stkruntime")):
cmd_line = [os.path.join(path, "stkruntime"), "--grpcHost", grpc_host, "--grpcPort", str(grpc_port)]
stkruntime_path = (pathlib.Path(path) / "stkruntime").resolve()
if stkruntime_path.exists():
cmd_line = [stkruntime_path, "--grpcHost", grpc_host, "--grpcPort", str(grpc_port)]
if no_graphics:
cmd_line.append("--noGraphics")
break
else:
raise STKInitializationError("LD_LIBRARY_PATH not defined. Add STK bin directory to LD_LIBRARY_PATH before running.")
else:
clsid_stkxapplication = "{062AB565-B121-45B5-A9A9-B412CEFAB6A9}"
stkx_dll_path = read_registry_key(f"CLSID\\{clsid_stkxapplication}\\InprocServer32", silent_exception=True)
bin_dir, dll_name = (None, None) if stkx_dll_path is None else os.path.split(stkx_dll_path)
if bin_dir is None or not os.path.exists(os.path.join(bin_dir, "STKRuntime.exe")):
bin_dir = winreg_stk_binary_dir()
if bin_dir is None:
stkx_dll_registry_value = read_registry_key(f"CLSID\\{clsid_stkxapplication}\\InprocServer32", silent_exception=True)
stkruntime_path = None if stkx_dll_registry_value is None else pathlib.Path(stkx_dll_registry_value).parent / "STKRuntime.exe"
if stkruntime_path is None or not stkruntime_path.exists():
stkruntime_path = pathlib.Path(winreg_stk_binary_dir()) / "STKRuntime.exe"
if not stkruntime_path.exists():
raise STKInitializationError(f"Could not find STKRuntime.exe. Verify STK installation.")
cmd_line = [os.path.join(bin_dir, "STKRuntime.exe"), "/grpcHost", grpc_host, "/grpcPort", str(grpc_port)]
cmd_line = [str(stkruntime_path.resolve()), "/grpcHost", grpc_host, "/grpcPort", str(grpc_port)]
if no_graphics:
cmd_line.append("/noGraphics")

Expand Down
Loading