Skip to content

Commit

Permalink
Merge branch 'main' into process-return-code
Browse files Browse the repository at this point in the history
  • Loading branch information
koubaa authored Jan 7, 2025
2 parents d5d77ee + c169bc7 commit 870eb8c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 25 deletions.
44 changes: 23 additions & 21 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ on:
revn:
type: choice
options:
- '252'
- '251'
- '242'
- '241'
- '232'
description: 'The Mechanical revision number to run tests on.'
default: '242' #stable version is 242, must match $stable_container
schedule:
Expand All @@ -35,8 +37,8 @@ env:
DOCUMENTATION_CNAME: mechanical.docs.pyansys.com
MAIN_PYTHON_VERSION: '3.10'
# DEV_REVN & its Docker image are used in scheduled or registry package runs
DEV_REVN: '251'
DEV_DOCKER_IMAGE_VERSION: '25.1_candidate'
STABLE_REVN: '242'
DEV_REVN: '252'
LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
ANSYSLMD_LICENSE_FILE: 1055@${{ secrets.LICENSE_SERVER }}

Expand Down Expand Up @@ -124,39 +126,41 @@ jobs:
name: Save variations of revn
runs-on: ubuntu-latest
outputs:
# ghcr.io/ansys/mechanical:24.2.0
stable_container: ${{ steps.save-versions.outputs.stable_container }}
# '242' or '251'
test_revn: '${{ steps.save-versions.outputs.test_revn }}'
# ghcr.io/ansys/mechanical:24.2.0 or ghcr.io/ansys/mechanical:25.1.0
test_container: ${{ steps.save-versions.outputs.test_container }}
# '24.2.0' or '25.1.0'
test_docker_image_version: '${{ steps.save-versions.outputs.test_docker_image_version }}'
steps:
- id: save-versions
run: |
if ${{ github.event_name == 'schedule' }}; then
# 251
echo "test_revn=${{ env.DEV_REVN}}" >> $GITHUB_OUTPUT
# ghcr.io/ansys/mechanical:24.2_candidate
echo "test_container=${{ env.DOCKER_PACKAGE }}:${{ env.DEV_DOCKER_IMAGE_VERSION }}" >> $GITHUB_OUTPUT
# 25.1_candidate
echo "test_docker_image_version=${{ env.DEV_DOCKER_IMAGE_VERSION }}" >> $GITHUB_OUTPUT
test_mech_revn=${{ env.DEV_REVN}}
test_mech_image_version=${test_mech_revn:0:2}.${test_mech_revn:2}_candidate
echo "test_container=${{ env.DOCKER_PACKAGE }}:$test_mech_image_version" >> $GITHUB_OUTPUT
echo "test_docker_image_version=$test_mech_image_version" >> $GITHUB_OUTPUT
else
if [[ -z "${{inputs.revn}}" ]]; then
export mech_revn=242
mech_revn=${{ env.STABLE_REVN }}
else
export mech_revn=${{inputs.revn}}
mech_revn=${{inputs.revn}}
fi
export mech_image_version=${mech_revn:0:2}.${mech_revn:2}.0
echo "test_revn=$mech_revn" >> $GITHUB_OUTPUT
# ghcr.io/ansys/mechanical:24.2.0
echo "test_container=${{ env.DOCKER_PACKAGE }}:$mech_image_version" >> $GITHUB_OUTPUT
# 24.2.0
echo "test_docker_image_version=$mech_image_version" >> $GITHUB_OUTPUT
fi
echo "stable_container=${{ env.DOCKER_PACKAGE }}:24.2.0" >> $GITHUB_OUTPUT
stable_mech_revn=${{ env.STABLE_REVN }}
stable_mech_image_version=${mech_revn:0:2}.${mech_revn:2}.0
echo "stable_container=${{ env.DOCKER_PACKAGE }}:$stable_mech_image_version" >> $GITHUB_OUTPUT
echo $GITHUB_OUTPUT
# --- Help ----
# schedule nightly uses DEV_REVN candidate
# PRs and merges use STABLE_REVN
# Workflow dispatch can use any revision number
config-matrix:
runs-on: ubuntu-latest
Expand All @@ -166,9 +170,7 @@ jobs:
steps:
- id: set-matrix
run: |
# Run all stable mechanical versions release tags
# For nightly scheduled runs use pre-release (25.1_candidate)
# For pull requests and merges use latest stable version (242)
# if a tag(release) is pushed, test all versions
if ${{ github.event_name == 'push' }} && ${{ contains(github.ref, 'refs/tags') }}; then
echo "matrix={\"mechanical-version\":['23.2.0', '24.1.0', '24.2.0'],\"experimental\":[false]}" >> $GITHUB_OUTPUT
else
Expand All @@ -184,8 +186,8 @@ jobs:
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
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
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/1022.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add project directory property
1 change: 1 addition & 0 deletions doc/changelog.d/1023.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update ngihtly for pre-release version
1 change: 1 addition & 0 deletions doc/changelog.d/1029.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Process return code
5 changes: 5 additions & 0 deletions src/ansys/mechanical/core/embedding/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ def version(self):
"""Returns the version of the app."""
return self._version

@property
def project_directory(self):
"""Returns the current project directory."""
return self.DataModel.Project.ProjectDirectory

def _share(self, other) -> None:
"""Shares the state of self with other.
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mechanical/core/embedding/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def save_temp_copy(
A Mechanical embedding application.
"""
# Identify the mechdb of the saved session from save_original()
project_directory = Path(app.DataModel.Project.ProjectDirectory)
project_directory = Path(app.project_directory)
project_directory_parent = project_directory.parent
mechdb_file = (
project_directory_parent / f"{project_directory.parts[-1].split('_')[0]}.mechdb"
Expand Down
7 changes: 6 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,15 @@ def mke_app_reset(request):


@pytest.fixture()
def run_subprocess():
def run_subprocess(pytestconfig):
version = pytestconfig.getoption("ansys_version")

def func(args, env=None, check: bool = None):
if check is None:
check = True
if os.name != "nt":
if int(version) < 251:
check = False
process, output = ansys.mechanical.core.run._run(
args, env, check, _PRINT_SUBPROCESS_OUTPUT_TO_CONSOLE
)
Expand Down
8 changes: 6 additions & 2 deletions tests/embedding/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def test_app_save_open(embedded_app, tmp_path: pytest.TempPathFactory):
embedded_app.DataModel.Project.Name = "PROJECT 1"
project_file = os.path.join(tmp_path, f"{NamedTemporaryFile().name}.mechdat")
embedded_app.save_as(project_file)

project_file_directory = os.path.splitext(project_file)[0] + "_Mech_Files"
assert project_file_directory == os.path.normpath(embedded_app.project_directory)

with pytest.raises(Exception):
embedded_app.save_as(project_file)
embedded_app.save_as(project_file, overwrite=True)
Expand Down Expand Up @@ -293,7 +297,7 @@ def test_rm_lockfile(embedded_app, tmp_path: pytest.TempPathFactory):
embedded_app.save(mechdat_path)
embedded_app.close()

lockfile_path = os.path.join(embedded_app.DataModel.Project.ProjectDirectory, ".mech_lock")
lockfile_path = os.path.join(embedded_app.project_directory, ".mech_lock")
# Assert lock file path does not exist
assert not os.path.exists(lockfile_path)

Expand Down Expand Up @@ -446,7 +450,7 @@ def test_app_lock_file_open(embedded_app, tmp_path: pytest.TempPathFactory):
embedded_app.save_as(project_file)
embedded_app.save_as(project_file, overwrite=True)

lock_file = Path(embedded_app.DataModel.Project.ProjectDirectory) / ".mech_lock"
lock_file = Path(embedded_app.project_directory) / ".mech_lock"

# Assert the lock file exists after saving it
assert lock_file.exists()
Expand Down

0 comments on commit 870eb8c

Please sign in to comment.