Skip to content

Commit

Permalink
Merge pull request #200 from NSLS-II/fix-osx-compilation
Browse files Browse the repository at this point in the history
Fix OSX compilation
  • Loading branch information
mrakitin authored Jun 5, 2024
2 parents f7d2757 + f142444 commit 36ec565
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 62 deletions.
142 changes: 98 additions & 44 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -1,91 +1,145 @@
name: CI-Test

on: [push, pull_request]
on:
push:
pull_request:
workflow_dispatch:
release:
types: [published, created]

jobs:

lint:
# pull requests are a duplicate of a branch push if within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected]
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected]

test:
# pull requests are a duplicate of a branch push if within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository

name: Tests
runs-on: ${{ matrix.host-os }}
needs: lint

strategy:
matrix:
# host-os: ["ubuntu-latest", "macos-13", "macos-14"]
host-os: ["ubuntu-latest"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false

defaults:
run:
shell: bash -l {0}

steps:
- name: Set env.REPOSITORY_NAME # just the repo, as opposed to org/repo
- name: Checkout the code
uses: actions/checkout@v4

- name: Set env vars
run: |
export REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}
export REPOSITORY_NAME=${GITHUB_REPOSITORY#*/} # just the repo, as opposed to org/repo
echo "REPOSITORY_NAME=${REPOSITORY_NAME}" >> $GITHUB_ENV
- name: Checkout the code
uses: actions/checkout@v4
python_version="${{ matrix.python-version }}"
export PYTHON_VERSION_NODOT="${python_version//\./}"
echo "PYTHON_VERSION_NODOT=${PYTHON_VERSION_NODOT}" >> $GITHUB_ENV
- name: Set MacOS Deployment Target
if: runner.os == 'macOS'
run: |
export MACOSX_DEPLOYMENT_TARGET="10.15"
echo "MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}" >> $GITHUB_ENV
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Install micromamba with build dependencies
uses: mamba-org/setup-micromamba@v1
# if: runner.os == 'macOS'
with:
python-version: ${{ matrix.python-version }}
init-shell: bash
environment-name: build-env
create-args: >-
python=${{ matrix.python-version }}
arpack=*=mpi_openmpi*
gfortran
openmpi=4
# - name: Set up Python ${{ matrix.python-version }}
# # if: matrix.host-os != 'macos-latest'
# if: runner.os != 'macOS'
# uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python-version }}

- name: Install MacOS dependencies
if: runner.os == 'macOS'
run: |
set -vxeuo pipefail
brew install tree
# python -m pip install delocate

- name: Install dependencies
run: |
set -vxeuo pipefail
bash ./scripts/install-deps.sh
tree .
ls -Al .
ls -Al ./dist/
tree .
# - name: Delocate wheels for MacOS
# if: runner.os == 'macOS'
# run: |
# set -vxeuo pipefail
# delocate-wheelpython -v ./dist/${{ env.REPOSITORY_NAME }}-*-cp${PYTHON_VERSION_NODOT}*.whl

- uses: actions/upload-artifact@v3
with:
name: ${{ env.REPOSITORY_NAME }}-wheels
path: dist/*.whl
path: dist/*

- name: Test with pytest
run: |
set -vxeuo pipefail
bash ./scripts/run-tests.sh
docs:
name: Documentation
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
python-version: [3.8]
fail-fast: false

steps:
- name: Set env.REPOSITORY_NAME # just the repo, as opposed to org/repo
run: |
export REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}
echo "REPOSITORY_NAME=${REPOSITORY_NAME}" >> $GITHUB_ENV
- name: Checkout the code
uses: actions/checkout@v4

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

- name: Install dependencies
run: |
set -vxeuo pipefail
bash ./scripts/install-deps.sh
- name: Build Docs
run: |
set -vxeuo pipefail
bash ./scripts/build-docs.sh
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ${{ env.REPOSITORY_NAME }}-docs
name: ${{ env.REPOSITORY_NAME }}-${{ matrix.python-version }}-${{ matrix.host-os }}-docs
path: docs/build/html/


publish-to-pypi:
# Hints from:
# - https://github.com/pypa/gh-action-pypi-publish/discussions/28
# - https://github.com/Lightning-AI/lightning/blob/master/.github/workflows/release-pypi.yml
if: github.event_name == 'release'
name: Publish to PyPI
needs: test
runs-on: ubuntu-latest
permissions:
id-token: write

steps:
- uses: actions/checkout@v3

- name: Download wheels from GitHub artifacts
uses: actions/download-artifact@v3
with:
name: wheels
path: dist/

- name: Publish wheels to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: ./dist/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@ target/

#Ipython Notebook
.ipynb_checkpoints

# cibuildwheel artifacts
wheelhouse/
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: check-toml
Expand All @@ -19,7 +19,7 @@ repos:
docs/
)
- repo: https://github.com/PyCQA/flake8.git
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
exclude: ^examples/
Expand Down
38 changes: 26 additions & 12 deletions scripts/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,43 @@

set -vxeuo pipefail

sudo apt-get update -y
sudo apt-get install -y \
gfortran \
openmpi-bin \
openmpi-doc \
libopenmpi-dev \
libopenblas-dev \
libarpack2-dev \
libparpack2-dev
platform="$(uname)"

if [ "${platform}" == "Linux" ]; then
# sudo apt-get update -y
# sudo apt-get install -y \
# gfortran \
# openmpi-bin \
# openmpi-doc \
# libopenmpi-dev \
# libopenblas-dev \
# libarpack2-dev \
# libparpack2-dev
echo "Skipping system packages installation in favor of conda packages for building."
elif [ "${platform}" == "Darwin" ]; then
echo "gfortran is expected to exist already."
fi

gfortran --version
which gfortran

# These packages are installed in the base environment but may be older
# versions. Explicitly upgrade them because they often create
# installation problems if out of date.
which python
python -VV

python -m pip install --upgrade pip setuptools wheel numpy

# # Generate .whl file.
python setup.py sdist bdist_wheel
ls -la dist/

# Install this package and the packages listed in requirements.txt.
pip install -v .
python -m pip install dist/edrixs-*-cp${PYTHON_VERSION_NODOT}*.whl

# Install extra requirements for running tests and building docs.
pip install -r requirements-dev.txt
python -m pip install -r requirements-dev.txt

# List the depencencies
pip list
python -m pip list
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# NOTE: This file must remain Python 2 compatible for the foreseeable future,
# to ensure that we error out properly for people with outdated setuptools
# and/or pip.
min_version = (3, 6)
min_version = (3, 8)
if sys.version_info < min_version:
error = """
edrixs does not support Python {0}.{1}.
Expand Down
17 changes: 14 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,22 @@ if (EDRIXS_PY_INTERFACE)
target_include_directories(${f2py_module_name} PUBLIC ${Python3_INCLUDE_DIRS} ${F2PY_INCLUDE_DIR} ${Python3_NumPy_INCLUDE_DIRS})
target_link_libraries(${f2py_module_name} PUBLIC edrixs)

set_target_properties(
${f2py_module_name}
if (LINUX)
set_target_properties(
${f2py_module_name}
PROPERTIES
PREFIX ""
OUTPUT_NAME ${generated_module_file}
LINKER_LANGUAGE C
)
elseif(APPLE)
set_target_properties(
${f2py_module_name}
PROPERTIES
PREFIX ""
OUTPUT_NAME ${generated_module_file}
LINKER_LANGUAGE C
)
LINK_FLAGS "-undefined dynamic_lookup"
)
endif()
endif()

0 comments on commit 36ec565

Please sign in to comment.