forked from dmritrekker/trekker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dmritrekker#15 from tfmoraes/cython_compile
compile just using cython and add github-ci
- Loading branch information
Showing
8 changed files
with
222 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
name: Build | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build_wheels: | ||
name: Build wheel for cp${{ matrix.python }}-${{ matrix.platform_id }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
# Windows 64-bit | ||
- os: windows-latest | ||
python: 38 | ||
platform_id: win_amd64 | ||
- os: windows-latest | ||
python: 39 | ||
platform_id: win_amd64 | ||
- os: windows-latest | ||
python: 310 | ||
platform_id: win_amd64 | ||
- os: windows-latest | ||
python: 311 | ||
platform_id: win_amd64 | ||
|
||
# Linux 64-bit | ||
- os: ubuntu-latest | ||
python: 38 | ||
platform_id: manylinux_x86_64 | ||
- os: ubuntu-latest | ||
python: 39 | ||
platform_id: manylinux_x86_64 | ||
- os: ubuntu-latest | ||
python: 310 | ||
platform_id: manylinux_x86_64 | ||
- os: ubuntu-latest | ||
python: 311 | ||
platform_id: manylinux_x86_64 | ||
|
||
# macOS on Intel 64-bit | ||
- os: macos-latest | ||
python: 38 | ||
arch: x86_64 | ||
platform_id: macosx_x86_64 | ||
- os: macos-latest | ||
python: 39 | ||
arch: x86_64 | ||
platform_id: macosx_x86_64 | ||
- os: macos-latest | ||
python: 310 | ||
arch: x86_64 | ||
platform_id: macosx_x86_64 | ||
- os: macos-latest | ||
python: 311 | ||
arch: x86_64 | ||
platform_id: macosx_x86_64 | ||
|
||
# macOS on Apple M1 64-bit | ||
- os: macos-latest | ||
python: 38 | ||
arch: arm64 | ||
platform_id: macosx_arm64 | ||
- os: macos-latest | ||
python: 39 | ||
arch: arm64 | ||
platform_id: macosx_arm64 | ||
- os: macos-latest | ||
python: 310 | ||
arch: arm64 | ||
platform_id: macosx_arm64 | ||
- os: macos-latest | ||
python: 311 | ||
arch: arm64 | ||
platform_id: macosx_arm64 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
|
||
- uses: actions/setup-python@v4 | ||
name: Install Python host for cibuildwheel | ||
with: | ||
python-version: '3.9' | ||
|
||
# Visual Studio | ||
- name: Set up MSVC x64 | ||
if: matrix.platform_id == 'win_amd64' | ||
uses: ilammy/msvc-dev-cmd@v1 | ||
|
||
- name: Installing Nasm win_amd64 | ||
if: matrix.platform_id == 'win_amd64' | ||
run: | | ||
choco install --no-progress -y nasm | ||
- name: Installing Nasm win32 | ||
if: matrix.platform_id == 'win32' | ||
run: | | ||
choco install --no-progress -y --x86 nasm | ||
- name: Set Path win32 | ||
if: matrix.platform_id == 'win32' | ||
shell: bash | ||
run: | | ||
echo "C:\Program Files (x86)\NASM" >> $GITHUB_PATH | ||
- name: Set Path win_amd64 | ||
if: matrix.platform_id == 'win_amd64' | ||
shell: bash | ||
run: | | ||
echo "C:\Program Files\NASM" >> $GITHUB_PATH | ||
- name: Install cibuildwheel | ||
run: python -m pip install cibuildwheel==2.11.4 | ||
|
||
- name: Build wheels | ||
# to supply options, put them in 'env', like: | ||
env: | ||
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014 | ||
CIBW_MANYLINUX_I686_IMAGE: manylinux2014 | ||
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014 | ||
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }} | ||
CIBW_ARCHS_LINUX: auto aarch64 | ||
|
||
CIBW_ARCHS_MACOS: ${{ matrix.arch }} | ||
CIBW_ENVIRONMENT_MACOS: > | ||
CMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} | ||
CIBW_TEST_COMMAND: python -c "import Trekker" | ||
|
||
# Include latest Python beta | ||
CIBW_PRERELEASE_PYTHONS: True | ||
|
||
CIBW_BEFORE_BUILD: pip install cython wheel | ||
|
||
run: python -m cibuildwheel --output-dir wheelhouse src/python/ | ||
|
||
- uses: actions/upload-artifact@v2 | ||
with: | ||
path: ./wheelhouse/*.whl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,89 @@ | ||
from setuptools import setup | ||
from setuptools.extension import Extension | ||
import glob | ||
import os | ||
import platform | ||
import shutil | ||
from pathlib import Path | ||
|
||
from Cython.Build import cythonize | ||
from Cython.Distutils import build_ext | ||
from setuptools import setup | ||
from setuptools.extension import Extension | ||
|
||
from pathlib import Path | ||
import shutil | ||
import os | ||
import platform | ||
import glob | ||
|
||
class TrekkerBuildExt(build_ext): | ||
def run(self): | ||
build_ext.run(self) | ||
target_dir = Path(self.build_lib) | ||
os.makedirs(str(target_dir / 'Trekker')) | ||
for file in glob.glob(str(Path('cython/*'))): | ||
shutil.copy(file, str(target_dir / 'Trekker')) | ||
shutil.copyfile(str(Path('build/cython') / 'Trekker.cpp'), str(target_dir / 'Trekker/Trekker.cpp')) | ||
os.makedirs(str(target_dir / "Trekker")) | ||
for file in glob.glob(str(Path("cython/*"))): | ||
shutil.copy(file, str(target_dir / "Trekker")) | ||
shutil.copyfile( | ||
str(Path("build/cython") / "Trekker.cpp"), | ||
str(target_dir / "Trekker/Trekker.cpp"), | ||
) | ||
|
||
|
||
LIB_DIRS = ["cython/"] | ||
INC_DIRS = [ | ||
"cython/", | ||
"../", | ||
"../nifticlib-2.0.0/znzlib", | ||
"../nifticlib-2.0.0/niftilib", | ||
"../base", | ||
"../math", | ||
"../image", | ||
"../config", | ||
"../tracker", | ||
] | ||
|
||
LIB_DIRS = ['cython/'] | ||
INC_DIRS = ['cython/'] | ||
cpp_sources = [str(i) for i in (Path("../").glob("**/*.cpp"))] | ||
c_sources = [str(i) for i in (Path("../").glob("**/*.c"))] | ||
sources = cpp_sources + c_sources | ||
sources = [ | ||
source | ||
for source in sources | ||
if not source.endswith("cmd.cpp") and not source.lower().endswith("trekker.cpp") | ||
] | ||
sources = sources + ["cython/Trekker.pxd", "cython/Trekker.pyx", "../trekker.cpp"] | ||
|
||
if (platform.system()=="Linux"): | ||
LIBS = ["Trekker","z","pthread"] | ||
if (platform.system()=="Windows"): | ||
LIBS = ["Trekker"] | ||
print(f"\n\n\n{sources=}\n\n\n") | ||
|
||
if platform.system() == "Windows": | ||
LIBS = [] | ||
EXTRA_COMPILE_ARGS = ["/DBUILD_FOR_WINDOWS"] | ||
elif platform.system() == "Darwin": | ||
LIBS = ["z"] | ||
EXTRA_COMPILE_ARGS = ["-std=c++11","-D BUILD_FOR_MACOS", "-D HAVE_ZLIB"] | ||
else: | ||
LIBS = ["z"] | ||
EXTRA_COMPILE_ARGS = ["-std=c++11", "-D HAVE_ZLIB"] | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setup( | ||
name='Trekker', | ||
description='Python package for parallel transport tractography (PTT)', | ||
name="Trekker", | ||
description="Python package for parallel transport tractography (PTT)", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
version='0.9', | ||
setup_requires=[ | ||
'setuptools>=18.0', | ||
'cython>=0.28.4', | ||
], | ||
version="0.9", | ||
setup_requires=["setuptools>=18.0", "cython>=0.28.4", "wheel"], | ||
ext_modules=cythonize( | ||
[ | ||
Extension( | ||
'Trekker', | ||
sources=['cython/Trekker.pxd','cython/Trekker.pyx'], | ||
[ | ||
Extension( | ||
"Trekker", | ||
sources=sources, | ||
libraries=LIBS, | ||
library_dirs=LIB_DIRS, | ||
include_dirs=INC_DIRS, | ||
language="c++",) | ||
], | ||
language_level=3, | ||
build_dir="build", | ||
compiler_directives=dict(always_allow_keywords=True), | ||
), | ||
language="c++", | ||
extra_compile_args=EXTRA_COMPILE_ARGS, | ||
) | ||
], | ||
language_level=3, | ||
build_dir="build", | ||
compiler_directives=dict(always_allow_keywords=True), | ||
), | ||
cmdclass=dict(build_ext=TrekkerBuildExt), | ||
author="Dogu Baran Aydogan", | ||
author_email="[email protected]", | ||
|
@@ -64,7 +93,7 @@ def run(self): | |
"License :: OSI Approved :: BSD License", | ||
"Operating System :: OS Independent", | ||
], | ||
python_requires='>=3.6', | ||
license='BSD 2-Clause License', | ||
platforms=['linux','win'], | ||
python_requires=">=3.6", | ||
license="BSD 2-Clause License", | ||
platforms=["linux", "win"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters