Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move macos ci/cd to github actions #62

Merged
merged 17 commits into from
Aug 6, 2021
Merged
46 changes: 0 additions & 46 deletions .ci/macos-install-python.sh

This file was deleted.

66 changes: 66 additions & 0 deletions .github/workflows/mac-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Mac Unit Testing and Deployment

on:
push:
branches: "*"
tags: "*"
pull_request:
branches: "**"

jobs:
macOS:
runs-on: macos-latest
name: Mac OS Unit Testing
strategy:
matrix:
python-version: ['3.8']

env:
SHELLOPTS: 'errexit:pipefail'

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Build wheels
uses: joerick/cibuildwheel@v2.0.1
env:
CIBW_BEFORE_BUILD: pip install -r requirements_build.txt
CIBW_BUILD: cp38-macosx_x86_64

- name: Build wheels
if: startsWith(github.event.ref, 'refs/tags')
uses: joerick/cibuildwheel@v2.0.1
env:
CIBW_BEFORE_BUILD: pip install -r requirements_build.txt
CIBW_SKIP: pp* cp38-macosx_x86_64

- name: Show files
run: ls -lh wheelhouse
shell: bash

- name: Upload wheels
uses: actions/upload-artifact@v2
with:
path: wheelhouse/*.whl

- name: Install wheel
run: |
pip install wheelhouse/*38*

- name: Test
run: |
pip install -r requirements_test.txt
cd tests
pytest -v

- name: Upload to PyPi
if: startsWith(github.event.ref, 'refs/tags')
run: |
twine upload -u __token__ --skip-existing wheelhouse/*
env:
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
22 changes: 0 additions & 22 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,3 @@ jobs:
- template: .ci/install_package.yml
- template: .ci/unit_testing.yml
- template: .ci/azure-publish-dist.yml


- job: macOS
strategy:
matrix:
Python36:
python.version: '3.6'
Python37:
python.version: '3.7'
Python38:
python.version: '3.8'
Python39:
python.version: '3.9'
pool:
vmImage: 'macOS-10.15'
steps:
- script: .ci/macos-install-python.sh '$(python.version)'
displayName: Install Python
- template: .ci/build_wheel.yml
- template: .ci/install_package.yml
- template: .ci/unit_testing_allow_error.yml
- template: .ci/azure-publish-dist.yml
2 changes: 1 addition & 1 deletion requirements_build.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
setuptools>=41.0.0
wheel>=0.33.0
numpy<1.20.0
cython==0.29.21
cython==0.29.24
matplotlib
34 changes: 34 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Installation file for ansys-mapdl-reader"""
import platform
import re
import subprocess
import struct
import os
import sys
Expand All @@ -13,6 +16,14 @@
raise Exception('Please install numpy first with "pip install numpy"')


# Facilities to install properly on Mac using clang
def is_clang(bin):
proc = subprocess.Popen([bin, '-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
output = str(b'\n'.join([stdout, stderr]).decode('ascii', 'ignore'))
return not re.search(r'clang', output) is None


def check_cython():
"""Check if binaries exist and if not check if Cython is installed"""
has_binary_reader = False
Expand Down Expand Up @@ -41,6 +52,29 @@ def finalize_options(self):
import numpy
self.include_dirs.append(numpy.get_include())

def build_extensions(self):
if os.name != 'nt':
binary = self.compiler.compiler[0]
if is_clang(binary):
for e in self.extensions:
e.extra_compile_args.append('-stdlib=libc++')

if platform.system() == 'Darwin':
mac_version, _, _ = platform.mac_ver()
major, minor, patch = [int(n) for n in mac_version.split('.')]

# libstdc++ is deprecated in recent versions of XCode
if minor >= 9:
e.extra_compile_args.append('-mmacosx-version-min=10.9')
e.extra_compile_args.append('-stdlib=libc++')
e.extra_link_args.append('-mmacosx-version-min=10.9')
e.extra_link_args.append('-stdlib=libc++')
else:
e.extra_compile_args.append('-mmacosx-version-min=10.7')
e.extra_link_args.append('-mmacosx-version-min=10.7')

_build_ext.build_extensions(self)


def compilerName():
""" Check compiler and assign compile arguments accordingly """
Expand Down
14 changes: 8 additions & 6 deletions tests/test_binary_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import platform
import shutil
import os

Expand All @@ -14,7 +15,6 @@
try:
from ansys.mapdl.core import _HAS_ANSYS
from ansys.mapdl.core.mapdl_grpc import MapdlGrpc
# from ansys.mapdl.core.mapdl_corba import MapdlCorba
MapdlCorba = None
from ansys.mapdl.core.mapdl_console import MapdlConsole
except:
Expand All @@ -33,9 +33,10 @@
test_path = os.path.dirname(os.path.abspath(__file__))
testfiles_path = os.path.join(test_path, 'testfiles')

IS_MAC = platform.system() == 'Darwin'
skip_no_ansys = pytest.mark.skipif(not _HAS_ANSYS, reason="Requires ANSYS installed")
skip_no_xserver = pytest.mark.skipif(not system_supports_plotting(),
reason="Requires active X Server")
skip_plotting = pytest.mark.skipif(not system_supports_plotting() or IS_MAC,
reason="Requires active X Server")

RSETS = list(zip(range(1, 9), [1]*8))

Expand Down Expand Up @@ -357,7 +358,7 @@ def test_save_as_vtk(tmpdir, result, result_type):
assert np.allclose(arr, rst_arr, atol=1E-5, equal_nan=True)


@skip_no_xserver
@skip_plotting
def test_plot_component():
"""
# create example file for component plotting
Expand Down Expand Up @@ -411,7 +412,7 @@ def test_file_close(tmpdir):
os.remove(tmpfile) # tests file has been correctly closed


@skip_no_xserver
@skip_plotting
@pytest.mark.skipif(not HAS_FFMPEG, reason="requires imageio_ffmpeg")
def test_animate_nodal_solution(tmpdir, result):
temp_movie = str(tmpdir.mkdir("tmpdir").join('tmp.mp4'))
Expand Down Expand Up @@ -455,7 +456,8 @@ def test_thermal_result(thermal_rst):

def test_plot_temperature(thermal_rst):
cpos = thermal_rst.plot_nodal_temperature(0, return_cpos=True)
assert isinstance(cpos, CameraPosition)
if cpos is not None:
assert isinstance(cpos, CameraPosition)


def test_file_not_found():
Expand Down
44 changes: 25 additions & 19 deletions tests/test_cyclic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import platform
import os

import numpy as np
Expand Down Expand Up @@ -30,8 +31,9 @@
except:
result_z = None

skip_with_no_xserver = pytest.mark.skipif(not system_supports_plotting(),
reason="Requires active X Server")
IS_MAC = platform.system() == 'Darwin'
skip_plotting = pytest.mark.skipif(not system_supports_plotting() or IS_MAC,
reason="Requires active X Server")


# static result x axis
Expand Down Expand Up @@ -105,35 +107,39 @@ def test_non_cyclic():
rst = CyclicResult(examples.rstfile)


@skip_with_no_xserver
@skip_plotting
@pytest.mark.skipif(result_z is None, reason="Requires result file")
def test_plot_sectors(tmpdir):
filename = str(tmpdir.mkdir("tmpdir").join('tmp.png'))
cpos = result_z.plot_sectors(screenshot=filename)
assert isinstance(cpos, CameraPosition)
if cpos is not None:
assert isinstance(cpos, CameraPosition)
assert os.path.isfile(filename)


@skip_with_no_xserver
@skip_plotting
def test_plot_sectors_x(result_x):
cpos = result_x.plot_sectors()
assert isinstance(cpos, CameraPosition)
if cpos is not None:
assert isinstance(cpos, CameraPosition)


@skip_with_no_xserver
@skip_plotting
@pytest.mark.skipif(result_z is None, reason="Requires result file")
def test_plot_z_cyc():
cpos = result_z.plot()
assert isinstance(cpos, CameraPosition)
if cpos is not None:
assert isinstance(cpos, CameraPosition)


@skip_with_no_xserver
@skip_plotting
def test_plot_x_cyc(result_x):
cpos = result_x.plot()
assert isinstance(cpos, CameraPosition)
if cpos is not None:
assert isinstance(cpos, CameraPosition)


@skip_with_no_xserver
@skip_plotting
def test_plot_component_rotor(cyclic_v182_z_with_comp):
cyclic_v182_z_with_comp.plot_nodal_solution(0, full_rotor=False,
node_components='REFINE',
Expand Down Expand Up @@ -270,7 +276,7 @@ def test_full_z_nodal_solution_phase(cyclic_v182_z):
assert np.allclose(disp[:, mask], tmp)


@skip_with_no_xserver
@skip_plotting
def test_full_x_nodal_solution_plot(result_x):
result_x.plot_nodal_solution(0)

Expand Down Expand Up @@ -339,7 +345,7 @@ def test_full_x_principal_nodal_stress(result_x):
assert np.allclose(stress[:, mask], tmp, atol=4E-3) # too loose


@skip_with_no_xserver
@skip_plotting
@pytest.mark.skipif(not HAS_FFMPEG, reason="requires imageio_ffmpeg")
@pytest.mark.skipif(result_z is None, reason="Requires result file")
def test_animate_nodal_solution(tmpdir):
Expand Down Expand Up @@ -368,17 +374,17 @@ def test_cyclic_z_harmonic_displacement():
assert np.allclose(disp[:, mask], tmp, atol=1E-5)


@skip_with_no_xserver
@skip_plotting
def test_plot_nodal_stress(result_x):
result_x.plot_nodal_stress(0, 'z')


@skip_with_no_xserver
@skip_plotting
def test_plot_nodal_stress(result_x):
result_x.plot_nodal_stress(0, 'z')


@skip_with_no_xserver
@skip_plotting
def test_plot_principal_nodal_stress(result_x):
result_x.plot_principal_nodal_stress(0, 'seqv')

Expand All @@ -399,7 +405,7 @@ def test_nodal_elastic_strain_cyclic(result_x):
assert np.allclose(stress, stress_ans)


@skip_with_no_xserver
@skip_plotting
def test_plot_nodal_elastic_strain(result_x):
result_x.plot_nodal_elastic_strain(0, 'X')

Expand All @@ -420,7 +426,7 @@ def test_nodal_temperature(result_x):
assert np.allclose(temp[mask], temp_ans[:, mask], equal_nan=True)


@skip_with_no_xserver
@skip_plotting
def test_plot_nodal_nodal_temperature(result_x):
result_x.plot_nodal_temperature(0)

Expand All @@ -440,6 +446,6 @@ def test_nodal_thermal_strain_cyclic(result_x):
assert np.allclose(strain, strain_ans)


@skip_with_no_xserver
@skip_plotting
def test_plot_nodal_thermal_strain(result_x):
result_x.plot_nodal_thermal_strain(0, 'X')
Loading