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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ repos:
rev: 22.3.0
hooks:
- id: black
exclude: ^(ansys/hps/client/jms/resource/|ansys/hps/client/auth/resource/|ansys/hps/client/rms/models.py)
exclude: ^(src/ansys/hps/client/rms/models.py)

- repo: https://github.com/pycqa/isort
rev: 5.11.5
hooks:
- id: isort
exclude: ^(ansys/hps/client/jms/resource/|ansys/hps/client/auth/resource/)
# exclude: ^(src/ansys/hps/client/jms/resource/|src/ansys/hps/client/auth/resource/)

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
exclude: ^(ansys/hps/client/jms/resource/|ansys/hps/client/auth/resource/)
exclude: ^(src/ansys/hps/client/jms/resource/|src/ansys/hps/client/auth/resource/)

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
Expand Down
37 changes: 32 additions & 5 deletions generate_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,26 @@ def get_resource_imports(resource, base_class):
return imports


def camel_case_split(text: str) -> str:
words = [[text[0]]]

for c in text[1:]:
if words[-1][-1].islower() and c.isupper():
words.append(list(c))
else:
words[-1].append(c)

words = ["".join(word) for word in words]
return " ".join([w.lower() for w in words])


def get_module_docstring(file_name: str) -> str:
module_name = " ".join(file_name.split("_"))
code = f'''"""Module providing the {module_name} resource."""
'''
return code


def get_resource_code(resource, base_class, fields, field_docs):

fields_str = ""
Expand All @@ -400,31 +420,33 @@ def get_resource_code(resource, base_class, fields, field_docs):
init_fields_str = " **kwargs"

code = f'''class {resource['class']}({base_class["name"]}):
"""{resource['class']} resource.
"""Provides the {camel_case_split(resource['class'])} resource.

Parameters
----------
{field_docs}
{field_docs.rstrip()}
"""

class Meta:
schema = {resource['schema']}
rest_name = "{resource['rest_name']}"

def __init__(self,
def __init__(
self,
{init_fields_str}
):
{fields_str}
{additional_initialization}


{resource['schema']}.Meta.object_class = {resource['class']}
'''
return code


def process_resources(subpackage, resources, base_class_path="ansys.hps.client"):

target_folder = os.path.join("ansys", "hps", "client", subpackage, "resource")
target_folder = os.path.join("src", "ansys", "hps", "client", subpackage, "resource")
resources_code = {}
for resource in resources:
print(f"Processing resource {resource['class']}")
Expand Down Expand Up @@ -458,7 +480,11 @@ def process_resources(subpackage, resources, base_class_path="ansys.hps.client")
# we're ready to put the pieces together
file_name = resource["resource_filename"]
if not file_name in resources_code:
resources_code[file_name] = {"imports": [], "code": []}
resources_code[file_name] = {
"imports": [],
"code": [],
"module_docstring": get_module_docstring(file_name),
}

resources_code[file_name]["imports"].extend(get_resource_imports(resource, base_class))
resources_code[file_name]["code"].append(
Expand All @@ -473,6 +499,7 @@ def process_resources(subpackage, resources, base_class_path="ansys.hps.client")
code = content["code"]
with open(file_path, "w") as file:
file.write("# autogenerated code\n")
file.write(content["module_docstring"])
file.write("\n".join(unique_imports))
file.write("\n\n")
file.write("\n".join(code))
Expand Down
2 changes: 2 additions & 0 deletions src/ansys/hps/client/auth/resource/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# autogenerated code
"""Module providing the user resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/hps/client/auth/schema/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class Meta(BaseSchema.Meta):
username = fields.Str(metadata={"description": "Username."})
password = fields.Str(dump_only=True, metadata={"description": "Password."})
firstName = fields.Str(
allow_none=True, metadata={"description": "First name"}, attribute="first_name"
allow_none=True, metadata={"description": "First name."}, attribute="first_name"
)
lastName = fields.Str(
allow_none=True, metadata={"description": "Last name"}, attribute="last_name"
allow_none=True, metadata={"description": "Last name."}, attribute="last_name"
)
email = fields.Str(allow_none=True, metadata={"description": "E-mail address (optional)."})
email = fields.Str(allow_none=True, metadata={"description": "E-mail address."})
6 changes: 3 additions & 3 deletions src/ansys/hps/client/jms/resource/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Module providing the algorithm resource."""

# autogenerated code
"""Module providing the algorithm resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand Down Expand Up @@ -48,8 +49,7 @@ class Algorithm(Object):
description : str, optional
Description of the algorithm.
data : str, optional
Generic string field to hold arbitrary algorithm configuration data. For example,
as a JSON dictionary.
Generic string field to hold arbitrary algorithm configuration data. For example, as a JSON dictionary.
jobs : list[str]
List of job IDs.
"""
Expand Down
12 changes: 6 additions & 6 deletions src/ansys/hps/client/jms/resource/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# autogenerated code
"""Module providing the job resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand All @@ -28,7 +30,7 @@


class Job(Object):
"""Provides a job resource.
"""Provides the job resource.

Parameters
----------
Expand All @@ -49,8 +51,7 @@ class Job(Object):
job_definition_id : str
ID of the linked job definition. For more information, see the :class:`JobDefinition` class.
priority : int, optional
Priority for evaluating the job. The default is ``0``, which is the highest priority.
Assigning a higher value to a job makes it a lower priority.
Priority for evaluating the job. The default is ``0``, which is the highest priority. Assigning a higher value to a job makes it a lower priority.
values : dict[str, any], optional
Dictionary with (name,value) pairs for all parameters defined in the linked job definition.
fitness : float, optional
Expand All @@ -60,10 +61,9 @@ class Job(Object):
note : str, optional
Note for the job.
creator : str, optional
Name and ID of the creator of the job.
Additional information about the creator of the job.
executed_level : int, optional
Execution level of the last executed task. A value of ``-1`` indicates that no task has been
executed yet.
Execution level of the last executed task. A value of ``-1`` indicates that no task has been executed yet.
elapsed_time : float
Number of seconds it took the evaluators to update the job.
host_ids : list, optional
Expand Down
7 changes: 4 additions & 3 deletions src/ansys/hps/client/jms/resource/job_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# autogenerated code
"""Module providing the job definition resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand All @@ -45,8 +47,7 @@ class JobDefinition(Object):
name : str, optional
Name of the job definition.
active : bool
Whether this is the active job definition in the project where evaluators are evaluating
pending jobs.
Whether this job definition is active.
client_hash : str, optional
parameter_definition_ids : list[str]
List of parameter definition IDs.
Expand All @@ -55,7 +56,7 @@ class JobDefinition(Object):
task_definition_ids : list[str]
List of task definition IDs.
fitness_definition : FitnessDefinitionBase, optional
:class:`FitnessDefinition` object.
A :class:`FitnessDefinition` object.
"""

class Meta:
Expand Down
5 changes: 3 additions & 2 deletions src/ansys/hps/client/jms/resource/license_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# autogenerated code
"""Module providing the license context resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand All @@ -35,8 +37,7 @@ class LicenseContext(Object):
context_id : str, optional
License context ID.
environment : dict, optional
Dictionary of license context environments.

License context environment dict.
"""

class Meta:
Expand Down
2 changes: 2 additions & 0 deletions src/ansys/hps/client/jms/resource/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# autogenerated code
"""Module providing the operation resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand Down
17 changes: 8 additions & 9 deletions src/ansys/hps/client/jms/resource/parameter_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# autogenerated code
"""Module providing the parameter definition resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand Down Expand Up @@ -77,7 +79,7 @@ class FloatParameterDefinition(ParameterDefinition):
display_text : str, optional
Text to display as the parameter name.
mode : str
Indicates if it's an input or output parameter. The mode is filled server-side.
Indicates whether it's an input or output parameter. The mode is filled server-side.
type : str
default : float, optional
Default parameter value.
Expand All @@ -86,13 +88,11 @@ class FloatParameterDefinition(ParameterDefinition):
upper_limit : float, optional
Upper bound for the parameter value.
step : float, optional
If provided, allowable values are given by: AllowableValue = lower_limit + n * step, where n
is an integer and AllowableValue <= upper_limit.
If provided, allowable values are given by: AllowableValue = lower_limit + n * step, where n is an integer and AllowableValue <= upper_limit.
cyclic : bool, optional
Whether the parameter is cyclic.
value_list : list, optional
List of allowed values. This parameter provides an alternative to specifying
upper and lower limits.
List of allowed values. This parameter provides an alternative to specifying upper and lower limits.
"""

class Meta:
Expand Down Expand Up @@ -145,7 +145,7 @@ def __init__(


class IntParameterDefinition(ParameterDefinition):
"""Provides the integer parameter definition resource.
"""Provides the int parameter definition resource.

Parameters
----------
Expand All @@ -168,7 +168,7 @@ class IntParameterDefinition(ParameterDefinition):
display_text : str, optional
Text to display as the parameter name.
mode : str
Indicates if it's an input or output parameter. The mode is filled server-side.
Indicates whether it's an input or output parameter. The mode is filled server-side.
type : str
default : int, optional
Default parameter value.
Expand All @@ -180,7 +180,6 @@ class IntParameterDefinition(ParameterDefinition):
The default is ``1``.
cyclic : bool, optional
Whether the parameter is cyclic.

"""

class Meta:
Expand Down Expand Up @@ -231,7 +230,7 @@ def __init__(


class BoolParameterDefinition(ParameterDefinition):
"""Provides the Boolean parameter definition resource.
"""Provides the bool parameter definition resource.

Parameters
----------
Expand Down
5 changes: 3 additions & 2 deletions src/ansys/hps/client/jms/resource/parameter_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# autogenerated code
"""Module providing the parameter mapping resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand Down Expand Up @@ -55,8 +57,7 @@ class ParameterMapping(Object):
true_string : str, optional
false_string : str, optional
parameter_definition_id : str, optional
ID of the linked parameter definition. For more information, see the
:class:`ParameterDefinition` class.
ID of the linked parameter definition. For more information, see the :class:`ParameterDefinition` class.
task_definition_property : str, optional
file_id : str, optional
ID of the file resource.
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/hps/client/jms/resource/permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# autogenerated code
"""Module providing the permission resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand All @@ -39,7 +41,6 @@ class Permission(Object):
value_name : str, optional
role : str
Role of the user. Options are ``'admin'``, ``'reader'``, and ``'writer'``.

"""

class Meta:
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/hps/client/jms/resource/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# autogenerated code
"""Module providing the project resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand All @@ -46,7 +48,6 @@ class Project(Object):
Date and time that the project was last modified.
statistics : dict, optional
Dictionary containing various project statistics.

"""

class Meta:
Expand Down
2 changes: 2 additions & 0 deletions src/ansys/hps/client/jms/resource/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# autogenerated code
"""Module providing the selection resource."""
from marshmallow.utils import missing

from ansys.hps.client.common import Object
Expand Down
Loading