Skip to content

Commit a2ea6ca

Browse files
committed
Trying with setup.py!
1 parent 35adc01 commit a2ea6ca

13 files changed

Lines changed: 161 additions & 156 deletions

.appveyor.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ version: devel-{build}
22

33
os: Visual Studio 2015
44

5-
test: off
6-
75
platform:
86
- x64
97
- x86
108

119
environment:
1210
matrix:
11+
- PYTHON: 27
12+
- PYTHON: 36
1313
- CONDA: 27
1414
- CONDA: 35
1515

@@ -21,13 +21,15 @@ install:
2121
if ($env:PYTHON) {
2222
if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" }
2323
$env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH"
24-
pip install --disable-pip-version-check --user --upgrade pip wheel
25-
pip install pytest numpy scipy
24+
pip install --disable-pip-version-check --user --upgrade pip setuptools
2625
} elseif ($env:CONDA) {
2726
if ($env:CONDA -eq "27") { $env:CONDA = "" }
2827
if ($env:PLATFORM -eq "x64") { $env:CONDA = "$env:CONDA-x64" }
2928
$env:PATH = "C:\Miniconda$env:CONDA\;C:\Miniconda$env:CONDA\Scripts\;$env:PATH"
30-
conda install -y -q pytest numpy scipy
29+
conda config --set always_yes yes --set changeps1 no
30+
conda config --add channels conda-forge
31+
conda update -q conda
32+
conda install -q conda-build
3133
}
3234
- if "%platform%" == "x64" SET VS_FULL=Visual Studio 14 2015 Win64
3335
- if "%platform%" == "x86" SET VS_FULL=Visual Studio 14 2015
@@ -36,16 +38,25 @@ install:
3638
- cd core-moos
3739
- mkdir build
3840
- cd build
39-
- cmake -G "%VS_FULL%" -DENABLE_EXPORT=ON -DUSE_ASYNC_COMMS=ON -DTIME_WARP_AGGLOMERATION=0.4 -DCMAKE_BUILD_TYPE=Release ../
41+
- cmake -G "%VS_FULL%" -DENABLE_EXPORT=ON -DUSE_ASYNC_COMMS=ON -DCMAKE_BUILD_TYPE=Release ../
4042
- cmake --build . --config Release
4143
- cmake --build . --config Release --target install
4244

4345
build_script:
4446
- cd %APPVEYOR_BUILD_FOLDER%
45-
- mkdir build
46-
- cd build
47-
- cmake -G "%VS_FULL%"
48-
- cmake --build . --config Release
47+
- ps: |
48+
if ($env:PYTHON) {
49+
python setup.py sdist
50+
pip install --verbose dist\pymoos-0.0.1.tar.gz
51+
} else {
52+
conda build conda.recipe
53+
conda install --use-local pymoos
54+
}
4955
50-
on_success:
51-
- cmake --build . --config Release --target install
56+
test_script:
57+
- ps: |
58+
cd tests
59+
python run_close.py
60+
python simple_comms.py
61+
python register.py
62+
python callbacks.py

.travis.yml

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
language: cpp
2-
3-
sudo: required
4-
5-
os:
6-
- linux
7-
- osx
8-
9-
compiler:
10-
- gcc
11-
12-
env:
13-
- PYTHON_VERSION=2.7
14-
- PYTHON_VERSION=3.2
15-
2+
matrix:
3+
include:
4+
- os: linux
5+
env: PYTHON=2.7
6+
- os: linux
7+
env: PYTHON=3.5
8+
- os: linux
9+
env: CONDA=2.7
10+
- os: linux
11+
env: CONDA=3.5
12+
- os: osx
13+
env: PYTHON=2.7
14+
- os: osx
15+
env: PYTHON=3.6
16+
- os: osx
17+
env: CONDA=2.7
18+
- os: osx
19+
env: CONDA=3.5
1620
addons:
17-
apt:
18-
sources:
19-
- ubuntu-toolchain-r-test
20-
- kubuntu-backports
21-
packages:
22-
- g++-4.8
23-
- cmake
21+
apt:
22+
sources:
23+
- ubuntu-toolchain-r-test
24+
- deadsnakes
25+
- kubuntu-backports
26+
packages:
27+
- g++-4.8
28+
- python3.5
29+
- python3.5-dev
30+
- cmake
2431

2532
before_install:
2633
- if [ "`uname`" != "Darwin" ] ; then export MOOS_CXX_FLAGS="-fPIC -Wno-long-long"; fi
@@ -30,21 +37,45 @@ before_install:
3037
- cd core-moos
3138
- mkdir build
3239
- cd build
33-
- cmake -DENABLE_EXPORT=ON -DUSE_ASYNC_COMMS=ON -DTIME_WARP_AGGLOMERATION=0.4 -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_FLAGS=$MOOS_CXX_FLAGS ..
40+
- cmake -DENABLE_EXPORT=ON -DUSE_ASYNC_COMMS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=$MOOS_CXX_FLAGS ..
3441
- cmake --build . --config Release --config -j4
3542
- sudo cmake --build . --config Release --target install
3643
- cd $TRAVIS_BUILD_DIR
37-
- mkdir build/
44+
- |
45+
if [ "$TRAVIS_OS_NAME" = "linux" ]; then export CXX=g++-4.8 CC=gcc-4.8; fi
46+
if [ -n "$PYTHON" ]; then
47+
if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "${PYTHON:0:1}" = "3" ]; then
48+
brew update; brew install python3;
49+
fi
50+
pip install --user --upgrade pip virtualenv
51+
virtualenv -p python$PYTHON venv
52+
source venv/bin/activate
53+
elif [ -n "$CONDA" ]; then
54+
if [ "$TRAVIS_OS_NAME" = "linux" ]; then OS=Linux-x86_64; else OS=MacOSX-x86_64; fi
55+
wget -O miniconda.sh https://repo.continuum.io/miniconda/Miniconda${CONDA:0:1}-latest-$OS.sh
56+
bash miniconda.sh -b -p $HOME/miniconda
57+
export PATH="$HOME/miniconda/bin:$PATH"
58+
conda config --set always_yes yes --set changeps1 no
59+
conda config --add channels conda-forge
60+
conda update -q conda
61+
conda install -q conda-build
62+
conda create -q -n test-environment python=$CONDA
63+
source activate test-environment
64+
fi
3865
3966
install:
40-
- cd build/
41-
- cmake .. -DPYBIND11_PYTHON_VERSION=$PYTHON_VERSION
42-
- cmake --build .
43-
44-
before_script:
45-
- mkdir pymoos && cp pymoos.so pymoos/
46-
- cp ../__init__.py pymoos/
47-
- export PYTHONPATH=$PWD
67+
- |
68+
if [ -n "$PYTHON" ]; then
69+
python setup.py sdist
70+
pip install --verbose dist/*.tar.gz
71+
elif [ -n "$CONDA" ]; then
72+
conda build conda.recipe
73+
conda install --use-local pymoos
74+
fi
4875
4976
script:
50-
- ctest -V
77+
- cd tests/
78+
- python run_close.py
79+
- python simple_comms.py
80+
- python register.py
81+
- python callbacks.py

CMakeLists.txt

Lines changed: 2 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,104 +4,6 @@ find_package(MOOS 10 REQUIRED)
44

55

66
add_subdirectory(pybind11)
7-
pybind11_add_module(pymoos pyMOOS.cpp)
7+
pybind11_add_module(pymoos src/pyMOOS.cpp)
88
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${MOOS_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIR})
9-
10-
11-
set_target_properties(pymoos
12-
PROPERTIES
13-
SUFFIX ".so")
14-
15-
set_target_properties(pymoos
16-
PROPERTIES
17-
PREFIX "")
18-
19-
#########################################################Saad
20-
if (WIN32)
21-
if (MSVC)
22-
# /bigobj is needed for bigger binding projects due to the limit to 64k
23-
# addressable sections. /MP enables multithreaded builds (relevant when
24-
# there are many files).
25-
set_target_properties(pymoos PROPERTIES COMPILE_FLAGS "/MP /bigobj ")
26-
27-
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
28-
# Enforce size-based optimization and link time code generation on MSVC
29-
# (~30% smaller binaries in experiments).
30-
set_target_properties(pymoos APPEND_STRING PROPERTY COMPILE_FLAGS "/Os /GL ")
31-
set_target_properties(pymoos APPEND_STRING PROPERTY LINK_FLAGS "/LTCG ")
32-
endif()
33-
endif()
34-
35-
# .PYD file extension on Windows
36-
set_target_properties(pymoos PROPERTIES SUFFIX ".pyd")
37-
38-
# Link against the Python shared library
39-
target_link_libraries(pymoos PUBLIC ${PYTHON_LIBRARY} ${MOOS_LIBRARIES})
40-
elseif (UNIX)
41-
# It's quite common to have multiple copies of the same Python version
42-
# installed on one's system. E.g.: one copy from the OS and another copy
43-
# that's statically linked into an application like Blender or Maya.
44-
# If we link our plugin library against the OS Python here and import it
45-
# into Blender or Maya later on, this will cause segfaults when multiple
46-
# conflicting Python instances are active at the same time (even when they
47-
# are of the same version).
48-
49-
# Windows is not affected by this issue since it handles DLL imports
50-
# differently. The solution for Linux and Mac OS is simple: we just don't
51-
# link against the Python library. The resulting shared library will have
52-
# missing symbols, but that's perfectly fine -- they will be resolved at
53-
# import time.
54-
55-
# .SO file extension on Linux/Mac OS
56-
set_target_properties(pymoos PROPERTIES SUFFIX ".so")
57-
58-
# Strip unnecessary sections of the binary on Linux/Mac OS
59-
if(APPLE)
60-
set_target_properties(pymoos PROPERTIES MACOSX_RPATH ".")
61-
set_target_properties(pymoos PROPERTIES LINK_FLAGS "-undefined dynamic_lookup ")
62-
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
63-
add_custom_command(TARGET pymoos POST_BUILD COMMAND strip -u -r ${PROJECT_BINARY_DIR}/pymoos.so)
64-
endif()
65-
target_link_libraries(pymoos PUBLIC ${PYTHON_LIBRARIES} ${MOOS_LIBRARIES})
66-
else()
67-
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
68-
add_custom_command(TARGET pymoos POST_BUILD COMMAND strip ${PROJECT_BINARY_DIR}/pymoos.so)
69-
endif()
70-
target_link_libraries(pymoos ${PYTHON_LIBRARIES} ${MOOS_LIBRARIES})
71-
endif()
72-
73-
endif()
74-
75-
file(GLOB ExampleFiles ${CMAKE_SOURCE_DIR}/Documentation/examples/*.py)
76-
add_custom_target(copy)
77-
get_target_property(pymoosLocation pymoos LOCATION)
78-
get_filename_component(pymoosDir ${pymoosLocation} PATH)
79-
foreach(ExampleFile ${ExampleFiles})
80-
add_custom_command(TARGET copy PRE_BUILD
81-
COMMAND ${CMAKE_COMMAND} -E
82-
copy ${ExampleFile} ${pymoosDir})
83-
endforeach()
84-
add_dependencies(pymoos copy)
85-
86-
87-
execute_process(COMMAND
88-
${PYTHON_EXECUTABLE} -c "import distutils.sysconfig, sys; sys.stdout.write(distutils.sysconfig.get_python_lib(1,0,\"\"))"
89-
OUTPUT_VARIABLE PYTHON_INSTALL
90-
ERROR_VARIABLE PYTHON_STDERR
91-
RESULT_VARIABLE PYTHON_ERR
92-
)
93-
if(NOT PYTHON_INSTDIR)
94-
set(PYTHON_INSTDIR ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL})
95-
endif(NOT PYTHON_INSTDIR)
96-
if(WIN32)
97-
string(REGEX REPLACE "\\\\" "/" PYTHON_INSTDIR ${PYTHON_INSTDIR})
98-
endif(WIN32)
99-
message(STATUS "pymoos will be installed in ${PYTHON_INSTDIR}")
100-
INSTALL(FILES ${CMAKE_BINARY_DIR}/pymoos.so
101-
__init__.py
102-
DESTINATION ${PYTHON_INSTDIR}/pymoos/
103-
)
104-
105-
###### Testing ######
106-
include( CTest )
107-
ADD_SUBDIRECTORY(testing)
9+
target_link_libraries(pymoos ${PYTHON_LIBRARIES} ${MOOS_LIBRARIES})

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include README.md LICENSE
2+
global-include CMakeLists.txt *.cmake
3+
recursive-include src *
4+
recursive-include pybind11/include *.h

setup.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
import re
3+
import sys
4+
import platform
5+
import subprocess
6+
7+
from setuptools import setup, Extension
8+
from setuptools.command.build_ext import build_ext
9+
from distutils.version import LooseVersion
10+
11+
12+
class CMakeExtension(Extension):
13+
def __init__(self, name, sourcedir=''):
14+
Extension.__init__(self, name, sources=[])
15+
self.sourcedir = os.path.abspath(sourcedir)
16+
17+
18+
class CMakeBuild(build_ext):
19+
def run(self):
20+
try:
21+
out = subprocess.check_output(['cmake', '--version'])
22+
except OSError:
23+
raise RuntimeError("CMake must be installed to build the following extensions: " +
24+
", ".join(e.name for e in self.extensions))
25+
26+
if platform.system() == "Windows":
27+
cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.decode()).group(1))
28+
if cmake_version < '3.1.0':
29+
raise RuntimeError("CMake >= 3.1.0 is required on Windows")
30+
31+
for ext in self.extensions:
32+
self.build_extension(ext)
33+
34+
def build_extension(self, ext):
35+
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
36+
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
37+
'-DPYTHON_EXECUTABLE=' + sys.executable]
38+
39+
cfg = 'Debug' if self.debug else 'Release'
40+
build_args = ['--config', cfg]
41+
42+
if platform.system() == "Windows":
43+
cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)]
44+
if sys.maxsize > 2**32:
45+
cmake_args += ['-A', 'x64']
46+
build_args += ['--', '/m']
47+
else:
48+
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
49+
build_args += ['--', '-j2']
50+
51+
env = os.environ.copy()
52+
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
53+
self.distribution.get_version())
54+
if not os.path.exists(self.build_temp):
55+
os.makedirs(self.build_temp)
56+
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
57+
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
58+
59+
setup(
60+
name='pymoos',
61+
version='0.0.1',
62+
author='Mohamed Saad Ibn Seddik',
63+
author_email='ms.ibnseddik@gmail.com',
64+
description='MOOS python wrapper.',
65+
long_description='',
66+
ext_modules=[CMakeExtension('pymoos')],
67+
cmdclass=dict(build_ext=CMakeBuild),
68+
zip_safe=False,
69+
)
File renamed without changes.

testing/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)