Skip to content

Commit

Permalink
Merge branch 'master' into cornu/use_fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu authored Aug 13, 2024
2 parents e2d7276 + 61dfd7c commit ed854d5
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
run: |
python3 -m venv music-venv
source music-venv/bin/activate
python3 -m pip install 'mpi4py<4' "cython<3" 'numpy<2' setuptools
python3 -m pip install 'mpi4py<4' "cython" 'numpy<2' setuptools
sudo mkdir -p $MUSIC_INSTALL_DIR
sudo chown -R $USER $MUSIC_INSTALL_DIR
curl -L -o MUSIC.zip https://github.com/INCF/MUSIC/archive/refs/tags/${MUSIC_VERSION}.zip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/neuron-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ jobs:
run: |
python3 -m venv music-venv
source music-venv/bin/activate
python3 -m pip install 'mpi4py<4' "cython<3" 'numpy<2' setuptools
python3 -m pip install 'mpi4py<4' "cython" 'numpy<2' setuptools
sudo mkdir -p $MUSIC_INSTALL_DIR
sudo chown -R $USER $MUSIC_INSTALL_DIR
curl -L -o MUSIC.zip https://github.com/INCF/MUSIC/archive/refs/tags/${MUSIC_VERSION}.zip
Expand Down
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,6 @@ if(NRN_ENABLE_RX3D)
message(SEND_ERROR "NRN_ENABLE_RX3D requires NRN_ENABLE_PYTHON feature.")
else()
find_package(Cython REQUIRED)
if(CYTHON_VERSION VERSION_GREATER_EQUAL 3)
message(FATAL_ERROR "Cython 3+ is not supported")
endif()
endif()
endif()
if(MINGW)
Expand Down Expand Up @@ -382,9 +379,6 @@ if(NRN_ENABLE_MUSIC)
message(FATAL "MUSIC requires -DNRN_ENABLE_PYTHON=ON")
endif()
find_package(Cython REQUIRED)
if(CYTHON_VERSION VERSION_GREATER_EQUAL 3)
message(FATAL_ERROR "Cython 3+ is not supported")
endif()
find_package(MUSIC REQUIRED)
set(NRN_MUSIC 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion ci/win_build_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export MSYSTEM_PREFIX=/mingw64
export PATH=/mingw64/bin:$PATH

# have compatible cython3
python3 -m pip install "cython<3"
python3 -m pip install "cython"

# if BUILD_SOURCESDIRECTORY not available, use te root of the repo
if [ -z "$BUILD_SOURCESDIRECTORY" ]; then
Expand Down
10 changes: 5 additions & 5 deletions ci/win_install_deps.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ pwsh -command "(Get-Content C:\Python310\Lib\distutils\cygwinccompiler.py) -repl
pwsh -command "(Get-Content C:\Python311\Lib\distutils\cygwinccompiler.py) -replace 'msvcr100', 'msvcrt' | Out-File C:\Python311\Lib\distutils\cygwinccompiler.py"

:: install numpy
C:\Python38\python.exe -m pip install numpy==1.17.5 "cython < 3" || goto :error
C:\Python39\python.exe -m pip install numpy==1.19.3 "cython < 3" || goto :error
C:\Python310\python.exe -m pip install numpy==1.21.3 "cython < 3" || goto :error
C:\Python311\python.exe -m pip install numpy==1.23.5 "cython < 3" || goto :error
C:\Python312\python.exe -m pip install numpy==1.26.3 "cython < 3" || goto :error
C:\Python38\python.exe -m pip install numpy==1.17.5 "cython" || goto :error
C:\Python39\python.exe -m pip install numpy==1.19.3 "cython" || goto :error
C:\Python310\python.exe -m pip install numpy==1.21.3 "cython" || goto :error
C:\Python311\python.exe -m pip install numpy==1.23.5 "cython" || goto :error
C:\Python312\python.exe -m pip install numpy==1.26.3 "cython" || goto :error
:: setuptools 70.2 leads to an error
C:\Python312\python.exe -m pip install setuptools==70.1.1 || goto :error

Expand Down
2 changes: 1 addition & 1 deletion docs/conda_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- cmake
- xorg-libxcomposite
- ffmpeg
- cython<3
- cython
- pandoc
- mpich
- pip
Expand Down
56 changes: 50 additions & 6 deletions docs/dev/setuptools/setuptools.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,64 @@ We use [setup.py](../../../setup.py) in two operational modes
:

1) **wheel building**
It boils down to
It boils down to

setup.py build_ext bdist_wheel

We configure the HOC extension along with a CMake configure, build all extensios and collect them for the wheel. This is called via [build_wheels.bash](../../../packaging/python/build_wheels.bash).

2) **CMake build**
It boils down to

setup.py build_ext build

We provide the cmake build folder, in this mode we do not run CMake configure, we build all extensions and make sure they are integrated into the CMake build and install. This is called via CMake in [src/nrnpython/CMakeLists.txt](../../../src/nrnpython/CMakeLists.txt) by passing **--cmake-build-dir** (the folder where we configured NEURON with CMake), along with other CMake options.
setup.py build_ext build

We provide the cmake build folder, in this mode we do not run CMake configure, we build all extensions and make sure they are integrated into the CMake build and install. This is called via CMake in [src/nrnpython/CMakeLists.txt](../../../src/nrnpython/CMakeLists.txt) by passing **--cmake-build-dir** (the folder where we configured NEURON with CMake), along with other CMake options.


## **Activity Diagram**

![](images/setup-py.png)
![](images/setup-py.png)


## 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:

```
--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.
```

A quick build for testing a change to a core component could therefore be:
```
python setup.py build --disable-rx3d --disable-iv --disable-mpi
```

---
**Mac Note**

Since the introduction of Mac with Apple silicon, with an Official Python distribution, extension are simultaneously built for arm64 and x86_64. Besides not required for a dev build, it may fail
on older SDKs with `Unsupported architecture` errors.

To skip that you may set the ARCHFLAGS environment var. Set it to "" (empty) for default architecture: `ARCHFLAGS='' python setup.py ...`

---

### Testing

Once built, the package may be imported and used normally. You might, however, need to set up
PYTHONPATH accordingly for the import to work:

```
export PYTHONPATH="<NRNDIR>/build/lib.macosx-10.9-x86_64-3.9/:$PYTHONPATH"
# Run Neuron base tests
python -c "import neuron; neuron.test()"
```
2 changes: 1 addition & 1 deletion docs/install/install_instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ In order to build NEURON from source, the following packages must be available:
The following packages are optional (see build options):

- Python >=3.8 (for Python interface)
- Cython < 3 (for RXD)
- Cython (for RXD)
- MPI (for parallel)
- X11 (Linux) or XQuartz (MacOS) (for GUI)

Expand Down
2 changes: 1 addition & 1 deletion nrn_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ matplotlib
# bokeh 3 seems to break docs notebooks
bokeh<3
ipython
cython<3
cython
packaging
pytest<=8.1.1 # potential bug from 8.2.0 due to parallelism?
pytest-cov
Expand Down
2 changes: 1 addition & 1 deletion packaging/python/build_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cython<3
cython
packaging
numpy==1.17.5;python_version=='3.8'
numpy==1.19.3;python_version=='3.9' and platform_machine!='arm64'
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def setup_package():
NRN_COLLECT_DIRS = ["bin", "lib", "include", "share"]

docs_require = [] # sphinx, themes, etc
maybe_rxd_reqs = ["numpy<2", "Cython<3"] if Components.RX3D else []
maybe_rxd_reqs = ["numpy<2", "Cython"] if Components.RX3D else []
maybe_docs = docs_require if "docs" in sys.argv else []
maybe_test_runner = ["pytest-runner"] if "test" in sys.argv else []

Expand All @@ -379,7 +379,6 @@ def setup_package():
list,
library_dirs=[os.path.join(cmake_build_dir, "lib")],
libraries=ext_common_libraries,
language="c++",
)

logging.info("Extension common compile flags %s" % str(extension_common_params))
Expand Down Expand Up @@ -436,6 +435,7 @@ def setup_package():
"neuronmusic",
["src/neuronmusic/neuronmusic.pyx"],
include_dirs=["src/nrnpython", "src/nrnmusic"],
language="c++",
**extension_common_params,
)
]
Expand Down
4 changes: 1 addition & 3 deletions share/lib/python/neuron/rxd/geometry3d/surfaces.pyx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import os
import numpy
import graphicsPrimitives
import neuron
import numpy
cimport numpy
import itertools
import bisect
cimport cython

from neuron.rxd.geometry3d import graphicsPrimitives

"""
The surfaces module
Expand Down

0 comments on commit ed854d5

Please sign in to comment.