diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index e1aa4289..92cb41e7 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -20,162 +20,195 @@ env: PACKAGE_NAME: 'ansys-modelcenter-workflow' PACKAGE_NAMESPACE: 'ansys.modelcenter.workflow' DOCUMENTATION_CNAME: 'modelcenter.docs.pyansys.com' + #ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER) }} jobs: - doc-style: - name: "Documentation Style Check" - runs-on: ubuntu-latest - steps: - - name: PyAnsys documentation style checks - uses: ansys/actions/doc-style@v8 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - smoke-tests: - name: "Build and Smoke tests" - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ['3.10', '3.11', '3.12', '3.13'] - # Only perform wheelhouse builds for Windows and macOS when releasing - should-release: - - ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags') }} - exclude: - - should-release: false - os: macos-latest - - should-release: false - os: windows-latest + debugging: + name: "Debugging" + runs-on: [self-hosted, pymodelcenter] + defaults: + run: + shell: powershell steps: - - name: Build wheelhouse and perform smoke test - uses: ansys/actions/build-wheelhouse@v8 - with: - library-name: ${{ env.PACKAGE_NAME }} - operating-system: ${{ matrix.os }} - python-version: ${{ matrix.python-version }} + - name: "Checkout project" + uses: actions/checkout@v5 - build-tests: - name: "Build and unit testing" - needs: [smoke-tests] - runs-on: windows-latest - strategy: - matrix: - python-version: ['3.10', '3.11', '3.12', '3.13'] - should-release: - - ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags') }} - steps: - - name: "Install Git and checkout project" - uses: actions/checkout@v4 - - - name: "Setup Python" - uses: actions/setup-python@v5 + - name: "Setup Python via UV" + uses: astral-sh/setup-uv@v7 with: python-version: ${{ env.MAIN_PYTHON_VERSION }} - - name: "Install packages for testing" + - name: "Install project" run: | - pip install --upgrade pip - pip install .[tests] - - - name: "Testing" - run: pytest -v - - - name: "Upload coverage artifacts" - uses: actions/upload-artifact@v4 - if: matrix.python-version == env.MAIN_PYTHON_VERSION - with: - name: coverage-html - path: .cov/html - retention-days: 7 - - - name: "Upload coverage to Codecov" - uses: codecov/codecov-action@v5 - if: matrix.python-version == env.MAIN_PYTHON_VERSION - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: .cov/xml - - - doc-build: - name: "Documentation building" - runs-on: ubuntu-latest - needs: [doc-style] - steps: - - name: Temporary handle broken package dependencies - shell: bash + uv venv --seed --python ${{ env.MAIN_PYTHON_VERSION }} + .venv\Scripts\activate + #uv pip install --editable . + uv pip install ansys-modelcenter-workflow + + - name: "Run basic example" + env: + AWP_ROOT: 'C:\Program Files\ANSYS Inc' run: | - sudo apt-get update - sudo apt-get --fix-broken install -y - sudo apt-get install -y texlive-latex-extra latexmk texlive-fonts-extra - - - name: "Run Ansys documentation building action" - uses: ansys/actions/doc-build@21c9de9bee9692173780696d4a39964f20b9cfa3 # v10.1.5 - with: - python-version: ${{ env.MAIN_PYTHON_VERSION }} - skip-install: true - #dependencies: "texlive-fonts-extra" - - package: - name: "Package library" - needs: [build-tests, doc-build] - runs-on: ubuntu-latest - steps: - - name: "Build library source and wheel artifacts" - uses: ansys/actions/build-library@v8 - with: - library-name: ${{ env.PACKAGE_NAME }} - python-version: ${{ env.MAIN_PYTHON_VERSION }} - - - doc-deploy-dev: - name: "Deploy developers documentation" - runs-on: ubuntu-latest - # Deploy development only when merging to main - if: github.ref == 'refs/heads/main' - needs: [package] - steps: - - name: "Deploy the latest documentation" - uses: ansys/actions/doc-deploy-dev@v8 - with: - cname: ${{ env.DOCUMENTATION_CNAME }} - token: ${{ secrets.GITHUB_TOKEN }} - bot-user: ${{ secrets.PYANSYS_CI_BOT_USERNAME }} - bot-email: ${{ secrets.PYANSYS_CI_BOT_EMAIL }} - - - release: - name: "Release project to public PyPI and GitHub" - if: github.event_name == 'push' && contains(github.ref, 'refs/tags') - needs: [package] - runs-on: ubuntu-latest - steps: - - name: "Release to the public PyPI repository" - uses: ansys/actions/release-pypi-public@v8 - with: - library-name: ${{ env.PACKAGE_NAME }} - twine-username: "__token__" - twine-token: ${{ secrets.PYPI_TOKEN }} - - - name: "Release to GitHub" - uses: ansys/actions/release-github@v8 - with: - library-name: ${{ env.PACKAGE_NAME }} - - - doc-deploy-stable: - name: "Deploy stable documentation" - # Deploy release documentation when creating a new tag - if: github.event_name == 'push' && contains(github.ref, 'refs/tags') - runs-on: ubuntu-latest - needs: [release] - steps: - - name: "Deploy the stable documentation" - uses: ansys/actions/doc-deploy-stable@v8 - with: - cname: ${{ env.DOCUMENTATION_CNAME }} - token: ${{ secrets.GITHUB_TOKEN }} - bot-user: ${{ secrets.PYANSYS_CI_BOT_USERNAME }} - bot-email: ${{ secrets.PYANSYS_CI_BOT_EMAIL }} + .venv\Scripts\activate + python -c "import sys; print(sys.executable)" + python examples/BasicExample.py + + # doc-style: + # name: "Documentation Style Check" + # runs-on: ubuntu-latest + # steps: + # - name: PyAnsys documentation style checks + # uses: ansys/actions/doc-style@v8 + # with: + # token: ${{ secrets.GITHUB_TOKEN }} + # + # + # smoke-tests: + # name: "Build and Smoke tests" + # runs-on: ${{ matrix.os }} + # strategy: + # fail-fast: false + # matrix: + # os: [ubuntu-latest, windows-latest, macos-latest] + # python-version: ['3.10', '3.11', '3.12', '3.13'] + # # Only perform wheelhouse builds for Windows and macOS when releasing + # should-release: + # - ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags') }} + # exclude: + # - should-release: false + # os: macos-latest + # - should-release: false + # os: windows-latest + # steps: + # - name: Build wheelhouse and perform smoke test + # uses: ansys/actions/build-wheelhouse@v8 + # with: + # library-name: ${{ env.PACKAGE_NAME }} + # operating-system: ${{ matrix.os }} + # python-version: ${{ matrix.python-version }} + # + # + # build-tests: + # name: "Build and unit testing" + # needs: [smoke-tests] + # runs-on: windows-latest + # strategy: + # matrix: + # python-version: ['3.10', '3.11', '3.12', '3.13'] + # should-release: + # - ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags') }} + # steps: + # - name: "Install Git and checkout project" + # uses: actions/checkout@v4 + # + # - name: "Setup Python" + # uses: actions/setup-python@v5 + # with: + # python-version: ${{ env.MAIN_PYTHON_VERSION }} + # + # - name: "Install packages for testing" + # run: | + # pip install --upgrade pip + # pip install .[tests] + # + # - name: "Testing" + # run: pytest -v + # + # - name: "Upload coverage artifacts" + # uses: actions/upload-artifact@v4 + # if: matrix.python-version == env.MAIN_PYTHON_VERSION + # with: + # name: coverage-html + # path: .cov/html + # retention-days: 7 + # + # - name: "Upload coverage to Codecov" + # uses: codecov/codecov-action@v5 + # if: matrix.python-version == env.MAIN_PYTHON_VERSION + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # files: .cov/xml + # + # + # doc-build: + # name: "Documentation building" + # runs-on: [self-hosted, Windows, pymodelcenter] + # needs: [doc-style] + # steps: + # # - name: Temporary handle broken package dependencies + # # shell: bash + # # run: | + # # sudo apt-get update + # # sudo apt-get --fix-broken install -y + # # sudo apt-get install -y texlive-latex-extra latexmk texlive-fonts-extra + # + # - name: "Run Ansys documentation building action" + # uses: ansys/actions/doc-build@21c9de9bee9692173780696d4a39964f20b9cfa3 # v10.1.5 + # with: + # python-version: ${{ env.MAIN_PYTHON_VERSION }} + # # skip-install: true + # #dependencies: "texlive-fonts-extra" + # + # package: + # name: "Package library" + # needs: [build-tests, doc-build] + # runs-on: ubuntu-latest + # steps: + # - name: "Build library source and wheel artifacts" + # uses: ansys/actions/build-library@v8 + # with: + # library-name: ${{ env.PACKAGE_NAME }} + # python-version: ${{ env.MAIN_PYTHON_VERSION }} + # + # + # doc-deploy-dev: + # name: "Deploy developers documentation" + # runs-on: ubuntu-latest + # # Deploy development only when merging to main + # if: github.ref == 'refs/heads/main' + # needs: [package] + # steps: + # - name: "Deploy the latest documentation" + # uses: ansys/actions/doc-deploy-dev@v8 + # with: + # cname: ${{ env.DOCUMENTATION_CNAME }} + # token: ${{ secrets.GITHUB_TOKEN }} + # bot-user: ${{ secrets.PYANSYS_CI_BOT_USERNAME }} + # bot-email: ${{ secrets.PYANSYS_CI_BOT_EMAIL }} + # + # + # release: + # name: "Release project to public PyPI and GitHub" + # if: github.event_name == 'push' && contains(github.ref, 'refs/tags') + # needs: [package] + # runs-on: ubuntu-latest + # steps: + # - name: "Release to the public PyPI repository" + # uses: ansys/actions/release-pypi-public@v8 + # with: + # library-name: ${{ env.PACKAGE_NAME }} + # twine-username: "__token__" + # twine-token: ${{ secrets.PYPI_TOKEN }} + # + # - name: "Release to GitHub" + # uses: ansys/actions/release-github@v8 + # with: + # library-name: ${{ env.PACKAGE_NAME }} + # + # + # doc-deploy-stable: + # name: "Deploy stable documentation" + # # Deploy release documentation when creating a new tag + # if: github.event_name == 'push' && contains(github.ref, 'refs/tags') + # runs-on: ubuntu-latest + # needs: [release] + # steps: + # - name: "Deploy the stable documentation" + # uses: ansys/actions/doc-deploy-stable@v8 + # with: + # cname: ${{ env.DOCUMENTATION_CNAME }} + # token: ${{ secrets.GITHUB_TOKEN }} + # bot-user: ${{ secrets.PYANSYS_CI_BOT_USERNAME }} + # bot-email: ${{ secrets.PYANSYS_CI_BOT_EMAIL }} diff --git a/.gitignore b/.gitignore index 2c303bdc..a08f16cf 100644 --- a/.gitignore +++ b/.gitignore @@ -72,4 +72,5 @@ doc/_build/ doc/source/api/ # Files generated by running example scripts -examples/Example*.pxcz \ No newline at end of file +examples/Example*.pxcz +doc/source/examples/ \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 59c70aa7..ca6d0ac7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,30 +1,30 @@ repos: - repo: https://github.com/ansys/pre-commit-hooks - rev: v0.4.4 + rev: v0.5.2 hooks: - id: add-license-headers args: - --start_year=2022 - repo: https://github.com/psf/black - rev: 24.10.0 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!! + rev: 25.9.0 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!! hooks: - id: black - repo: https://github.com/adamchainz/blacken-docs - rev: 1.19.1 + rev: 1.20.0 hooks: - id: blacken-docs additional_dependencies: [black==24.10.0] - repo: https://github.com/pycqa/isort - rev: 5.13.2 + rev: 7.0.0 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 + rev: 7.3.0 hooks: - id: flake8 @@ -37,7 +37,7 @@ repos: # language: python - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.1 hooks: - id: codespell args: ["--ignore-words", "doc/styles/config/vocabularies/ANSYS/accept.txt"] @@ -51,6 +51,6 @@ repos: # this validates our github workflow files - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.30.0 + rev: 0.34.1 hooks: - id: check-github-workflows \ No newline at end of file diff --git a/doc/source/conf.py b/doc/source/conf.py index 68a4ab51..e8a6cd9e 100755 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -17,6 +17,7 @@ pyansys_logo_black, watermark, ) +from sphinx_gallery.sorting import FileNameSortKey from ansys.modelcenter.workflow import __version__ @@ -61,6 +62,7 @@ ], } + html_context = { "display_github": True, # Integrate GitHub "github_user": USERNAME, @@ -81,6 +83,27 @@ "sphinx_design", ] +BUILD_EXAMPLES = True if os.environ.get("BUILD_EXAMPLES", "true") == "true" else False +if BUILD_EXAMPLES is True: + # Necessary for pyvista when building the sphinx gallery + extensions.append("sphinx_gallery.gen_gallery") + sphinx_gallery_conf = { + # convert rst to md for ipynb + "pypandoc": True, + # path to your examples scripts + "examples_dirs": ["../../examples/"], + # path where to save gallery generated examples + "gallery_dirs": ["examples"], + # Pattern to search for examples files + "filename_pattern": r"\.py", + # Sort gallery examples by file name instead of number of lines (default) + "within_subsection_order": FileNameSortKey, + # Modules for which function level galleries are created. In + "doc_module": "ansys-modelcenter-workflow", + "thumbnail_size": (600, 300), + "remove_config_comments": True, + } + # Intersphinx mapping intersphinx_mapping = { "python": ("https://docs.python.org/dev", None), diff --git a/doc/source/index.rst b/doc/source/index.rst index 8b2fc3a8..ef147469 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -52,4 +52,5 @@ engineering workflows. getting_started/index user_guide/index api/index - contributing/index \ No newline at end of file + contributing/index + examples/index \ No newline at end of file diff --git a/examples/BasicExample.py b/examples/BasicExample.py index c9860951..8c252b7c 100644 --- a/examples/BasicExample.py +++ b/examples/BasicExample.py @@ -20,6 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +"""Basic example of using the Ansys ModelCenter Workflow API.""" + import os from ansys.tools.variableinterop.scalar_values import RealValue @@ -37,7 +39,7 @@ workflow_path = os.path.join(cwd, workflow_filename) print("Initializing workflow engine...") -with Engine() as mc: +with Engine(heartbeat_interval=60 * 1_000) as mc: print("Loading workflow: " + workflow_path) with mc.load_workflow(workflow_path) as workflow: print("Loaded: " + workflow_filename) diff --git a/examples/CreateWorkflow.py b/examples/CreateWorkflow.py index d0e4a306..85076994 100644 --- a/examples/CreateWorkflow.py +++ b/examples/CreateWorkflow.py @@ -20,6 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +"""Create a new workflow in Ansys ModelCenter Workflow.""" + import os import ansys.modelcenter.workflow.api as mcapi diff --git a/examples/Datapins.py b/examples/Datapins.py index e5a60d54..85b576fb 100644 --- a/examples/Datapins.py +++ b/examples/Datapins.py @@ -19,6 +19,7 @@ # 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. +"""Datapins example for Ansys ModelCenter Workflow.""" import os diff --git a/examples/NewComponentsAndLinks.py b/examples/NewComponentsAndLinks.py index 4b78ab45..c35d1ab0 100644 --- a/examples/NewComponentsAndLinks.py +++ b/examples/NewComponentsAndLinks.py @@ -19,7 +19,7 @@ # 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. - +"""New components and links example.""" import os ############################################################# diff --git a/examples/README.txt b/examples/README.txt new file mode 100644 index 00000000..9f0cbcc2 --- /dev/null +++ b/examples/README.txt @@ -0,0 +1,15 @@ +Examples +======== + +This folder contains example scripts and workflows that show how to work with +various aspects of Ansys ModelCenter Workflow. + +| File | Description | +|---------------------------|-----------------------------------------------------------------------------------| +| BasicExample.py | Shows how to set and get values from the workflow and from datapins. | +| NewComponentsAndLinks.py | Shows how to add a new component to a workflow and link it to other elements. | +| WorkingWithNames.py | Shows how to reference elements by name, and how to rename elements. | +| Datapins.py | Shows how to interact with datapin values and states. | +| CreateWorkflow.py | Shows how to create a new workflow. | +| WorkflowTraversal.py | Shows how to traverse the workflow tree by getting element groups and children. | +| SequencesAndArrays.py | Shows how to add new sequences to a workflow and how to work with array datapins. | diff --git a/examples/SequencesAndArrays.py b/examples/SequencesAndArrays.py index b44af4a5..dd4be6f9 100644 --- a/examples/SequencesAndArrays.py +++ b/examples/SequencesAndArrays.py @@ -19,7 +19,7 @@ # 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. - +"""Example of how to create new sequences and arrays.""" ############################################ # Example of how to create new sequences and arrays ############################################ diff --git a/examples/WorkflowTraversal.py b/examples/WorkflowTraversal.py index b72d2098..16e86fcf 100644 --- a/examples/WorkflowTraversal.py +++ b/examples/WorkflowTraversal.py @@ -19,6 +19,7 @@ # 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. +"""Workflow traversal example for Ansys ModelCenter Workflow.""" import os diff --git a/examples/WorkingWithNames.py b/examples/WorkingWithNames.py index 91e66e6f..3d86e94d 100644 --- a/examples/WorkingWithNames.py +++ b/examples/WorkingWithNames.py @@ -19,7 +19,7 @@ # 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. - +"""Working with element names example for Ansys ModelCenter Workflow.""" import os ############################################## diff --git a/pyproject.toml b/pyproject.toml index d11f8b66..b0efa9fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ doc=[ "sphinx-autoapi==3.6.1", "sphinx-gallery==0.19.0", "sphinx-notfound-page==1.1.0", + "matplotlib>=3.10.7", ] tests = [ "ansys-engineeringworkflow-api==0.1.0",