diff --git a/.circleci/config.yml b/.circleci/config.yml index b7269b66ee..642bec51e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -32,7 +32,7 @@ jobs: -e SETUPTOOLS_SCM_PRETEND_VERSION \ -e NRN_BUILD_FOR_UPLOAD=1 \ 'docker.io/neuronsimulator/neuron_wheel:manylinux_2_28_aarch64' \ - packaging/python/build_wheels.bash linux 3<< parameters.NRN_PYTHON_VERSION_MINOR >> coreneuron + packaging/python/build_wheels.bash $(uname -s) 3<< parameters.NRN_PYTHON_VERSION_MINOR >> coreneuron - store_artifacts: path: ./wheelhouse diff --git a/.github/workflows/neuron-ci.yml b/.github/workflows/neuron-ci.yml index 1c0195a2af..5302f848a8 100644 --- a/.github/workflows/neuron-ci.yml +++ b/.github/workflows/neuron-ci.yml @@ -136,7 +136,7 @@ jobs: echo CMAKE_BUILD_PARALLEL_LEVEL=3 >> $GITHUB_ENV echo CTEST_PARALLEL_LEVEL=3 >> $GITHUB_ENV fi - echo CI_OS_NAME=osx >> $GITHUB_ENV + echo CI_OS_NAME=$(uname -s) >> $GITHUB_ENV shell: bash - name: Install apt packages @@ -152,7 +152,7 @@ jobs: # Core https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories echo CMAKE_BUILD_PARALLEL_LEVEL=4 >> $GITHUB_ENV echo CTEST_PARALLEL_LEVEL=4 >> $GITHUB_ENV - echo CI_OS_NAME=linux >> $GITHUB_ENV + echo CI_OS_NAME=$(uname -s) >> $GITHUB_ENV shell: bash - uses: actions/checkout@v4 @@ -430,8 +430,8 @@ jobs: BUILD_MODE: ${{ matrix.config.build_mode }} CCACHE_BASEDIR: ${{runner.workspace}}/nrn CCACHE_DIR: ${{runner.workspace}}/ccache - NRN_ENABLE_PYTHON_DYNAMIC : ${{ matrix.config.python_dynamic }} - NRN_ENABLE_MUSIC: ${{ matrix.config.music }} + NRN_ENABLE_PYTHON_DYNAMIC : ${{ matrix.config.python_dynamic || 'OFF' }} + NRN_ENABLE_MUSIC: ${{ matrix.config.music || 'OFF' }} PYTHON_MIN_NAME: "python${{ env.PY_MIN_VERSION }}" PYTHON_MAX_NAME: "python${{ env.PY_MAX_VERSION }}" INSTALL_DIR : ${{ runner.workspace }}/install diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a081844ac0..cd6148ed08 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -71,7 +71,7 @@ stages: -e SETUPTOOLS_SCM_PRETEND_VERSION \ -e NRN_BUILD_FOR_UPLOAD=1 \ 'docker.io/neuronsimulator/neuron_wheel:manylinux_2_28_x86_64' \ - packaging/python/build_wheels.bash linux $(python.version) coreneuron + packaging/python/build_wheels.bash $(uname -s) $(python.version) coreneuron displayName: 'Building ManyLinux Wheel' - script: | @@ -151,7 +151,7 @@ stages: export NRN_BUILD_FOR_UPLOAD=1 sudo mkdir -p /opt/nrnwheel/$(uname -m) sudo tar -zxf $(readlineSF.secureFilePath) --directory /opt/nrnwheel/$(uname -m) - packaging/python/build_wheels.bash osx $(python.version) coreneuron + packaging/python/build_wheels.bash $(uname -s) $(python.version) coreneuron displayName: 'Build MacOS Wheel' - template: ci/azure-wheel-test-upload.yml diff --git a/build_osx_wheels.sh b/build_osx_wheels.sh index 7633361710..f5f607e870 100755 --- a/build_osx_wheels.sh +++ b/build_osx_wheels.sh @@ -27,9 +27,9 @@ fi set -e -packaging/python/build_wheels.bash osx 3.9 coreneuron &>3.9-output -packaging/python/build_wheels.bash osx 3.10 coreneuron &>3.10-output -packaging/python/build_wheels.bash osx 3.11 coreneuron &>3.11-output +packaging/python/build_wheels.bash "$(uname -s)" 3.9 coreneuron &>3.9-output +packaging/python/build_wheels.bash "$(uname -s)" 3.10 coreneuron &>3.10-output +packaging/python/build_wheels.bash "$(uname -s)" 3.11 coreneuron &>3.11-output if [ -n $INTERACTIVE_OK ] then diff --git a/docs/dev/setuptools/setuptools.md b/docs/dev/setuptools/setuptools.md index ae449e4f7e..bd9af74e1b 100644 --- a/docs/dev/setuptools/setuptools.md +++ b/docs/dev/setuptools/setuptools.md @@ -37,22 +37,28 @@ We use [setup.py](../../../setup.py) in two operational modes ## Creating a Development Python Package `setup.py` can be lanched manually as well to create a dev build package, which can be tested -immediately. It supports several arguments to that the build can be tuned: +immediately. It supports several environmental variables through which the build can be tuned: ``` - --disable-rx3d Disables Rx3d. Implies CMake -DNRN_ENABLE_RX3D=OFF - --disable-iv Disables IV. Implies CMake -DNRN_ENABLE_INTERVIEWS=OFF - --disable-mpi Disables MPI. Implies -DNRN_ENABLE_MPI=OFF and disabling of neuronmusic - --enable-music Enables neuronmusic - --enable-coreneuron Enables experimental CorenNeuron support - --rx3d-opt-level Sets the rx3d optimization level. Default: 0 (-O0) - --cmake-build-dir Declares one wants to use a specic NEURON build (with CMake), instead - of creating one behind the scenes. Only builds extensions and package. + NRN_ENABLE_RX3D Enables RX3D. + NRN_ENABLE_INTERVIEWS Enables IV. + NRN_ENABLE_MPI Enables MPI. + NRN_ENABLE_MUSIC Enables neuronmusic + NRN_ENABLE_CORENEURON Enables experimental CorenNeuron support + NRN_RX3D_OPT_LEVEL Sets the RX3D optimization level. Default: 0 (-O0) +``` + +It also supports certain command-line arguments: + +``` + --cmake-build-dir Declares one wants to use a specic NEURON build (with CMake), instead + of creating one behind the scenes. Only builds extensions and package. ``` A quick build for testing a change to a core component could therefore be: + ``` -python setup.py build --disable-rx3d --disable-iv --disable-mpi +NRN_ENABLE_RX3D=OFF NRN_ENABLE_INTERVIEWS=OFF NRN_ENABLE_MPI=OFF python setup.py build ``` --- diff --git a/docs/install/python_wheels.md b/docs/install/python_wheels.md index 8456174bcd..c49024eec2 100644 --- a/docs/install/python_wheels.md +++ b/docs/install/python_wheels.md @@ -136,18 +136,18 @@ Wheels are generated under `/root/nrn/wheelhouse` and also accessible in the mou ``` # Working directory is /root/nrn -bash packaging/python/build_wheels.bash linux +bash packaging/python/build_wheels.bash Linux ls -la wheelhouse ``` You can build the wheel for a specific python version: ``` -bash packaging/python/build_wheels.bash linux 39 # 39 for Python v3.9 +bash packaging/python/build_wheels.bash Linux 39 # 39 for Python v3.9 ``` To build wheels with CoreNEURON support you have to pass an additional argument: `coreneuron`. ``` -bash packaging/python/build_wheels.bash linux 3* coreneuron +bash packaging/python/build_wheels.bash Linux 3* coreneuron ``` Where we are passing `3*` to build the wheels with `CoreNEURON` support for all python 3 versions. @@ -158,7 +158,7 @@ As mentioned above, for macOS all dependencies have to be available on a system. ``` cd nrn -bash packaging/python/build_wheels.bash osx +bash packaging/python/build_wheels.bash Darwin ``` In some cases, setuptools-scm will see extra commits and consider your build as "dirty," resulting in filenames such as `NEURON-9.0a1.dev0+g9a96a3a4d.d20230717-cp310-cp310-macosx_11_0_arm64.whl` (which should have been `NEURON-9.0a0-cp310-cp310-macosx_11_0_arm64.whl`). If this happens, you can set an environment variable to correct this behavior: diff --git a/packaging/python/build_wheels.bash b/packaging/python/build_wheels.bash index 5b4d2be04c..87b8f90cd4 100755 --- a/packaging/python/build_wheels.bash +++ b/packaging/python/build_wheels.bash @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -xe # A script to loop over the available pythons installed # on Linux/OSX and build wheels # @@ -16,14 +15,16 @@ set -xe # - C/C++ compiler # - ncurses -set -e +set -xeu if [ ! -f setup.py ]; then echo "Error: setup.py not found. Please launch $0 from the nrn root dir" exit 1 fi -py_ver="" +# various platform identifiers (as reported by `uname -s`) +PLATFORM_LINUX="Linux" +PLATFORM_MACOS="Darwin" # path to the (temp) requirements file containing all of the build dependencies # for NEURON and its submodules @@ -54,41 +55,39 @@ setup_venv() { } -build_wheel_linux() { - echo "[BUILD WHEEL] Building with interpreter $1" - local skip= - setup_venv "$1" - (( $skip )) && return 0 - - echo " - Installing build requirements" +configure_linux() { + echo " - Installing build requirements for Linux" pip install 'auditwheel<=6.2.0' - cp packaging/python/build_requirements.txt "${python_requirements_path}" - - CMAKE_DEFS="NRN_MPI_DYNAMIC=$3" - if [ "$USE_STATIC_READLINE" == "1" ]; then - CMAKE_DEFS="$CMAKE_DEFS,NRN_BINARY_DIST_BUILD=ON,NRN_WHEEL_STATIC_READLINE=ON" - fi - - if [ "$2" == "coreneuron" ]; then - setup_args="--enable-coreneuron" - nmodl_add_requirements - CMAKE_DEFS="${CMAKE_DEFS},NRN_LINK_AGAINST_PYTHON=OFF,CORENRN_ENABLE_OPENMP=ON" - fi + CMAKE_PREFIX_PATH="/nrnwheel/ncurses;/nrnwheel/readline" + export CMAKE_PREFIX_PATH +} - cat "${python_requirements_path}" - pip install -r "${python_requirements_path}" - pip check +configure_macos() { + echo " - Installing build requirements for MacOS" + pip install -U 'delocate<=0.13.0,>=0.13.0' - echo " - Building..." - rm -rf dist build + # We need to "fix" the platform tag if the Python installer is universal2 + # See: + # * https://github.com/pypa/setuptools/issues/2520 + # * https://github.com/neuronsimulator/nrn/pull/1562 + py_platform=$(python -c "import sysconfig; print('%s' % sysconfig.get_platform());") - # Workaround for https://github.com/pypa/manylinux/issues/1309 - git config --global --add safe.directory "*" + echo " - Python platform: ${py_platform}" + if [[ "${py_platform}" == *"-universal2" ]]; then + export _PYTHON_HOST_PLATFORM="${py_platform/universal2/$(uname -m)}" + echo " - Python installation is universal2 and we are on $(uname -m), setting _PYTHON_HOST_PLATFORM to: ${_PYTHON_HOST_PLATFORM}" + ARCHFLAGS="-arch $(uname -m)" + export ARCHFLAGS + echo " - Setting ARCHFLAGS to: ${ARCHFLAGS}" + fi - python setup.py build_ext --cmake-prefix="/nrnwheel/ncurses;/nrnwheel/readline" --cmake-defs="$CMAKE_DEFS" $setup_args bdist_wheel + CMAKE_PREFIX_PATH="/opt/nrnwheel/$(uname -m)/ncurses;/opt/nrnwheel/$(uname -m)/readline;/usr/x11" + export CMAKE_PREFIX_PATH +} +fix_wheel_linux() { # For CI runs we skip wheelhouse repairs - if [ "$SKIP_WHEELHOUSE_REPAIR" = true ] ; then + if [ "${SKIP_WHEELHOUSE_REPAIR:-}" = true ] ; then echo " - Skipping wheelhouse repair ..." mkdir wheelhouse && cp dist/*.whl wheelhouse/ else @@ -105,18 +104,31 @@ build_wheel_linux() { # ships an extra copy of libnrniv.so and hence exclude it here. auditwheel -v repair dist/*.whl --exclude "libgomp.so.1" --exclude "libnrniv.so" fi +} - deactivate +fix_wheel_macos() { + echo " - Calling delocate-listdeps" + delocate-listdeps dist/*.whl + + echo " - Repairing..." + # we started clean, there's a single wheel + delocate-wheel -w wheelhouse -v dist/*.whl } -build_wheel_osx() { - echo "[BUILD WHEEL] Building with interpreter $1" +build_wheel() { + platform="$(uname -s)" + echo "[BUILD WHEEL] Building with interpreter $1 on ${platform}" local skip= setup_venv "$1" - (( $skip )) && return 0 + (( skip )) && return 0 + + if [[ "${platform}" == "${PLATFORM_LINUX}" ]]; then + configure_linux + elif [[ "${platform}" == "${PLATFORM_MACOS}" ]]; then + configure_macos + fi - echo " - Installing build requirements" cp packaging/python/build_requirements.txt "${python_requirements_path}" CMAKE_DEFS="NRN_MPI_DYNAMIC=$3" @@ -125,71 +137,42 @@ build_wheel_osx() { fi if [ "$2" == "coreneuron" ]; then - setup_args="--enable-coreneuron" + NRN_ENABLE_CORENEURON=ON nmodl_add_requirements CMAKE_DEFS="${CMAKE_DEFS},NRN_LINK_AGAINST_PYTHON=OFF" + if [[ "${platform}" == "${PLATFORM_LINUX}" ]]; then + CMAKE_DEFS="${CMAKE_DEFS},CORENRN_ENABLE_OPENMP=ON" + fi + else + NRN_ENABLE_CORENEURON=OFF fi + export NRN_ENABLE_CORENEURON cat "${python_requirements_path}" - pip install -U 'delocate<=0.13.0' -r "${python_requirements_path}" + pip install -r "${python_requirements_path}" pip check echo " - Building..." rm -rf dist build - # We need to "fix" the platform tag if the Python installer is universal2 - # See: - # * https://github.com/pypa/setuptools/issues/2520 - # * https://github.com/neuronsimulator/nrn/pull/1562 - py_platform=$(python -c "import sysconfig; print('%s' % sysconfig.get_platform());") - - echo " - Python platform: ${py_platform}" - if [[ "${py_platform}" == *"-universal2" ]]; then - if [[ `uname -m` == 'arm64' ]]; then - export _PYTHON_HOST_PLATFORM="${py_platform/universal2/arm64}" - echo " - Python installation is universal2 and we are on arm64, setting _PYTHON_HOST_PLATFORM to: ${_PYTHON_HOST_PLATFORM}" - export ARCHFLAGS="-arch arm64" - echo " - Setting ARCHFLAGS to: ${ARCHFLAGS}" - # This is a shortcut to have a successful delocate-wheel. See: - # https://github.com/matthew-brett/delocate/issues/153 - python -c "import os,delocate; print(os.path.join(os.path.dirname(delocate.__file__), 'tools.py'));quit()" | xargs -I{} sed -i."" "s/first, /input.pop('i386',None); first, /g" {} - else - export _PYTHON_HOST_PLATFORM="${py_platform/universal2/x86_64}" - echo " - Python installation is universal2 and we are on x84_64, setting _PYTHON_HOST_PLATFORM to: ${_PYTHON_HOST_PLATFORM}" - export ARCHFLAGS="-arch x86_64" - echo " - Setting ARCHFLAGS to: ${ARCHFLAGS}" - fi - fi - - python setup.py build_ext --cmake-prefix="/opt/nrnwheel/$(uname -m)/ncurses;/opt/nrnwheel/$(uname -m)/readline;/usr/x11" --cmake-defs="$CMAKE_DEFS" $setup_args bdist_wheel + # Workaround for https://github.com/pypa/manylinux/issues/1309 + git config --global --add safe.directory "*" - echo " - Calling delocate-listdeps" - delocate-listdeps dist/*.whl + python setup.py build_ext --cmake-defs="$CMAKE_DEFS" bdist_wheel - echo " - Repairing..." - delocate-wheel -w wheelhouse -v dist/*.whl # we started clean, there's a single wheel + if [[ "${platform}" == "${PLATFORM_LINUX}" ]]; then + fix_wheel_linux + elif [[ "${platform}" == "${PLATFORM_MACOS}" ]]; then + fix_wheel_macos + fi deactivate } -# platform for which wheel to be build -platform=$1 - -# python version for which wheel to be built; 3* (default) means all python 3 versions -python_wheel_version= -if [ ! -z "$2" ]; then - python_wheel_version=$2 -fi - -# enable coreneuron support: "coreneuron" -# this should be removed/improved once wheel is stable -coreneuron=$3 - -# MAIN -case "$1" in - - linux) +set_mpi_headers_linux() { + # first two are for AlmaLinux 8 (default for manylinux_2_28); + # second two are for Debian/Ubuntu derivatives MPI_POSSIBLE_INCLUDE_HEADERS="/usr/include/openmpi-$(uname -m) /usr/include/mpich-$(uname -m) /usr/lib/$(uname -m)-linux-gnu/openmpi/include /usr/include/$(uname -m)-linux-gnu/mpich" MPI_INCLUDE_HEADERS="" for dir in $MPI_POSSIBLE_INCLUDE_HEADERS @@ -204,45 +187,77 @@ case "$1" in if [ -d "$MPT_INCLUDE_PATH" ]; then MPI_INCLUDE_HEADERS="${MPI_INCLUDE_HEADERS};${MPT_INCLUDE_PATH}" fi + + export MPI_INCLUDE_HEADERS +} + +set_mpi_headers_macos() { + BREW_PREFIX="$(brew --prefix)" + MPI_POSSIBLE_INCLUDE_HEADERS="${BREW_PREFIX}/opt/openmpi/include ${BREW_PREFIX}/opt/mpich/include" + MPI_INCLUDE_HEADERS="" + for dir in $MPI_POSSIBLE_INCLUDE_HEADERS + do + if [ -d "${dir}" ]; then + MPI_INCLUDE_HEADERS="${MPI_INCLUDE_HEADERS};${dir}" + fi + done + export MPI_INCLUDE_HEADERS +} + + +# platform for which to build the wheel (default: host machine platform) +# supported values: Linux, Darwin, CI +platform= +if [ $# -ge 1 ]; then + platform=$1 +fi + +# python version for which wheel to be built; 3* (default) means all python 3 versions +python_wheel_version= +if [ $# -ge 2 ]; then + python_wheel_version=$2 +fi + +# enable coreneuron support: "coreneuron" enables support (default: without coreneuron) +# this should be removed/improved once wheel is stable +coreneuron="${3:-}" + +# MAIN + +case "${platform}" in + + Linux) + set_mpi_headers_linux USE_STATIC_READLINE=1 python_wheel_version=${python_wheel_version//[-._]/} for py_bin in /opt/python/cp${python_wheel_version}*/bin/python; do - build_wheel_linux "$py_bin" "$coreneuron" "$MPI_INCLUDE_HEADERS" + build_wheel "$py_bin" "$coreneuron" "$MPI_INCLUDE_HEADERS" done ;; - osx) - BREW_PREFIX=$(brew --prefix) - MPI_INCLUDE_HEADERS="${BREW_PREFIX}/opt/openmpi/include;${BREW_PREFIX}/opt/mpich/include" + Darwin) + set_mpi_headers_macos USE_STATIC_READLINE=1 for py_bin in /Library/Frameworks/Python.framework/Versions/${python_wheel_version}*/bin/python3; do - build_wheel_osx "$py_bin" "$coreneuron" "$MPI_INCLUDE_HEADERS" + build_wheel "$py_bin" "$coreneuron" "$MPI_INCLUDE_HEADERS" done ;; CI) - if [ "$CI_OS_NAME" == "osx" ]; then - BREW_PREFIX=$(brew --prefix) - MPI_INCLUDE_HEADERS="${BREW_PREFIX}/opt/openmpi/include;${BREW_PREFIX}/opt/mpich/include" - build_wheel_osx $(which python3) "$coreneuron" "$MPI_INCLUDE_HEADERS" - else - # first two are for AlmaLinux 8 (default for manylinux_2_28); - # second two are for Debian/Ubuntu derivatives - MPI_POSSIBLE_INCLUDE_HEADERS="/usr/include/openmpi-$(uname -m) /usr/include/mpich-$(uname -m) /usr/lib/$(uname -m)-linux-gnu/openmpi/include /usr/include/$(uname -m)-linux-gnu/mpich" - MPI_INCLUDE_HEADERS="" - for dir in $MPI_POSSIBLE_INCLUDE_HEADERS - do - if [ -d "${dir}" ]; then - MPI_INCLUDE_HEADERS="${MPI_INCLUDE_HEADERS};${dir}" - fi - done - build_wheel_linux $(which python3) "$coreneuron" "$MPI_INCLUDE_HEADERS" + if [ "$CI_OS_NAME" == "${PLATFORM_MACOS}" ]; then + set_mpi_headers_macos + USE_STATIC_READLINE=0 + build_wheel "$(which python3)" "$coreneuron" "$MPI_INCLUDE_HEADERS" + elif [ "$CI_OS_NAME" == "${PLATFORM_LINUX}" ]; then + set_mpi_headers_linux + USE_STATIC_READLINE=0 + build_wheel "$(which python3)" "$coreneuron" "$MPI_INCLUDE_HEADERS" fi ls wheelhouse/ ;; *) - echo "Usage: $(basename $0) < linux | osx > [python version 36|37|38|39|3*] [coreneuron]" + echo "Usage: $(basename "$0") < ${PLATFORM_LINUX} | ${PLATFORM_MACOS} > [python version 36|37|38|39|3*] [coreneuron]" exit 1 ;; diff --git a/packaging/python/test_wheels.sh b/packaging/python/test_wheels.sh index 9e8dffd95b..8d20a5e35d 100755 --- a/packaging/python/test_wheels.sh +++ b/packaging/python/test_wheels.sh @@ -181,7 +181,7 @@ run_parallel_test() { run_mpi_test "${BREW_PREFIX}/opt/open-mpi/bin/mpirun" "OpenMPI" "" # CI Linux or Azure Linux or circleCI build (all on Debian/Ubuntu) - elif [[ "$CI_OS_NAME" == "linux" || "$AGENT_OS" == "Linux" || "$CIRCLECI" == "true" ]]; then + elif [[ "$CI_OS_NAME" == "Linux" || "$AGENT_OS" == "Linux" || "$CIRCLECI" == "true" ]]; then # make debugging easier sudo update-alternatives --get-selections | grep mpi sudo update-alternatives --list mpi-${ARCH_DIR}-linux-gnu diff --git a/setup.py b/setup.py index d83b9974a2..150d5b2199 100644 --- a/setup.py +++ b/setup.py @@ -14,16 +14,34 @@ logging.basicConfig(level=logging.INFO) - logging.info("setup.py called with:" + " ".join(sys.argv)) +def strtobool(val: str) -> bool: + """ + Convert a string representation of truth to True or False. + + True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values + are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if + 'val' is anything else. + """ + val = val.lower() + if val in ("y", "yes", "t", "true", "on", "1"): + return True + if val in ("n", "no", "f", "false", "off", "0"): + return False + + raise ValueError(f"invalid truth value {val}") + + class Components: - RX3D = True - IV = True - MPI = True - MUSIC = False # still early support - CORENRN = False # still early support + RX3D = strtobool(os.getenv("NRN_ENABLE_RX3D", "ON")) + IV = strtobool(os.getenv("NRN_ENABLE_INTERVIEWS", "ON")) + MPI = strtobool(os.getenv("NRN_ENABLE_MPI", "ON")) + MUSIC = strtobool(os.getenv("NRN_ENABLE_MUSIC", "OFF")) # still early support + CORENRN = strtobool( + os.getenv("NRN_ENABLE_CORENEURON", "OFF") + ) # still early support # Check if we've got --cmake-build-dir path that will be used to build extensions only @@ -65,41 +83,14 @@ class Components: just_extensions = True # Check for RX3D Optimization Level -rx3d_opt_level = "-O0" -if "--rx3d-opt-level" in sys.argv: - rx3d_opt_level_arg = sys.argv[sys.argv.index("--rx3d-opt-level") + 1] - rx3d_opt_level = "-O{}".format(int(rx3d_opt_level_arg)) - sys.argv.remove("--rx3d-opt-level") - sys.argv.remove(rx3d_opt_level_arg) +rx3d_opt_level = os.getenv("NRN_RX3D_OPT_LEVEL", "0") # If NRN_ENABLE_PYTHON_DYNAMIC is ON, we will build the wheel without the nrnpython library -without_nrnpython = False -if "--without-nrnpython" in sys.argv: - without_nrnpython = True - sys.argv.remove("--without-nrnpython") +without_nrnpython = strtobool( + os.getenv("NRN_ENABLE_MODULE_INSTALL", "OFF") +) and not strtobool(os.getenv("NRN_ENABLE_PYTHON_DYNAMIC", "OFF")) # setup options must be checked for very early as it impacts imports -if "--disable-rx3d" in sys.argv: - Components.RX3D = False - sys.argv.remove("--disable-rx3d") - -if "--disable-iv" in sys.argv: - Components.IV = False - sys.argv.remove("--disable-iv") - -if "--disable-mpi" in sys.argv: - Components.MPI = False - Components.MUSIC = False - sys.argv.remove("--disable-mpi") - -if "--enable-coreneuron" in sys.argv: - Components.CORENRN = True - sys.argv.remove("--enable-coreneuron") - -if "--enable-music" in sys.argv: - Components.MUSIC = True - sys.argv.remove("--enable-music") - if Components.RX3D: try: from Cython.Distutils import Extension as CyExtension @@ -162,14 +153,13 @@ class CMakeAugmentedBuilder(build_ext): """Builder which understands CMakeAugmentedExtension""" user_options = build_ext.user_options + [ - ("cmake-prefix=", None, "value for CMAKE_PREFIX_PATH"), ("cmake-defs=", None, "Additional CMake definitions, comma split"), ] boolean_options = build_ext.boolean_options + ["docs"] def initialize_options(self): build_ext.initialize_options(self) - self.cmake_prefix = None + self.cmake_prefix = os.getenv("CMAKE_PREFIX_PATH", "") self.cmake_defs = None self.docs = False @@ -401,7 +391,7 @@ def setup_package(): libraries=ext_common_libraries, ) - logging.info("Extension common compile flags %s" % str(extension_common_params)) + logging.info("Extension common compile flags %s", extension_common_params) # Get extra_compile_args and extra_link_args from environment variable extra_link_args = os.environ.get("LDFLAGS", "").split() @@ -474,7 +464,11 @@ def setup_package(): # Cython files take a long time to compile with O2 but this # is a distribution... extra_compile_args=extra_compile_args - + ["-O2" if "NRN_BUILD_FOR_UPLOAD" in os.environ else rx3d_opt_level], + + [ + "-O2" + if "NRN_BUILD_FOR_UPLOAD" in os.environ + else f"-O{rx3d_opt_level}" + ], extra_link_args=extra_link_args + ["-Wl,-rpath,{}".format(REL_RPATH + "/../../.data/lib/")], ) @@ -482,7 +476,7 @@ def setup_package(): if platform.system() == "Darwin": rxd_params["extra_link_args"] += ["-headerpad_max_install_names"] - logging.info("RX3D compile flags %s" % str(rxd_params)) + logging.info("RX3D compile flags %s", rxd_params) rxd_extensions = [ CyExtension( diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index f0a04d49c9..9220c1f66d 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -171,21 +171,23 @@ if(NRN_ENABLE_MODULE_INSTALL) # Prepare build options for setup.py build set(NRN_SETUP_PY_BUILD_OPTIONS "--cmake-build-dir") list(APPEND NRN_SETUP_PY_BUILD_OPTIONS ${CMAKE_BINARY_DIR}) - if(NOT NRN_ENABLE_RX3D) - list(APPEND NRN_SETUP_PY_BUILD_OPTIONS "--disable-rx3d") - else() - list(APPEND NRN_SETUP_PY_BUILD_OPTIONS "--rx3d-opt-level" ${NRN_RX3D_OPT_LEVEL}) - endif() if(MINGW) list(APPEND NRN_SETUP_PY_BUILD_OPTIONS "--compiler=mingw32") endif() - if(NOT NRN_ENABLE_PYTHON_DYNAMIC) - list(APPEND NRN_SETUP_PY_BUILD_OPTIONS "--without-nrnpython") - endif() - if(NRN_ENABLE_MUSIC) - list(APPEND NRN_SETUP_PY_BUILD_OPTIONS "--enable-music") - endif() list(APPEND NRN_SETUP_PY_BUILD_OPTIONS "--build-lib=${NRN_PYTHON_BUILD_LIB}") + set(setup_py_env_vars + NRN_ENABLE_PYTHON_DYNAMIC + NRN_ENABLE_MODULE_INSTALL + NRN_RX3D_OPT_LEVEL + NRN_ENABLE_RX3D + NRN_ENABLE_INTERVIEWS + NRN_ENABLE_MPI + NRN_ENABLE_MUSIC + NRN_ENABLE_CORENEURON) + + foreach(var IN LISTS setup_py_env_vars) + list(APPEND extra_env "${var}=${${var}}") + endforeach() # Prepare build_ext options for setup.py build set(NRN_SETUP_PY_BUILD_EXT_OPTIONS "build_ext")