From 0861e9f303b34951d08a5a0df96edb7ecba76f67 Mon Sep 17 00:00:00 2001 From: Alex Kaszynski Date: Mon, 31 Jan 2022 15:25:59 -0700 Subject: [PATCH] build python 3.10 (#101) * add py310 req and setup * add back missing CI * fix build_wheels.sh * correct terms * upgrade numpy for py 3.10 * do not use req_build * add back in req_build * use req in build * attempt to run all tests * fix install req * disable plot testing for 3.10 * check version correctly --- .ci/build_wheels.sh | 3 + .github/workflows/testing-and-deployment.yml | 22 ++---- pyproject.toml | 7 ++ requirements.txt | 5 -- requirements_build.txt | 3 +- requirements_test.txt | 2 +- setup.py | 77 ++++++++------------ tests/test_cyclic.py | 9 ++- 8 files changed, 59 insertions(+), 69 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements.txt diff --git a/.ci/build_wheels.sh b/.ci/build_wheels.sh index 2d8849de..14bcc9f6 100755 --- a/.ci/build_wheels.sh +++ b/.ci/build_wheels.sh @@ -24,6 +24,9 @@ case $PYTHON_VERSION in 3.9) PYBIN="/opt/python/cp39-cp39/bin" ;; +3.10) + PYBIN="/opt/python/cp310-cp310/bin" + ;; esac # build, don't install diff --git a/.github/workflows/testing-and-deployment.yml b/.github/workflows/testing-and-deployment.yml index 01c9ba36..b17d868f 100644 --- a/.github/workflows/testing-and-deployment.yml +++ b/.github/workflows/testing-and-deployment.yml @@ -29,7 +29,6 @@ jobs: run: | pip install -r requirements_style.txt --disable-pip-version-check make - doc_build: name: Build Documentation runs-on: ubuntu-latest @@ -48,7 +47,6 @@ jobs: sudo apt-get install libgl1-mesa-glx xvfb pip install pyvista xvfb-run python -c "import pyvista; print(pyvista.Report())" - - name: Install ansys-mapdl-reader run: | pip install -r requirements_build.txt --disable-pip-version-check @@ -56,7 +54,6 @@ jobs: pip install dist/ansys*.whl --disable-pip-version-check cd tests/ xvfb-run python -c "from ansys.mapdl import reader as pymapdl_reader; print(pymapdl_reader.Report())" - - name: Build Documentation run: | sudo apt install pandoc -qy @@ -65,7 +62,6 @@ jobs: sudo apt install zip cd doc/build/html/ zip ../../../${{ env.PACKAGE_NAME }}-HTML.zip ./* - - name: Upload uses: actions/upload-artifact@v2 with: @@ -89,7 +85,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ['3.6', '3.7', '3.8', '3.9'] + python-version: ['3.6', '3.7', '3.8', '3.9', '3.10'] os: [ubuntu-latest, windows-latest] steps: @@ -135,9 +131,8 @@ jobs: - name: Build wheel on Windows if: ${{ runner.os == 'Windows' }} run: | - pip install -r requirements_build.txt - python setup.py bdist_wheel - python setup.py sdist + pip install build + python -m build - name: Validate wheel run: | @@ -181,17 +176,16 @@ jobs: sudo apt-get install libgl1-mesa-glx xvfb xvfb-run python -c "import pyvista; print(pyvista.Report())" + - name: Install test requirements + run: pip install -r requirements_test.txt + - name: Test with XVFB if: ${{ runner.os == 'Linux' }} - run: | - pip install -r requirements_test.txt - xvfb-run pytest -v tests/ --durations=0 + run: xvfb-run pytest -v tests/ --durations=0 - name: Test without XVFB if: ${{ runner.os == 'Windows' }} - run: | - pip install -r requirements_test.txt - pytest -v tests/ --durations=0 + run: pytest -v tests/ --durations=0 - name: Upload wheel uses: actions/upload-artifact@v2 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..6a19e417 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = [ + "setuptools>=41.0.0", + "wheel>=0.33.0", + "numpy<=1.22.1", + "cython==0.29.24", +] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index c4e7494d..00000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -numpy>=1.14.0 -pyvista>=0.27.2 -appdirs>=1.4.0 -tqdm>=4.45.0 -matplotlib>=3.0.0 diff --git a/requirements_build.txt b/requirements_build.txt index c79e6c8f..97b2b3a3 100644 --- a/requirements_build.txt +++ b/requirements_build.txt @@ -1,5 +1,6 @@ setuptools>=41.0.0 wheel>=0.33.0 -numpy<1.20.0 +numpy<1.20.0;python_version<"3.10" +numpy==1.22.1;python_version>="3.10" cython==0.29.24 matplotlib diff --git a/requirements_test.txt b/requirements_test.txt index f04789e1..08b95fcc 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -3,6 +3,6 @@ pytest matplotlib pytest pytest-cov -vtk<9.1.0 +vtk<9.1.0;python_version<"3.10" pyvista>=0.24.0 ansys-mapdl-core==0.60.4 diff --git a/setup.py b/setup.py index 7cade675..50501038 100644 --- a/setup.py +++ b/setup.py @@ -1,20 +1,15 @@ """Installation file for ansys-mapdl-reader""" +from io import open as io_open +from setuptools import setup, Extension +from setuptools.command.build_ext import build_ext as _build_ext +import os import platform import re -import subprocess import struct -import os +import subprocess import sys -from io import open as io_open - -from setuptools import setup, Extension -from setuptools.command.build_ext import build_ext as _build_ext - -try: - import numpy as np -except ImportError: - raise Exception('Please install numpy first with "pip install numpy"') +import numpy as np # Facilities to install properly on Mac using clang def is_clang(bin): @@ -24,33 +19,8 @@ def is_clang(bin): 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 - for filename in os.listdir('ansys/mapdl/reader'): - if '_binary_reader' in filename: - has_binary_reader = True - - if not has_binary_reader: - # ensure cython is installed before trying to build - try: - import cython - except ImportError: - raise ImportError('\n\n\nTo build pyansys please install Cython with:\n\n' - 'pip install cython\n\n') from None - - -check_cython() - - class build_ext(_build_ext): """ build class that includes numpy directory """ - def finalize_options(self): - _build_ext.finalize_options(self) - # Prevent numpy from thinking it is still in its setup process: - __builtins__.__NUMPY_SETUP__ = False - import numpy - self.include_dirs.append(numpy.get_include()) def build_extensions(self): if os.name != 'nt': @@ -77,7 +47,7 @@ def build_extensions(self): _build_ext.build_extensions(self) -def compilerName(): +def compiler_name(): """ Check compiler and assign compile arguments accordingly """ import re import distutils.ccompiler @@ -104,7 +74,7 @@ def compilerName(): # Assign arguments based on compiler -compiler = compilerName() +compiler = compiler_name() if compiler == 'unix': cmp_arg = ['-O3', '-w'] else: @@ -119,16 +89,19 @@ def compilerName(): # execute file from raw string exec(fd.read()) -install_requires = ['numpy>=1.16.0', - 'pyvista>=0.32.0', - 'appdirs>=1.4.0', - 'matplotlib>=3.0.0', - 'tqdm>=4.45.0'] +install_requires = [ + 'numpy>=1.16.0', + 'pyvista>=0.32.0', + 'appdirs>=1.4.0', + 'matplotlib>=3.0.0', + 'tqdm>=4.45.0' +] # perform python version checking # this is necessary to avoid the new pip package checking as vtk does # not support Python 32-bit as of 17 June 2021. -if not struct.calcsize("P")*8 == 64: +is64 = struct.calcsize("P") * 8 == 64 +if not is64: try: import vtk except ImportError: @@ -136,7 +109,19 @@ def compilerName(): 'Please check the version of Python installed at\n' '%s' % sys.executable) -# Actual setup + +if sys.version_info.minor == 10 and is64: + # use pip to check if vtk is available or installed + sys_name = platform.system() + if sys_name == 'Linux': + install_requires.append( + 'vtk @ https://github.com/pyvista/pyvista-wheels/raw/main/vtk-9.1.0.dev0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl', + ) + elif sys_name == 'Windows': + install_requires.append( + 'vtk @ https://github.com/pyvista/pyvista-wheels/raw/main/vtk-9.1.0.dev0-cp310-cp310-win_amd64.whl', + ) + setup( name='ansys-mapdl-reader', packages=['ansys.mapdl.reader', 'ansys.mapdl.reader.examples'], @@ -157,11 +142,13 @@ def compilerName(): 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', ], url='https://github.com/pyansys/pymapdl-reader', # Build cython modules cmdclass={'build_ext': build_ext}, + include_dirs=[np.get_include()], ext_modules=[ Extension('ansys.mapdl.reader._archive', ['ansys/mapdl/reader/cython/_archive.pyx', diff --git a/tests/test_cyclic.py b/tests/test_cyclic.py index 0146aecb..270e5db1 100644 --- a/tests/test_cyclic.py +++ b/tests/test_cyclic.py @@ -1,5 +1,6 @@ -import platform import os +import platform +import sys import numpy as np import pytest @@ -32,8 +33,10 @@ result_z = None IS_MAC = platform.system() == 'Darwin' -skip_plotting = pytest.mark.skipif(not system_supports_plotting() or IS_MAC, - reason="Requires active X Server") +skip_plotting = pytest.mark.skipif( + not system_supports_plotting() or IS_MAC or sys.version_info >= (3, 10), + reason="Plotting disabled for these tests" +) # static result x axis