Skip to content

Commit

Permalink
bump to v0.11.10
Browse files Browse the repository at this point in the history
  • Loading branch information
dipinknair committed Nov 18, 2024
2 parents aa438eb + 87e3da7 commit e550ee6
Show file tree
Hide file tree
Showing 26 changed files with 222 additions and 95 deletions.
56 changes: 42 additions & 14 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ jobs:
else
echo "matrix={\"mechanical-version\":['${{ needs.revn-variations.outputs.test_docker_image_version }}'],\"experimental\":[false]}" >> $GITHUB_OUTPUT
fi
container-stability-check:
runs-on: ubuntu-latest
needs: [revn-variations]
outputs:
container_stable_exit: ${{ steps.check_stability.outputs.container_stable_exit }}
steps:
- id: check_stability
run: |
sudo apt update
sudo apt install bc -y
CONTAINER_VERSION=$(echo "${{ needs.revn-variations.outputs.test_docker_image_version }}" | grep -o -E '[0-9]+(\.[0-9]+)?' | head -n 1)
if (( $(echo "$CONTAINER_VERSION > 24.2" | bc -l) )); then
echo "container_stable_exit=true" >> $GITHUB_OUTPUT
else
echo "container_stable_exit=false" >> $GITHUB_OUTPUT
fi
remote-connect:
name: Remote connect testing and coverage - Mechanical ${{ matrix.mechanical-version }}
Expand Down Expand Up @@ -222,7 +238,7 @@ jobs:
pytest-extra-args: '-s --junitxml remote_results${{ env.MAIN_PYTHON_VERSION}}.xml'

- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
uses: mikepenz/action-junit-report@v5
if: always()
with:
report_paths: '**/remote_results*.xml'
Expand Down Expand Up @@ -269,7 +285,7 @@ jobs:
name: Embedding testing and coverage
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [smoke-tests, revn-variations]
needs: [smoke-tests, revn-variations, container-stability-check]
container:
image: ${{ needs.revn-variations.outputs.test_container }}
options: --entrypoint /bin/bash
Expand Down Expand Up @@ -304,7 +320,11 @@ jobs:
PYTHONUNBUFFERED: 1
run: |
. /env/bin/activate
xvfb-run mechanical-env pytest -m embedding -s --junitxml test_results${{ matrix.python-version }}.xml || true
if [ "${{ needs.container-stability-check.outputs.container_stable_exit }}" = "true" ]; then
xvfb-run mechanical-env pytest -m embedding -s --junitxml test_results${{ matrix.python-version }}.xml
else
xvfb-run mechanical-env pytest -m embedding -s --junitxml test_results${{ matrix.python-version }}.xml || true
fi
- name: Upload coverage results
uses: actions/upload-artifact@v4
Expand All @@ -325,7 +345,7 @@ jobs:
retention-days: 7

- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
uses: mikepenz/action-junit-report@v5
if: always()
with:
report_paths: '**/test_results*.xml'
Expand Down Expand Up @@ -395,7 +415,7 @@ jobs:
retention-days: 7

- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
uses: mikepenz/action-junit-report@v5
if: always()
with:
report_paths: '**/test_results*.xml'
Expand All @@ -411,7 +431,7 @@ jobs:
container:
image: ${{ needs.revn-variations.outputs.test_container }}
options: --entrypoint /bin/bash
needs: [ style, revn-variations]
needs: [ style, revn-variations, container-stability-check]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -447,10 +467,14 @@ jobs:
unset PYMECHANICAL_PORT
unset PYMECHANICAL_START_INSTANCE
. /env/bin/activate
pytest -m remote_session_launch -s --junitxml launch_test_results${{ matrix.python-version }}.xml || true
if [ "${{ needs.container-stability-check.outputs.container_stable_exit }}" = "true" ]; then
pytest -m remote_session_launch -s --junitxml launch_test_results${{ matrix.python-version }}.xml
else
pytest -m remote_session_launch -s --junitxml launch_test_results${{ matrix.python-version }}.xml || true
fi
- name: Publish Launch Test Report
uses: mikepenz/action-junit-report@v4
uses: mikepenz/action-junit-report@v5
if: always()
with:
report_paths: '**/launch_test_results*.xml'
Expand Down Expand Up @@ -481,9 +505,9 @@ jobs:
name: Documentation
runs-on: ubuntu-latest
container:
image: ${{ needs.revn-variations.outputs.stable_container }}
image: ${{ needs.revn-variations.outputs.test_container }}
options: --entrypoint /bin/bash
needs: [style, doc-style, revn-variations]
needs: [style, doc-style, revn-variations, container-stability-check]

steps:

Expand Down Expand Up @@ -545,10 +569,14 @@ jobs:
unset PYMECHANICAL_START_INSTANCE
output_file=doc_$1_output.txt
xvfb-run mechanical-env make -C doc $1 > $output_file 2>&1 || true
cat $output_file
echo done running make
validate_output $output_file
if [ "${{ needs.container-stability-check.outputs.container_stable_exit }}" = "true" ]; then
xvfb-run mechanical-env make -C doc $1
else
xvfb-run mechanical-env make -C doc $1 > $output_file 2>&1 || true
cat $output_file
echo done running make
validate_output $output_file
fi
}
# Validate that the html or pdf build succeeded
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ repos:
args: ["--ignore-words", "doc/styles/config/vocabularies/ANSYS/accept.txt", "-w"]

- repo: https://github.com/ansys/pre-commit-hooks
rev: v0.4.3
rev: v0.4.4
hooks:
- id: add-license-headers
args:
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/963.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
update CHANGELOG for v0.11.9
1 change: 1 addition & 0 deletions doc/changelog.d/965.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modify how job success is verified for CI/CD
1 change: 1 addition & 0 deletions doc/changelog.d/966.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump mikepenz/action-junit-report from 4 to 5
1 change: 1 addition & 0 deletions doc/changelog.d/967.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump grpcio from 1.67.0 to 1.67.1 in the core group
1 change: 1 addition & 0 deletions doc/changelog.d/968.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump the doc group with 2 updates
1 change: 1 addition & 0 deletions doc/changelog.d/969.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump pytest-cov from 5.0.0 to 6.0.0
1 change: 1 addition & 0 deletions doc/changelog.d/971.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update docs build action container
1 change: 1 addition & 0 deletions doc/changelog.d/972.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add Mechanical API link to Mechanical Scripting page
1 change: 1 addition & 0 deletions doc/changelog.d/974.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update embedding script tests
1 change: 1 addition & 0 deletions doc/changelog.d/977.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pre-commit automatic update
1 change: 1 addition & 0 deletions doc/changelog.d/979.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Version input type check
1 change: 1 addition & 0 deletions doc/changelog.d/980.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adding new method for connecting to Mechanical instance
1 change: 1 addition & 0 deletions doc/changelog.d/981.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump grpcio from 1.67.1 to 1.68.0 in the core group
1 change: 1 addition & 0 deletions doc/changelog.d/982.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump the doc group with 2 updates
6 changes: 3 additions & 3 deletions doc/source/cheatsheet/cheat_sheet.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ ansys-mechanical -r 242 --port 10000 -g
## Manually connect to the Mechanical session
```{python}
#| eval: false
import ansys.mechanical.core as pymechanical
from ansys.mechanical.core import connect_to_mechanical
# Connect locally
mechanical = pymechanical.Mechanical(port=10000)
mechanical = connect_to_mechanical(port=10000)
# Or
# Connect remotely, to the IP address or hostname
mechanical = pymechanical.Mechanical(
mechanical = connect_to_mechanical(
"192.168.0.1", port=10000
)
```
Expand Down
3 changes: 2 additions & 1 deletion doc/source/links.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
.. _Chapter 7: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/%%VERSION%%/en/installation/win_silent.html

.. # Mechanical related
.. _Mechanical scripting interface: https://developer.ansys.com/docs/mechanical-scripting-interface/api/index.md
.. _Mechanical API Documentation: https://scripting.mechanical.docs.pyansys.com/version/dev/api/index.html
.. _Mechanical scripting interface APIs: https://developer.ansys.com/docs/mechanical-scripting-interface/api/index.md
.. _ACT API Reference Guide: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v242/en/act_ref/act_ref.html
.. _Mechanical API known issues and limitations: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/%%VERSION%%/en/act_script/mech_apis_KIL.html?q=known%20issues
.. _ACT known issues and limitations: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/%%VERSION%%/en/act_dev/act_dev_knownissues.html
Expand Down
7 changes: 5 additions & 2 deletions doc/source/user_guide_scripting/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ You could already perform scripting of Mechanical with Python from inside
Mechanical. PyMechanical leverages the same APIs but allows you to run your
automation from outside Mechanical.

For comprehensive information on these APIs, see the `Scripting in Mechanical Guide`_ in the
Ansys Help.
.. note::

For comprehensive information on these APIs, see the `Scripting in Mechanical Guide`_ in the
Ansys Help portal, the `Mechanical scripting interface APIs`_ in the Developer Portal, or the
`Mechanical API Documentation`_.

Recording
---------
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
[project]
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
name = "ansys-mechanical-core"
version = "0.11.9"
version = "0.11.10"
description = "A python wrapper for Ansys Mechanical"
readme = "README.rst"
requires-python = ">=3.10,<4.0"
Expand Down Expand Up @@ -51,23 +51,23 @@ Changelog = "https://mechanical.docs.pyansys.com/version/stable/changelog.html"
[project.optional-dependencies]
tests = [
"pytest==8.3.3",
"pytest-cov==5.0.0",
"pytest-cov==6.0.0",
"pytest-print==1.0.2",
"psutil==6.1.0"
]
doc = [
"sphinx==8.1.3",
"ansys-sphinx-theme[autoapi]==1.1.7",
"grpcio==1.67.0",
"ansys-sphinx-theme[autoapi]==1.2.1",
"grpcio==1.68.0",
"imageio-ffmpeg==0.5.1",
"imageio==2.36.0",
"jupyter_sphinx==0.5.3",
"jupyterlab>=3.2.8",
"matplotlib==3.9.2",
"numpy==2.1.2",
"numpy==2.1.3",
"numpydoc==1.8.0",
"pandas==2.2.3",
"panel==1.5.3",
"panel==1.5.4",
"plotly==5.24.1",
"pypandoc==1.14",
"pytest-sphinx==0.6.3",
Expand Down
1 change: 1 addition & 0 deletions src/ansys/mechanical/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from ansys.mechanical.core.mechanical import (
change_default_mechanical_path,
close_all_local_instances,
connect_to_mechanical,
get_mechanical_path,
launch_mechanical,
)
Expand Down
7 changes: 7 additions & 0 deletions src/ansys/mechanical/core/embedding/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ def __init__(self, db_file=None, private_appdata=False, **kwargs):
if len(INSTANCES) > 0:
raise Exception("Cannot have more than one embedded mechanical instance!")
version = kwargs.get("version")
if version is not None:
try:
version = int(version)
except ValueError:
raise ValueError(
f"The version must be an integer or that can be converted to an integer."
)
self._version = initializer.initialize(version)
configuration = kwargs.get("config", _get_default_addin_configuration())

Expand Down
83 changes: 83 additions & 0 deletions src/ansys/mechanical/core/mechanical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2242,3 +2242,86 @@ def launch_mechanical(
raise exception

return mechanical


def connect_to_mechanical(
ip=None,
port=None,
loglevel="ERROR",
log_file=False,
log_mechanical=None,
connect_timeout=120,
clear_on_connect=False,
cleanup_on_exit=False,
keep_connection_alive=True,
) -> Mechanical:
"""Connect to an existing Mechanical server instance.
Parameters
----------
ip : str, optional
IP address for connecting to an existing Mechanical instance. The
IP address defaults to ``"127.0.0.1"``.
port : int, optional
Port to listen on for an existing Mechanical instance. The default is ``None``,
in which case ``10000`` is used. You can override the
default behavior of this parameter with the
``PYMECHANICAL_PORT=<VALID PORT>`` environment variable.
loglevel : str, optional
Level of messages to print to the console.
Options are:
- ``"WARNING"``: Prints only Ansys warning messages.
- ``"ERROR"``: Prints only Ansys error messages.
- ``"INFO"``: Prints all Ansys messages.
The default is ``WARNING``.
log_file : bool, optional
Whether to copy the messages to a file named ``logs.log``, which is
located where the Python script is executed. The default is ``False``.
log_mechanical : str, optional
Path to the output file on the local disk to write every script
command to. The default is ``None``. However, you might set
``"log_mechanical='pymechanical_log.txt'"`` to write all commands that are
sent to Mechanical via PyMechanical to this file. You can then use these
commands to run a script within Mechanical without PyMechanical.
connect_timeout : float, optional
Maximum allowable time in seconds to connect to the Mechanical server.
The default is ``120``.
clear_on_connect : bool, optional
Whether to clear the Mechanical instance when connecting. The default is ``False``.
When ``True``, a fresh environment is provided when you connect to Mechanical.
cleanup_on_exit : bool, optional
Whether to exit Mechanical when Python exits. The default is ``False``.
When ``False``, Mechanical is not exited when the garbage for this Mechanical
instance is collected.
keep_connection_alive : bool, optional
Whether to keep the gRPC connection alive by running a background thread
and making dummy calls for remote connections. The default is ``True``.
Returns
-------
ansys.mechanical.core.mechanical.Mechanical
Instance of Mechanical.
Examples
--------
Connect to an existing Mechanical instance at IP address ``192.168.1.30`` on port
``50001``..
>>> from ansys.mechanical.core import connect_to_mechanical
>>> pymech = connect_to_mechanical(ip='192.168.1.30', port=50001)
"""
return launch_mechanical(
start_instance=False,
loglevel=loglevel,
log_file=log_file,
log_mechanical=log_mechanical,
start_timeout=connect_timeout,
port=port,
ip=ip,
clear_on_connect=clear_on_connect,
cleanup_on_exit=cleanup_on_exit,
keep_connection_alive=keep_connection_alive,
)
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
# Check if Mechanical is installed
# NOTE: checks in this order to get the newest installed version

# Ignore functions starts with `test` from scripts folder
collect_ignore = ["scripts"]

valid_rver = [str(each) for each in SUPPORTED_MECHANICAL_VERSIONS]

Expand Down Expand Up @@ -277,7 +279,7 @@ def connect_to_mechanical_instance(port=None, clear_on_connect=False):
# ip needs to be passed or start instance takes precedence
# typical for container scenarios use connect
# and needs to be treated as remote scenarios
mechanical = pymechanical.launch_mechanical(
mechanical = pymechanical.connect_to_mechanical(
ip=hostname, port=port, clear_on_connect=clear_on_connect, cleanup_on_exit=False
)
return mechanical
Expand Down
Loading

0 comments on commit e550ee6

Please sign in to comment.