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
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,20 @@ extend-exclude = [
select = [
# "E", # pycodestyle, see https://beta.ruff.rs/docs/rules/#pycodestyle-e-w
"D", # pydocstyle, see https://beta.ruff.rs/docs/rules/#pydocstyle-d
# "F", # pyflakes, see https://beta.ruff.rs/docs/rules/#pyflakes-f
"F", # pyflakes, see https://beta.ruff.rs/docs/rules/#pyflakes-f
"PYI", # flake8-pyi, see https://docs.astral.sh/ruff/rules/#flake8-pyi-pyi
# "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
"TD", # flake8-todos, https://docs.astral.sh/ruff/rules/#flake8-todos-td
]
ignore = [
# "E501", # Line too long. Ignoring this so "ruff.formatter" manages line length.
"D204", # One blank line required after class docstring
"D212", # Multi-line docstring summary should start at the first line
"D400", # First line should end with a period
"TD002", # Missing author in TODOs comment
"D204", # One blank line required after class docstring.
"D212", # Multi-line docstring summary should start at the first line.
"D400", # First line should end with a period.
"F821", # Undefined name. PyFlakes can not handle forward reference annotations. Using flake8-pyi instead.
"TD002", # Missing author in TODOs comment.
]

[tool.ruff.lint.pydocstyle]
Expand Down
9 changes: 7 additions & 2 deletions src/ansys/stk/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
"""


__version__ = "0.1.dev0"

from . import graphics
from . import stkobjects
from . import stkutil
from . import vgt
from .stkobjects import astrogator
from .stkobjects import aviator


__version__ = "0.1.dev0"
"""Current version of PySTK."""

__all__ = ["__version__", "graphics", "stkobjects", "stkutil", "vgt", "astrogator", "aviator"]
"""Available modules when using wildcard import."""
15 changes: 7 additions & 8 deletions src/ansys/stk/core/stkdesktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .internal.apiutil import InterfaceProxy, read_registry_key, winreg_stk_binary_dir
from .utilities.grpcutilities import GrpcCallBatcher
from .utilities.exceptions import STKRuntimeError, STKInitializationError
from .stkobjects import StkObjectRoot, StkObjectModelContext, StkObjectRoot
from .stkobjects import StkObjectModelContext, StkObjectRoot
from .uiapplication import UiApplication

class ThreadMarshaller(object):
Expand Down Expand Up @@ -196,7 +196,7 @@ def start_application(visible:bool=False, \
try:
pass
except ModuleNotFoundError:
raise STKInitializationError(f"gRPC use requires Python modules grpcio and protobuf.")
raise STKInitializationError("gRPC use requires Python modules grpcio and protobuf.")
if grpc_port < 0 or grpc_port > 65535:
raise STKInitializationError(f"{grpc_port} is not a valid port number for the gRPC server.")
if grpc_host != "localhost":
Expand All @@ -215,14 +215,14 @@ def start_application(visible:bool=False, \
if bin_dir.exists():
executable = bin_dir / "AgUiApplication.exe"
else:
raise STKInitializationError(f"Could not find AgUiApplication.exe. Verify STK 12 installation.")
raise STKInitializationError("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")

# Calling subprocess.Popen (without shell equals true) to start the backend.
# Excluding low severity bandit check as the validity of the inputs has been ensured.
app_process = subprocess.Popen(cmd_line) # nosec B603
subprocess.Popen(cmd_line) # nosec B603
host = grpc_host
# Ignoring B104 warning as it is a false positive. The hard-coded string "0.0.0.0" is being filtered
# to ensure that it is not used.
Expand Down Expand Up @@ -268,11 +268,11 @@ def attach_to_application(pid:int=None, \
CoInitializeManager.initialize()
if grpc_server:
if pid is not None:
raise STKInitializationError(f"Retry using either 'pid' or 'grpc_server'. Cannot initialize using both.")
raise STKInitializationError("Retry using either 'pid' or 'grpc_server'. Cannot initialize using both.")
try:
from .internal.grpcutil import GrpcClient
except ModuleNotFoundError:
raise STKInitializationError(f"gRPC use requires Python modules grpcio and protobuf.")
raise STKInitializationError("gRPC use requires Python modules grpcio and protobuf.")
client: GrpcClient = GrpcClient.new_client(grpc_host, grpc_port, grpc_timeout_sec)
if client is not None:
app_impl = client.get_stk_application_interface()
Expand All @@ -286,7 +286,6 @@ def attach_to_application(pid:int=None, \
clsid_aguiapplication = GUID()
if Succeeded(OLE32Lib.CLSIDFromString("STK12.Application", clsid_aguiapplication)):
unknown = IUnknown()
iid_iunknown = GUID(IUnknown._guid)
if Succeeded(OLEAut32Lib.GetActiveObject(byref(clsid_aguiapplication), None, byref(unknown.p))):
unknown.take_ownership(isApplication=True)
app = STKDesktopApplication()
Expand Down Expand Up @@ -329,4 +328,4 @@ def create_thread_marshaller(stk_object:typing.Any) -> ThreadMarshaller:

################################################################################
# Copyright 2020-2024, Ansys Government Initiatives
################################################################################
################################################################################
2 changes: 1 addition & 1 deletion src/ansys/stk/core/stkengine/tkcontrols.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self):
self.AgPythonKeyReleased = WINFUNCTYPE(LPVOID, LPVOID, LPVOID, LPVOID, LONG, BOOL, BOOL, BOOL)(("AgPythonKeyReleased", self.jniCore), ((1, "env"), (1, "_this"), (1, "pContainer"), (1, "keyCode"), (1, "ctrlKeyDown"), (1, "altKeyDown"), (1, "shiftKeyDown")))
def _get_jni_core_path(self):
if not STKEngine._is_engine_running:
raise STKRuntimeError(f"STKEngine.StartApplication() must be called before using the STK Engine controls")
raise STKRuntimeError("STKEngine.StartApplication() must be called before using the STK Engine controls")

if os.name != "nt":
return "libagjnicore.so"
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/stk/core/stkruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def new_object_root(self) -> StkObjectRoot:
root = StkObjectRoot()
root._private_init(root_unk)
return root
raise STKInitializationError(f"Not connected to the gRPC server.")
raise STKInitializationError("Not connected to the gRPC server.")

def new_object_model_context(self) -> StkObjectModelContext:
"""May be used to obtain an Object Model Context from a running STK Engine application."""
Expand All @@ -63,7 +63,7 @@ def new_object_model_context(self) -> StkObjectModelContext:
context = StkObjectModelContext()
context._private_init(context_unk)
return context
raise STKInitializationError(f"Not connected to the gRPC server.")
raise STKInitializationError("Not connected to the gRPC server.")

def set_grpc_options(self, options:dict) -> None:
"""
Expand Down Expand Up @@ -155,7 +155,7 @@ def start_application(grpc_host:str="localhost", \
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.")
raise STKInitializationError("Could not find STKRuntime.exe. Verify STK installation.")
cmd_line = [str(stkruntime_path.resolve()), "/grpcHost", grpc_host, "/grpcPort", str(grpc_port)]
if no_graphics:
cmd_line.append("/noGraphics")
Expand Down