Skip to content

Commit

Permalink
Fix items flagged by ruff hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ansMHanmer committed Jan 17, 2025
1 parent a5a6250 commit 568a46b
Showing 1 changed file with 52 additions and 37 deletions.
89 changes: 52 additions & 37 deletions .ci/generate_operators_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from ansys.dpf.core.dpf_operator import available_operator_names
from ansys.dpf.core.core import load_library
import argparse
import os
from jinja2 import Template
from pathlib import Path

def initialize_server(ansys_path=None):
server = dpf.start_local_server(ansys_path=ansys_path)
Expand All @@ -13,65 +13,74 @@ def initialize_server(ansys_path=None):
print(f"Server Config: {server.config}")
print(f"Server version: {dpf.global_server().version}")
print("Loading Composites Plugin")
load_library(os.path.join(server.ansys_path, "dpf", "plugins", "dpf_composites", "composite_operators.dll"))
load_library(
Path(server.ansys_path) / "dpf" / "plugins" / "dpf_composites" / "composite_operators.dll"
)
print("Loading Acoustics Plugin")
load_library(os.path.join(server.ansys_path, "Acoustics", "SAS", "ads", "dpf_sound.dll"))
load_library(Path(server.ansys_path) / "Acoustics" / "SAS" / "ads" / "dpf_sound.dll")
return server


def fetch_doc_info(server, operator_name):
spec = dpf.Operator.operator_specification(op_name=operator_name, server=server)
input_info = []
output_info = []
configurations_info = []
for input_pin in spec.inputs:
input = spec.inputs[input_pin]
input_info.append({
"pin_number": input_pin,
"name": input.name,
"types": [str(t) for t in input._type_names],
"document": input.document,
"optional": input.optional,
})
input_info.append(
{
"pin_number": input_pin,
"name": input.name,
"types": [str(t) for t in input._type_names],
"document": input.document,
"optional": input.optional,
}
)
for output_pin in spec.outputs:
output = spec.outputs[output_pin]
output_info.append({
"pin_number": output_pin,
"name": output.name,
"types": [str(t) for t in output._type_names],
"document": output.document,
"optional": output.optional,
})
output_info.append(
{
"pin_number": output_pin,
"name": output.name,
"types": [str(t) for t in output._type_names],
"document": output.document,
"optional": output.optional,
}
)
for configuration_key in spec.config_specification:
configuration = spec.config_specification[configuration_key]
configurations_info.append({
"name": configuration.name,
"types": [str(t) for t in configuration.type_names],
"document": configuration.document,
"default_value": configuration.default_value_str,
})
configurations_info.append(
{
"name": configuration.name,
"types": [str(t) for t in configuration.type_names],
"document": configuration.document,
"default_value": configuration.default_value_str,
}
)
properties = spec.properties
if "plugin" in properties:
plugin = properties["plugin"]
else:
plugin = "N/A"
try:
scripting_name = properties['scripting_name']
full_name = properties['category'] + "." + properties['scripting_name']
scripting_name = properties["scripting_name"]
full_name = properties["category"] + "." + properties["scripting_name"]
except KeyError:
scripting_name = None
full_name = None
try:
user_name = properties['user_name']
user_name = properties["user_name"]
except KeyError:
user_name = operator_name
try:
category = properties['category']
category = properties["category"]
op_friendly_name = category + ": " + user_name
except KeyError:
category = ""
op_friendly_name = user_name
try:
license = properties['license']
license = properties["license"]
except KeyError:
license = "None"
scripting_info = {
Expand All @@ -89,9 +98,10 @@ def fetch_doc_info(server, operator_name):
"outputs": output_info,
"configurations": configurations_info,
"scripting_info": scripting_info,
"exposure": properties['exposure'],
"exposure": properties["exposure"],
}


def get_plugin_operators(server, plugin_name):
operators = available_operator_names(server)
plugin_operators = []
Expand All @@ -101,26 +111,30 @@ def get_plugin_operators(server, plugin_name):
plugin_operators.append(operator_name)
return plugin_operators


def generate_operator_doc(server, operator_name, include_private):
operator_info = fetch_doc_info(server, operator_name)
if not include_private and operator_info["exposure"] == "private":
return
script_dir = os.path.dirname(__file__)
root_dir = os.path.dirname(script_dir)
template_dir = os.path.join(root_dir, 'doc', 'source', 'operators_doc')
with open(os.path.join(template_dir, 'operator_doc_template.md'), 'r') as file:
script_path = Path(__file__)
root_dir = script_path.parent.parent
template_dir = Path(root_dir) / "doc" / "source" / "operators_doc"
with Path.open(Path(template_dir) / "operator_doc_template.md", "r") as file:
template = Template(file.read())

output = template.render(operator_info)
if "::" in operator_name:
operator_name = operator_name.replace("::", "_")
with open(os.path.join(template_dir, f"{operator_name}.md"), 'w') as file:
with Path.open(Path(template_dir) / f"{operator_name}.md", "w") as file:
file.write(output)


def main():
parser = argparse.ArgumentParser(description="Fetch available operators")
parser.add_argument("--plugin", help="Filter operators by plugin")
parser.add_argument("--ansys_path", default=None, help="Path to Ansys DPF Server installation directory")
parser.add_argument(
"--ansys_path", default=None, help="Path to Ansys DPF Server installation directory"
)
parser.add_argument("--include_private", action="store_true", help="Include private operators")
args = parser.parse_args()
desired_plugin = args.plugin
Expand All @@ -133,5 +147,6 @@ def main():
for operator_name in operators:
generate_operator_doc(server, operator_name, args.include_private)


if __name__ == "__main__":
main()
main()

0 comments on commit 568a46b

Please sign in to comment.