Skip to content

Commit

Permalink
chore: merging with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 committed Dec 16, 2024
2 parents e574837 + 6007ae0 commit 76edb08
Show file tree
Hide file tree
Showing 18 changed files with 333 additions and 100 deletions.
10 changes: 5 additions & 5 deletions .ci/build_matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ for version in "${versions[@]}"; do
fi

# Skipping student versions on auth_user
if [[ "$auth_user" == "true" && "$ON_STUDENT" == "true" ]]; then
echo "Skipping student versions when user is authenticated"
echo ""
continue
fi
# if [[ "$auth_user" == "true" && "$ON_STUDENT" == "true" ]]; then
# echo "Skipping student versions when user is authenticated"
# echo ""
# continue
# fi

# main logic
if [[ "$auth_user" == "true" ]]; then
Expand Down
114 changes: 111 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ env:
DPF_PORT: 21004
MAPDL_PACKAGE: ghcr.io/ansys/mapdl
ON_CI: True
PYTEST_ARGUMENTS: '-vvv -rxXsal --full-trace --tb=long --color=yes --durations=10 --random-order --random-order-bucket=class --maxfail=10 --reruns 3 --reruns-delay 4 --cov=ansys.mapdl.core --cov-report=html'
PYTEST_ARGUMENTS: '-vvv -rxXsal --full-trace --tb=long --color=yes --durations=10 --random-order --random-order-bucket=class --maxfail=10 --reruns 3 --reruns-delay 4 --cov=ansys.mapdl.core --cov-report=html --timeout=40'

BUILD_CHEATSHEET: True

Expand Down Expand Up @@ -615,7 +615,7 @@ jobs:
- id: set-matrix
env:
ONLY_UBUNTU: true
LIMIT_VERSIONS: 3
LIMIT_VERSIONS: 2
ON_SCHEDULE: ${{ github.event_name == 'schedule' }}
ON_WORKFLOW_DISPATCH: ${{ github.event_name == 'workflow_dispatch' }}
RUN_ALL_TEST: ${{ inputs.run_all_tests }}
Expand Down Expand Up @@ -821,7 +821,7 @@ jobs:
- name: "Unit testing requirements installation"
run: |
python -m pip install pytest pytest-rerunfailures pytest-cov pytest-random-order
python -m pip install pytest pytest-rerunfailures pytest-cov pytest-random-order pyfakefs pytest-timeout
- name: "Unit testing"
env:
Expand Down Expand Up @@ -865,6 +865,114 @@ jobs:
path: ./${{ matrix.mapdl-version }}-minimal.xml


build-test-ubuntu-console:
name: "Local-min-console: ${{ matrix.mapdl-version }}"
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
needs: [smoke-tests, build-test-local-minimal-matrix]
timeout-minutes: 75
strategy:
fail-fast: false
matrix: ${{fromJson(needs.build-test-local-minimal-matrix.outputs.matrix)}}
container:
image: ghcr.io/ansys/mapdl:${{ matrix.mapdl-version }}
options: -u=0:0 --oom-kill-disable --memory=6656MB --memory-swap=16896MB --shm-size=1gb --entrypoint /bin/bash
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
ON_LOCAL: true
ON_UBUNTU: true
TESTING_MINIMAL: true
ON_CONSOLE: true

steps:
- name: "Install Git and checkout project"
uses: actions/[email protected]
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}

- name: "Get if running student version"
id: student_check
run: |
if [[ "${{ matrix.mapdl-version }}" == *"student"* ]];
then export ON_STUDENT=true; export TAG_STUDENT="student";
else export ON_STUDENT=false; export TAG_STUDENT="non-student";
fi
echo "ON_STUDENT: $ON_STUDENT"
echo "TAG_STUDENT: $TAG_STUDENT"
echo "ON_STUDENT=$(echo $ON_STUDENT)" >> $GITHUB_OUTPUT
echo "TAG_STUDENT=$(echo $TAG_STUDENT)" >> $GITHUB_OUTPUT
- name: "Installing missing package"
run: |
sudo apt-get update
sudo apt-get install -y libgomp1
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- name: "Checking Python"
run: |
python --version
python -m pip install --upgrade pip
- name: "Install ansys-mapdl-core"
run: |
python -m pip install . --no-deps
python -m pip install -r minimum_requirements.txt
python -c "from ansys.mapdl import core as pymapdl; print('Import successfull')"
- name: "Unit testing requirements installation"
run: |
python -m pip install pytest pytest-rerunfailures pytest-cov pytest-random-order pyfakefs pytest-timeout
- name: "Unit testing"
env:
ANSYSLMD_LICENSE_FILE: "1055@${{ secrets.LICENSE_SERVER }}"
ON_STUDENT: ${{ steps.student_check.outputs.ON_STUDENT }}
run: |
echo "ON_UBUNTU: $ON_UBUNTU"
echo "ON_STUDENT: $ON_STUDENT"
# Because there is no 'ansys-tools-path' we need to input the
# executable path with the env var: PYMAPDL_MAPDL_EXEC.
if [[ "${{ matrix.mapdl-version }}" == *"latest-ubuntu"* ]] ; then
version=${{ env.LATEST_VERSION }}
else
version=$(echo "${{ matrix.mapdl-version }}" | head -c 5 | tail -c 4 | tr -d '.')
fi;
echo "Version: $version"
export PYMAPDL_MAPDL_EXEC=/ansys_inc/v"$version"/ansys/bin/ansys"$version"
echo "$PYMAPDL_MAPDL_EXEC"
unset PYMAPDL_START_INSTANCE
pytest -k "console" \
${{ env.PYTEST_ARGUMENTS }} \
--cov-report=xml:${{ matrix.mapdl-version }}-minimal-console.xml
- uses: codecov/codecov-action@v5
name: "Upload coverage to Codecov"
with:
token: ${{ secrets.CODECOV_TOKEN }} # required
root_dir: ${{ github.workspace }}
name: ${{ matrix.mapdl-version }}-minimal-console.xml
flags: ubuntu,local,${{ matrix.mapdl-version }},minimal,console,${{ steps.student_check.outputs.TAG_STUDENT }},dmp

- name: "Upload coverage artifacts"
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.mapdl-version }}-minimal-console.xml
path: ./${{ matrix.mapdl-version }}-minimal-console.xml


test-windows:
# Skipped
if: github.repository == ''
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3509.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: faking-v150
1 change: 1 addition & 0 deletions doc/changelog.d/3583.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: avoiding long names in test arguments
1 change: 1 addition & 0 deletions doc/changelog.d/3586.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: console launching
1 change: 1 addition & 0 deletions doc/changelog.d/3621.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests: adding timeout to each test
1 change: 1 addition & 0 deletions doc/changelog.d/3623.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ci: adding student back
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ tests = [
"pyfakefs==5.7.2",
"pyiges[full]==0.3.1",
"pytest-cov==6.0.0",
"pytest-memprof<0.3.0",
"pytest-pyvista==0.1.9",
"pytest-random-order==1.1.1",
"pytest-rerunfailures==15.0",
"pytest-timeout==2.3.1",
"pytest==8.3.4",
"scipy==1.14.1",
"vtk==9.4.0",
Expand Down Expand Up @@ -118,7 +118,7 @@ pymapdl_convert_script = "ansys.mapdl.core.cli:old_pymapdl_convert_script_entry_
pymapdl = "ansys.mapdl.core.cli:main"

[tool.pytest.ini_options]
addopts = "-rxXsa -vvv --maxfail=10 --random-order-bucket=class --random-order --durations=10"
addopts = "-rxXsa -vvv --maxfail=10 --random-order-bucket=class --random-order --durations=10 --timeout=40"
junit_family = "legacy"
filterwarnings = [
"ignore::FutureWarning",
Expand Down
4 changes: 4 additions & 0 deletions src/ansys/mapdl/core/information.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import weakref

from ansys.mapdl import core as pymapdl
from ansys.mapdl.core.errors import MapdlExitedError


def update_information_first(update=False):
Expand Down Expand Up @@ -122,6 +123,9 @@ def _update(self):
self._mapdl._log.debug("Information class: Updated")

def __repr__(self):
if self._mapdl.is_console and self._mapdl.exited:
return "MAPDL exited"

if not self._stats:
self._update()

Expand Down
56 changes: 39 additions & 17 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,25 @@ def launch_mapdl(

pre_check_args(args)

########################################
# PyPIM connection
# ----------------
# Delegating to PyPIM if applicable
#
if _HAS_PIM and exec_file is None and pypim.is_configured():
# Start MAPDL with PyPIM if the environment is configured for it
# and the user did not pass a directive on how to launch it.
LOG.info("Starting MAPDL remotely. The startup configuration will be ignored.")

return launch_remote_mapdl(
cleanup_on_exit=args["cleanup_on_exit"], version=args["version"]
)

########################################
# SLURM settings
# --------------
# Checking if running on SLURM HPC
#
if is_running_on_slurm(args):
LOG.info("On Slurm mode.")

Expand Down Expand Up @@ -1499,20 +1517,6 @@ def launch_mapdl(
env_vars.setdefault("ANS_MULTIPLE_NODES", "1")
env_vars.setdefault("HYDRA_BOOTSTRAP", "slurm")

########################################
# PyPIM connection
# ----------------
# Delegating to PyPIM if applicable
#
if _HAS_PIM and exec_file is None and pypim.is_configured():
# Start MAPDL with PyPIM if the environment is configured for it
# and the user did not pass a directive on how to launch it.
LOG.info("Starting MAPDL remotely. The startup configuration will be ignored.")

return launch_remote_mapdl(
cleanup_on_exit=args["cleanup_on_exit"], version=args["version"]
)

start_parm = generate_start_parameters(args)

# Early exit for debugging.
Expand Down Expand Up @@ -1569,6 +1573,7 @@ def launch_mapdl(
#
from ansys.mapdl.core.mapdl_console import MapdlConsole

start_parm = check_console_start_parameters(start_parm)
mapdl = MapdlConsole(
loglevel=args["loglevel"],
log_apdl=args["log_apdl"],
Expand Down Expand Up @@ -2101,6 +2106,7 @@ def generate_start_parameters(args: Dict[str, Any]) -> Dict[str, Any]:
start_parm["timeout"] = args["start_timeout"]

start_parm["launched"] = True
start_parm.pop("mode")

LOG.debug(f"Using start parameters {start_parm}")
return start_parm
Expand Down Expand Up @@ -2259,9 +2265,9 @@ def get_version(
raise VersionError(
"The MAPDL gRPC interface requires MAPDL 20.2 or later"
)

# Early exit
return
else:
# Early exit
return

if isinstance(version, float):
version = int(version * 10)
Expand Down Expand Up @@ -2871,3 +2877,19 @@ def submitter(
stderr=stderr,
env=env_vars,
) # nosec B603 B607


def check_console_start_parameters(start_parm):
valid_args = [
"exec_file",
"run_location",
"jobname",
"nproc",
"additional_switches",
"start_timeout",
]
for each in list(start_parm.keys()):
if each not in valid_args:
start_parm.pop(each)

return start_parm
5 changes: 4 additions & 1 deletion src/ansys/mapdl/core/mapdl_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,18 @@ def __init__(
self._continue_on_error = False
self._process = None
self._name = None
self._session_id = None
self._cleanup = None

self._launch(start_parm)
super().__init__(
loglevel=loglevel,
use_vtk=use_vtk,
log_apdl=log_apdl,
print_com=print_com,
mode="console",
**start_parm,
)
self._mode = "console"

def _launch(self, start_parm):
"""Connect to MAPDL process using pexpect"""
Expand Down
11 changes: 10 additions & 1 deletion src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
"jobid",
"jobname",
"launch_on_hpc",
"mode",
"nproc",
"override",
"port",
Expand Down Expand Up @@ -252,7 +253,7 @@ def __init__(
self._store_commands: bool = False
self._stored_commands = []
self._response = None
self._mode = None
self._mode = start_parm.get("mode", None)
self._mapdl_process = None
self._launched: bool = start_parm.get("launched", False)
self._stderr = None
Expand Down Expand Up @@ -1290,6 +1291,9 @@ def inner_wrapper(*args, **kwargs):

def _wrap_xsel_commands(self):
# Wrapping XSEL commands.
if self.is_console:
return

def wrap_xsel_function(func):
if hasattr(func, "__func__"):
func.__func__.__doc__ = inject_docs(
Expand Down Expand Up @@ -2179,6 +2183,11 @@ def run(
if "\n" in command or "\r" in command:
raise ValueError("Use ``input_strings`` for multi-line commands")

if len(command) > 639: # CMD_MAX_LENGTH
# If using mapdl_grpc, this check is redundant on purpose.
# Console probably do not have this limitation, but I'm not certain.
raise ValueError("Maximum command length must be less than 640 characters")

# Check kwargs
verbose = kwargs.pop("verbose", False)
save_fig = kwargs.pop("savefig", False)
Expand Down
1 change: 1 addition & 0 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ def __init__(
log_apdl=log_apdl,
log_file=log_file,
print_com=print_com,
mode="grpc",
**start_parm,
)
self._mode: Literal["grpc"] = "grpc"
Expand Down
Loading

0 comments on commit 76edb08

Please sign in to comment.