From dea060720258f23ea5ea2848ee16b4dbf1cca2db Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Fri, 20 Oct 2023 13:28:12 -0300 Subject: [PATCH] try windows --- .github/workflows/build_latest.yml | 104 +++++++++++++++++++++++++++++ .github/workflows/build_master.yml | 78 ++++++++++++++++++++++ .github/workflows/build_old.yml | 104 +++++++++++++++++++++++++++++ .github/workflows/cibuildwheel.yml | 58 ++++++++++++++-- .github/workflows/miniconda.yml | 89 ++++++++++++++++++++++++ pyproject.toml | 1 + test/tst_multifile.py | 4 +- test/tst_multifile2.py | 6 +- 8 files changed, 434 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/build_latest.yml create mode 100644 .github/workflows/build_master.yml create mode 100644 .github/workflows/build_old.yml create mode 100644 .github/workflows/miniconda.yml diff --git a/.github/workflows/build_latest.yml b/.github/workflows/build_latest.yml new file mode 100644 index 000000000..fab9510db --- /dev/null +++ b/.github/workflows/build_latest.yml @@ -0,0 +1,104 @@ +name: Build and Test Linux with latest netcdf-c +on: [push, pull_request] +jobs: + build-linux: + name: Python (${{ matrix.python-version }}) + runs-on: ubuntu-latest + env: + PNETCDF_VERSION: 1.12.1 + NETCDF_VERSION: 4.9.2 + NETCDF_DIR: ${{ github.workspace }}/.. + NETCDF_EXTRA_CONFIG: --enable-pnetcdf + CC: mpicc.mpich + #NO_NET: 1 + strategy: + matrix: + python-version: ["3.11"] + steps: + + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Ubuntu Dependencies + run: | + sudo apt-get update + sudo apt-get install mpich libmpich-dev libhdf5-mpich-dev libcurl4-openssl-dev bzip2 libsnappy-dev libblosc-dev libzstd-dev + echo "Download and build PnetCDF version ${PNETCDF_VERSION}" + wget https://parallel-netcdf.github.io/Release/pnetcdf-${PNETCDF_VERSION}.tar.gz + tar -xzf pnetcdf-${PNETCDF_VERSION}.tar.gz + pushd pnetcdf-${PNETCDF_VERSION} + ./configure --prefix $NETCDF_DIR --enable-shared --disable-fortran --disable-cxx + make -j 2 + make install + popd + echo "Download and build netCDF version ${NETCDF_VERSION}" + wget https://downloads.unidata.ucar.edu/netcdf-c/${NETCDF_VERSION}/netcdf-c-${NETCDF_VERSION}.tar.gz + tar -xzf netcdf-c-${NETCDF_VERSION}.tar.gz + pushd netcdf-c-${NETCDF_VERSION} + export CPPFLAGS="-I/usr/include/hdf5/mpich -I${NETCDF_DIR}/include" + export LDFLAGS="-L${NETCDF_DIR}/lib" + export LIBS="-lhdf5_mpich_hl -lhdf5_mpich -lm -lz" + ./configure --prefix $NETCDF_DIR --enable-netcdf-4 --enable-shared --enable-dap --enable-parallel4 $NETCDF_EXTRA_CONFIG + make -j 2 + make install + popd + +# - name: The job has failed +# if: ${{ failure() }} +# run: | +# cd netcdf-c-${NETCDF_VERSION} +# cat config.log + + - name: Install python dependencies via pip + run: | + python -m pip install --upgrade pip + pip install numpy cython cftime pytest twine wheel check-manifest mpi4py + + - name: Install netcdf4-python + run: | + export PATH=${NETCDF_DIR}/bin:${PATH} + export NETCDF_PLUGIN_DIR=${{ github.workspace }}/netcdf-c-${NETCDF_VERSION}/plugins/plugindir + python setup.py install + - name: Test + run: | + export PATH=${NETCDF_DIR}/bin:${PATH} + python checkversion.py + # serial + cd test + python run_all.py + # parallel (hdf5 for netcdf4, pnetcdf for netcdf3) + cd ../examples + mpirun.mpich -np 4 python mpi_example.py + if [ $? -ne 0 ] ; then + echo "hdf5 mpi test failed!" + exit 1 + else + echo "hdf5 mpi test passed!" + fi + mpirun.mpich -np 4 python mpi_example_compressed.py + if [ $? -ne 0 ] ; then + echo "hdf5 compressed mpi test failed!" + exit 1 + else + echo "hdf5 compressed mpi test passed!" + fi + mpirun.mpich -np 4 python mpi_example.py NETCDF3_64BIT_DATA + if [ $? -ne 0 ] ; then + echo "pnetcdf mpi test failed!" + exit 1 + else + echo "pnetcdf mpi test passed!" + fi + +# - name: Tarball +# run: | +# export PATH=${NETCDF_DIR}/bin:${PATH} +# python setup.py --version +# check-manifest --version +# check-manifest --verbose +# pip wheel . -w dist --no-deps +# twine check dist/* diff --git a/.github/workflows/build_master.yml b/.github/workflows/build_master.yml new file mode 100644 index 000000000..3bd836abd --- /dev/null +++ b/.github/workflows/build_master.yml @@ -0,0 +1,78 @@ +name: Build and Test on Linux with netcdf-c github master +on: [push, pull_request] +jobs: + build-linux: + name: Python (${{ matrix.python-version }}) + runs-on: ubuntu-latest + env: + NETCDF_DIR: ${{ github.workspace }}/.. + CC: mpicc.mpich + #NO_NET: 1 + strategy: + matrix: + python-version: ["3.11"] + steps: + + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Ubuntu Dependencies + run: | + sudo apt-get update + sudo apt-get install mpich libmpich-dev libhdf5-mpich-dev libcurl4-openssl-dev bzip2 libsnappy-dev libblosc-dev libzstd-dev + echo "Download and build netCDF github master" + git clone https://github.com/Unidata/netcdf-c + pushd netcdf-c + export CPPFLAGS="-I/usr/include/hdf5/mpich -I${NETCDF_DIR}/include" + export LDFLAGS="-L${NETCDF_DIR}/lib" + export LIBS="-lhdf5_mpich_hl -lhdf5_mpich -lm -lz" + autoreconf -i + ./configure --prefix $NETCDF_DIR --enable-netcdf-4 --enable-shared --enable-dap --enable-parallel4 + make -j 2 + make install + popd + +# - name: The job has failed +# if: ${{ failure() }} +# run: | +# cd netcdf-c-${NETCDF_VERSION} +# cat config.log + + - name: Install python dependencies via pip + run: | + python -m pip install --upgrade pip + pip install numpy cython cftime pytest twine wheel check-manifest mpi4py + + - name: Install netcdf4-python + run: | + export PATH=${NETCDF_DIR}/bin:${PATH} + export NETCDF_PLUGIN_DIR=${{ github.workspace }}/netcdf-c/plugins/plugindir + python setup.py install + - name: Test + run: | + export PATH=${NETCDF_DIR}/bin:${PATH} + #export HDF5_PLUGIN_PATH=${NETCDF_DIR}/plugins/plugindir + python checkversion.py + # serial + cd test + python run_all.py + # parallel + cd ../examples + mpirun.mpich -np 4 python mpi_example.py + if [ $? -ne 0 ] ; then + echo "hdf5 mpi test failed!" + exit 1 + else + echo "hdf5 mpi test passed!" + fi + mpirun.mpich -np 4 python mpi_example_compressed.py + if [ $? -ne 0 ] ; then + echo "hdf5 compressed mpi test failed!" + exit 1 + else + echo "hdf5 compressed mpi test passed!" + fi diff --git a/.github/workflows/build_old.yml b/.github/workflows/build_old.yml new file mode 100644 index 000000000..c06d37604 --- /dev/null +++ b/.github/workflows/build_old.yml @@ -0,0 +1,104 @@ +name: Build and Test Linux with older netcdf-c +on: [push, pull_request] +jobs: + build-linux: + name: Python (${{ matrix.python-version }}) + runs-on: ubuntu-latest + env: + PNETCDF_VERSION: 1.12.1 + NETCDF_VERSION: 4.8.1 + NETCDF_DIR: ${{ github.workspace }}/.. + NETCDF_EXTRA_CONFIG: --enable-pnetcdf + CC: mpicc.mpich + #NO_NET: 1 + strategy: + matrix: + python-version: ["3.11"] + steps: + + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Ubuntu Dependencies + run: | + sudo apt-get update + sudo apt-get install mpich libmpich-dev libhdf5-mpich-dev libcurl4-openssl-dev bzip2 libsnappy-dev libblosc-dev libzstd-dev + echo "Download and build PnetCDF version ${PNETCDF_VERSION}" + wget https://parallel-netcdf.github.io/Release/pnetcdf-${PNETCDF_VERSION}.tar.gz + tar -xzf pnetcdf-${PNETCDF_VERSION}.tar.gz + pushd pnetcdf-${PNETCDF_VERSION} + ./configure --prefix $NETCDF_DIR --enable-shared --disable-fortran --disable-cxx + make -j 2 + make install + popd + echo "Download and build netCDF version ${NETCDF_VERSION}" + wget https://downloads.unidata.ucar.edu/netcdf-c/${NETCDF_VERSION}/netcdf-c-${NETCDF_VERSION}.tar.gz + tar -xzf netcdf-c-${NETCDF_VERSION}.tar.gz + pushd netcdf-c-${NETCDF_VERSION} + export CPPFLAGS="-I/usr/include/hdf5/mpich -I${NETCDF_DIR}/include" + export LDFLAGS="-L${NETCDF_DIR}/lib" + export LIBS="-lhdf5_mpich_hl -lhdf5_mpich -lm -lz" + ./configure --prefix $NETCDF_DIR --enable-netcdf-4 --enable-shared --enable-dap --enable-parallel4 $NETCDF_EXTRA_CONFIG + make -j 2 + make install + popd + +# - name: The job has failed +# if: ${{ failure() }} +# run: | +# cd netcdf-c-${NETCDF_VERSION} +# cat config.log + + - name: Install python dependencies via pip + run: | + python -m pip install --upgrade pip + pip install numpy cython cftime pytest twine wheel check-manifest mpi4py + + - name: Install netcdf4-python + run: | + export PATH=${NETCDF_DIR}/bin:${PATH} + export NETCDF_PLUGIN_DIR=${{ github.workspace }}/netcdf-c-${NETCDF_VERSION}/plugins/plugindir + python setup.py install + - name: Test + run: | + export PATH=${NETCDF_DIR}/bin:${PATH} + python checkversion.py + # serial + cd test + python run_all.py + # parallel (hdf5 for netcdf4, pnetcdf for netcdf3) + cd ../examples + mpirun.mpich -np 4 python mpi_example.py + if [ $? -ne 0 ] ; then + echo "hdf5 mpi test failed!" + exit 1 + else + echo "hdf5 mpi test passed!" + fi + mpirun.mpich -np 4 python mpi_example_compressed.py + if [ $? -ne 0 ] ; then + echo "hdf5 compressed mpi test failed!" + exit 1 + else + echo "hdf5 compressed mpi test passed!" + fi + mpirun.mpich -np 4 python mpi_example.py NETCDF3_64BIT_DATA + if [ $? -ne 0 ] ; then + echo "pnetcdf mpi test failed!" + exit 1 + else + echo "pnetcdf mpi test passed!" + fi + +# - name: Tarball +# run: | +# export PATH=${NETCDF_DIR}/bin:${PATH} +# python setup.py --version +# check-manifest --version +# check-manifest --verbose +# pip wheel . -w dist --no-deps +# twine check dist/* diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml index 2f2982459..4504ab31d 100644 --- a/.github/workflows/cibuildwheel.yml +++ b/.github/workflows/cibuildwheel.yml @@ -19,9 +19,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - submodules: true - uses: actions/setup-python@v4 name: Install Python @@ -82,8 +79,59 @@ jobs: name: pypi-artifacts path: ${{ github.workspace }}/wheelhouse/*.whl + + build_wheels_windows: + name: Build wheels for ${{matrix.arch}} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest] + arch: [win_amd64] + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v4 + name: Install Python + with: + python-version: 3.x + + - name: Setup Micromamba Python ${{ matrix.python-version }} + uses: mamba-org/setup-micromamba@v1 + with: + environment-name: build + init-shell: bash + create-args: >- + python=${{ matrix.python-version }} hdf5 libnetcdf --channel conda-forge + + - name: Install cibuildwheel + run: | + python -m pip install --upgrade cibuildwheel + + - name: Build wheels for Windows (${{ matrix.arch }}) + run: cibuildwheel --output-dir wheelhouse + env: + CIBW_BUILD: "cp39-${{ matrix.arch }} cp310-${{ matrix.arch }} cp311-${{ matrix.arch }} cp312-${{ matrix.arch }}" + CIBW_ENVIRONMENT_WINDOWS: > + HDF5_DIR="C:\\Users\\runneradmin\\micromamba\\envs\\build\\Library" + netCDF4_DIR="C:\\Users\\runneradmin\\micromamba\\envs\\build\\Library" + PATH="C:\\Users\\runneradmin\\micromamba\\envs\\build\\Library\\bin;${PATH}" + CIBW_BEFORE_BUILD: "python -m pip install delvewheel" + CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}" + CIBW_TEST_COMMAND: > + python -c "import netCDF4; print(f'netCDF4 v{netCDF4.__version__}')" + && xcopy {project}\\test . /E/H + && python -m pip install --upgrade numpy cython packaging + && python run_all.py + + - uses: actions/upload-artifact@v3 + with: + name: pypi-artifacts + path: ${{ github.workspace }}/wheelhouse/*.whl + + show-artifacts: - needs: [build_bdist, build_sdist] + needs: [build_bdist, build_sdist, build_wheels_windows] name: "Show artifacts" runs-on: ubuntu-latest steps: @@ -98,7 +146,7 @@ jobs: publish-artifacts-pypi: - needs: [build_bdist, build_sdist] + needs: [build_bdist, build_sdist, build_wheels_windows] name: "Publish to PyPI" runs-on: ubuntu-latest # upload to PyPI for every tag starting with 'v' diff --git a/.github/workflows/miniconda.yml b/.github/workflows/miniconda.yml new file mode 100644 index 000000000..03f982b3c --- /dev/null +++ b/.github/workflows/miniconda.yml @@ -0,0 +1,89 @@ +name: Build and Test + +on: + pull_request: + push: + branches: [master] + +jobs: + run-serial: + runs-on: ${{ matrix.os }} + #env: + # NO_NET: 1 + strategy: + matrix: + python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] + os: [windows-latest, ubuntu-latest, macos-latest] + platform: [x64, x32] + exclude: + - os: macos-latest + platform: x32 + fail-fast: false + + steps: + - uses: actions/checkout@v3 + + - name: Setup Micromamba + uses: mamba-org/setup-micromamba@v1 + with: + environment-name: TEST + init-shell: bash + create-args: >- + python=${{ matrix.python-version }} + numpy cython pip pytest hdf5 libnetcdf cftime zlib certifi + --channel conda-forge + + - name: Install netcdf4-python + shell: bash -l {0} + run: | + export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH" # so setup.py finds nc-config + python -m pip install -v -e . --no-deps --force-reinstall + + - name: Tests + shell: bash -l {0} + run: | + cd test && python run_all.py + + run-mpi: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: [ "3.11" ] + os: [ubuntu-latest] + platform: [x64] + steps: + - uses: actions/checkout@v3 + + - name: Setup Micromamba + uses: mamba-org/setup-micromamba@v1 + with: + environment-name: TEST + init-shell: bash + create-args: >- + python=${{ matrix.python-version }} + numpy cython pip pytest mpi4py hdf5=*=mpi* libnetcdf=*=mpi* cftime zlib certifi + --channel conda-forge + + - name: Install netcdf4-python with mpi + shell: bash -l {0} + run: | + export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH" # so setup.py finds nc-config + nc-config --all + python -m pip install -v -e . --no-build-isolation --no-deps --force-reinstall + + - name: Tests + shell: bash -l {0} + run: | + cd test && python run_all.py + cd ../examples + export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH" + which mpirun + mpirun --version + #mpirun -np 4 --oversubscribe python mpi_example.py # for openmpi + mpirun -np 4 python mpi_example.py + if [ $? -ne 0 ] ; then + echo "hdf5 mpi test failed!" + exit 1 + else + echo "hdf5 mpi test passed!" + fi diff --git a/pyproject.toml b/pyproject.toml index 01562cefb..d115c0d32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,7 @@ requires = [ "Cython>=0.29", "oldest-supported-numpy", "setuptools>=61", + "packaging", ] build-backend = "setuptools.build_meta" diff --git a/test/tst_multifile.py b/test/tst_multifile.py index 0d9584892..93d72bded 100644 --- a/test/tst_multifile.py +++ b/test/tst_multifile.py @@ -5,7 +5,7 @@ from numpy import ma import tempfile, unittest, os, datetime import cftime -from pkg_resources import parse_version +from packaging.version import Version nx=100; ydim=5; zdim=10 nfiles = 10 @@ -138,7 +138,7 @@ def runTest(self): assert_equal(T.typecode(), t.typecode()) # skip this until cftime pull request #55 is in a released # version (1.0.1?). Otherwise, fix for issue #808 breaks this - if parse_version(cftime.__version__) >= parse_version('1.0.1'): + if Version(cftime.__version__) >= Version('1.0.1'): assert_array_equal(cftime.num2date(T[:], T.units, T.calendar), dates) assert_equal(cftime.date2index(datetime.datetime(1980, 1, 2), T), 366) f.close() diff --git a/test/tst_multifile2.py b/test/tst_multifile2.py index f818fcaba..f8e8552a6 100644 --- a/test/tst_multifile2.py +++ b/test/tst_multifile2.py @@ -5,7 +5,7 @@ from numpy import ma import tempfile, unittest, os, datetime import cftime -from pkg_resources import parse_version +from packaging.version import Version nx=100; ydim=5; zdim=10 nfiles = 10 @@ -106,7 +106,7 @@ def runTest(self): # Get the real dates # skip this until cftime pull request #55 is in a released # version (1.0.1?). Otherwise, fix for issue #808 breaks this - if parse_version(cftime.__version__) >= parse_version('1.0.1'): + if Version(cftime.__version__) >= Version('1.0.1'): dates = [] for file in self.files: f = Dataset(file) @@ -126,7 +126,7 @@ def runTest(self): assert_equal(T.typecode(), t.typecode()) # skip this until cftime pull request #55 is in a released # version (1.0.1?). Otherwise, fix for issue #808 breaks this - if parse_version(cftime.__version__) >= parse_version('1.0.1'): + if Version(cftime.__version__) >= Version('1.0.1'): assert_array_equal(cftime.num2date(T[:], T.units, T.calendar), dates) assert_equal(cftime.date2index(datetime.datetime(1980, 1, 2), T), 366) f.close()