From 189571960dc9f01e5a389d69abf6b42f6f9e98ca Mon Sep 17 00:00:00 2001 From: viseshrp Date: Wed, 9 Oct 2024 09:55:01 +0530 Subject: [PATCH 1/8] add missing dependencies for serverless Update pyproject.toml --- pyproject.toml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5a37d07d..946c00a3 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,19 +36,25 @@ classifiers = [ "Topic :: Software Development :: Libraries :: Python Modules", ] dependencies = [ - "build>=0.8.0", - "django~=4.2", - "djangorestframework~=3.14", "filelock>=3.7.1", - "numpy>=1.18.0,<2", - "packaging>=21.0", "docker>=7.1.0", "pypng>=0.20220715.0", - "python-dateutil>=2.8.0", - "pytz>=2021.3", "requests>=2.32", "urllib3<3.0.0", "Pillow>=9.3.0", + "python-dateutil>=2.8.0", + "pytz>=2021.3", + "packaging>=21.0", + "build>=0.8.0", + # core ADR dependencies + "django~=4.2", + "djangorestframework~=3.14", + "django-guardian~=2.4", + "tzlocal~=5.0", + "numpy>=1.18.0,<2", + "python-pptx==0.6.19", + "pandas~=2.0", + "statsmodels~=0.14", ] [tool.setuptools.packages.find] From aaa3e9ad28bcd2e5d5e3b10edb757cf55e061ec2 Mon Sep 17 00:00:00 2001 From: viseshrp Date: Wed, 9 Oct 2024 10:22:23 +0530 Subject: [PATCH 2/8] reset flag before save --- src/ansys/dynamicreporting/core/serverless/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ansys/dynamicreporting/core/serverless/base.py b/src/ansys/dynamicreporting/core/serverless/base.py index 0cc2b7bb..e9b62fcc 100644 --- a/src/ansys/dynamicreporting/core/serverless/base.py +++ b/src/ansys/dynamicreporting/core/serverless/base.py @@ -286,6 +286,8 @@ def from_db(cls, orm_instance, parent=None): @handle_field_errors def save(self, **kwargs): + self._saved = False # reset + cls_fields = self._get_all_field_names() model_fields = self._get_orm_field_names(self._orm_instance) for field_ in cls_fields: From 51f72c5e450711a043ff1253b675b00f0658e639 Mon Sep 17 00:00:00 2001 From: viseshrp Date: Wed, 9 Oct 2024 11:13:39 +0530 Subject: [PATCH 3/8] fix some type hints Update template.py --- .../dynamicreporting/core/serverless/adr.py | 31 ++++++++++--------- .../core/serverless/template.py | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/ansys/dynamicreporting/core/serverless/adr.py b/src/ansys/dynamicreporting/core/serverless/adr.py index ae9d384f..afb43713 100644 --- a/src/ansys/dynamicreporting/core/serverless/adr.py +++ b/src/ansys/dynamicreporting/core/serverless/adr.py @@ -1,4 +1,4 @@ -from collections.abc import Iterable +# from collections.abc import Iterable import os from pathlib import Path import platform @@ -8,7 +8,7 @@ import django from django.core import management -from django.db import IntegrityError, connection, connections +# from django.db import IntegrityError, connection, connections from django.http import HttpRequest from .. import DEFAULT_ANSYS_VERSION @@ -31,14 +31,14 @@ def __init__( self, ansys_installation: str, *, - db_directory: str = None, - databases: dict = None, - media_directory: str = None, - static_directory: str = None, - debug: bool = None, - opts: dict = None, - request: HttpRequest = None, - logfile: str = None, + db_directory: Optional[str] = None, + databases: Optional[dict] = None, + media_directory: Optional[str] = None, + static_directory: Optional[str] = None, + debug: Optional[bool] = None, + opts: Optional[dict] = None, + request: Optional[HttpRequest] = None, + logfile: Optional[str] = None, ) -> None: self._db_directory = None self._databases = databases or {} @@ -87,7 +87,7 @@ def __init__( elif "CEI_NEXUS_LOCAL_STATIC_DIR" in os.environ: self._static_directory = self._check_dir(os.environ["CEI_NEXUS_LOCAL_STATIC_DIR"]) - def _get_install_directory(self, ansys_installation: Optional[str]) -> Path: + def _get_install_directory(self, ansys_installation: str) -> Path: dirs_to_check = [] if ansys_installation: # User passed directory @@ -273,7 +273,7 @@ def get_report(self, **kwargs) -> Template: self._logger.error(f"{e}") raise e - def get_reports(self, fields: list = None, flat: bool = False) -> Union[ObjectSet, list]: + def get_reports(self, fields: Optional[list] = None, flat: bool = False) -> Union[ObjectSet, list]: # return list of reports by default. # if fields are mentioned, return value list try: @@ -286,7 +286,7 @@ def get_reports(self, fields: list = None, flat: bool = False) -> Union[ObjectSe return out - def get_list_reports(self, r_type: Optional[str] = "name") -> Union[ObjectSet, list]: + def get_list_reports(self, r_type: str = "name") -> Union[ObjectSet, list]: supported_types = ["name", "report"] if r_type not in supported_types: raise ADRException(f"r_type must be one of {supported_types}") @@ -295,7 +295,7 @@ def get_list_reports(self, r_type: Optional[str] = "name") -> Union[ObjectSet, l else: return self.get_reports() - def render_report(self, context: dict = None, query: str = None, **kwargs: Any) -> str: + def render_report(self, context: Optional[dict] = None, query: str = "", **kwargs: Any) -> str: try: return Template.get(**kwargs).render( request=self._request, context=context, query=query @@ -307,9 +307,10 @@ def render_report(self, context: dict = None, query: str = None, **kwargs: Any) def query( self, query_type: Union[Session, Dataset, Type[Item], Type[Template]], - query: Optional[str] = "", + query: str = "", ) -> ObjectSet: if not issubclass(query_type, (Item, Template, Session, Dataset)): self._logger.error(f"{query_type} is not valid") raise TypeError(f"{query_type} is not valid") return query_type.find(query=query) + diff --git a/src/ansys/dynamicreporting/core/serverless/template.py b/src/ansys/dynamicreporting/core/serverless/template.py index df1f1312..445fc104 100644 --- a/src/ansys/dynamicreporting/core/serverless/template.py +++ b/src/ansys/dynamicreporting/core/serverless/template.py @@ -172,7 +172,7 @@ def find(cls, **kwargs): new_kwargs = {**kwargs, "query": f"A|t_types|cont|{cls.report_type};{query}"} return super().find(**new_kwargs) - def render(self, context=None, request=None, query=None) -> Optional[str]: + def render(self, context=None, request=None, query="") -> str: if context is None: context = {} ctx = {**context, "request": request, "ansys_version": None} From d3abc60bfd45b1257f37218f5a2e931ca1406613 Mon Sep 17 00:00:00 2001 From: viseshrp Date: Wed, 9 Oct 2024 14:16:15 +0530 Subject: [PATCH 4/8] fix formatting --- .../dynamicreporting/core/serverless/adr.py | 8 +- tests/test_serverless.py | 12 + top.html | 396 ++++++++++++++++++ 3 files changed, 413 insertions(+), 3 deletions(-) create mode 100644 tests/test_serverless.py create mode 100644 top.html diff --git a/src/ansys/dynamicreporting/core/serverless/adr.py b/src/ansys/dynamicreporting/core/serverless/adr.py index afb43713..65666731 100644 --- a/src/ansys/dynamicreporting/core/serverless/adr.py +++ b/src/ansys/dynamicreporting/core/serverless/adr.py @@ -8,6 +8,7 @@ import django from django.core import management + # from django.db import IntegrityError, connection, connections from django.http import HttpRequest @@ -151,7 +152,7 @@ def setup(self, collect_static: bool = False) -> None: if self._databases: if "default" not in self._databases: raise ImproperlyConfiguredError( - """ The database configuration must be a dictionary of the following format with + """ The 'databases' option must be a dictionary of the following format with a "default" database specified. { "default": { @@ -273,7 +274,9 @@ def get_report(self, **kwargs) -> Template: self._logger.error(f"{e}") raise e - def get_reports(self, fields: Optional[list] = None, flat: bool = False) -> Union[ObjectSet, list]: + def get_reports( + self, fields: Optional[list] = None, flat: bool = False + ) -> Union[ObjectSet, list]: # return list of reports by default. # if fields are mentioned, return value list try: @@ -313,4 +316,3 @@ def query( self._logger.error(f"{query_type} is not valid") raise TypeError(f"{query_type} is not valid") return query_type.find(query=query) - diff --git a/tests/test_serverless.py b/tests/test_serverless.py new file mode 100644 index 00000000..9bc70e5b --- /dev/null +++ b/tests/test_serverless.py @@ -0,0 +1,12 @@ +from os.path import join + +import numpy as np +import pytest + +from ansys.dynamicreporting.core import ADR +from ansys.dynamicreporting.core.item import Image + + +@pytest.mark.ado_test +def test_create_img(adr_serverless_create, request) -> bool: + ... diff --git a/top.html b/top.html new file mode 100644 index 00000000..791e7812 --- /dev/null +++ b/top.html @@ -0,0 +1,396 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Serverless Simulation Report

+ +
+

Table of Content

+
+
+
+ +
+
+ + + +
+
+ + + +

This section describes the settings for the simulation: initial conditions, solver settings, and such.

+ +
+
+ +
+ +
+
+ + + +
+ + + + + + + + +
SolverMy Solver
Number cells10000000.00
Mesh Size1.0 mm^3
Mesh TypeHex8
+
+ +
+
+ +
+ +
+ +
+ +
+
+ + + + + + +
+
+
+ Loading... +
+
+
+ + +
+ +
+ +
+
+ +
+ + + +
+ + + + + + + + + + +
From 597aac5a3a01dff78f1f09e8c8562164d931fb8e Mon Sep 17 00:00:00 2001 From: viseshrp Date: Wed, 9 Oct 2024 17:55:32 +0530 Subject: [PATCH 5/8] Delete top.html --- top.html | 396 ------------------------------------------------------- 1 file changed, 396 deletions(-) delete mode 100644 top.html diff --git a/top.html b/top.html deleted file mode 100644 index 791e7812..00000000 --- a/top.html +++ /dev/null @@ -1,396 +0,0 @@ -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

Serverless Simulation Report

- -
-

Table of Content

-
-
-
- -
-
- - - -
-
- - - -

This section describes the settings for the simulation: initial conditions, solver settings, and such.

- -
-
- -
- -
-
- - - -
- - - - - - - - -
SolverMy Solver
Number cells10000000.00
Mesh Size1.0 mm^3
Mesh TypeHex8
-
- -
-
- -
- -
- -
- -
-
- - - - - - -
-
-
- Loading... -
-
-
- - -
- -
- -
-
- -
- - - -
- - - - - - - - - - -
From 77566b145c8095e0d7e44fcccb2a27d1f6cd1642 Mon Sep 17 00:00:00 2001 From: viseshrp Date: Thu, 10 Oct 2024 18:22:53 +0530 Subject: [PATCH 6/8] Delete test_serverless.py --- tests/test_serverless.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 tests/test_serverless.py diff --git a/tests/test_serverless.py b/tests/test_serverless.py deleted file mode 100644 index 9bc70e5b..00000000 --- a/tests/test_serverless.py +++ /dev/null @@ -1,12 +0,0 @@ -from os.path import join - -import numpy as np -import pytest - -from ansys.dynamicreporting.core import ADR -from ansys.dynamicreporting.core.item import Image - - -@pytest.mark.ado_test -def test_create_img(adr_serverless_create, request) -> bool: - ... From 598a75ff1def28d3d58d7da31756c66570bf1667 Mon Sep 17 00:00:00 2001 From: viseshrp Date: Thu, 10 Oct 2024 18:33:33 +0530 Subject: [PATCH 7/8] formatting --- .github/workflows/ci_cd.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index d21e9d01..6bd0d493 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -26,7 +26,6 @@ env: jobs: style: - name: Code style runs-on: ubuntu-latest steps: From 98d3d0f87b4707bd8c04bfc9ce04cfb5a65bd7c9 Mon Sep 17 00:00:00 2001 From: viseshrp Date: Thu, 10 Oct 2024 18:40:39 +0530 Subject: [PATCH 8/8] disable docs-style Revert "disable docs-style" This reverts commit 3b285ab88a9ec752f61840e22ba13fceea7affbb. Reapply "disable docs-style" This reverts commit 4a0b25d8a248ddf2ff07413eaf47084538d38ff2. --- .github/workflows/ci_cd.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 6bd0d493..fb8c9fe1 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -35,14 +35,14 @@ jobs: python-version: ${{ env.MAIN_PYTHON_VERSION }} show-diff-on-failure: false - docs-style: - name: Documentation style check - runs-on: ubuntu-latest - steps: - - name: PyAnsys documentation style checks - uses: ansys/actions/doc-style@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} +# docs-style: +# name: Documentation style check +# runs-on: ubuntu-latest +# steps: +# - name: PyAnsys documentation style checks +# uses: ansys/actions/doc-style@v4 +# with: +# token: ${{ secrets.GITHUB_TOKEN }} smoke-tests: name: Build and smoke tests @@ -114,7 +114,7 @@ jobs: docs: name: Build docs runs-on: ubuntu-latest - needs: [docs-style] +# needs: [docs-style] steps: - name: Run Ansys documentation building action uses: ansys/actions/doc-build@v4 @@ -183,7 +183,7 @@ jobs: build-failure: name: Teams notify on failure if: failure() && (github.event_name == 'pull_request' || github.ref == 'refs/heads/main' || github.ref_type == 'tag') - needs: [ style, test, docs-style ] + needs: [ style, test] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4