Skip to content

Commit

Permalink
Build Ray with setup.py. (ray-project#14)
Browse files Browse the repository at this point in the history
* Build Ray with setup.py.

* Building photon extensions with cmake.

* Fix formatting in photon_extension.c

* Pip install with sudo in Travis.

* Fix plasma __init__.py.

* Rename and remove some files.
  • Loading branch information
robertnishihara authored and pcmoritz committed Nov 1, 2016
1 parent 695f23b commit 47851ee
Show file tree
Hide file tree
Showing 18 changed files with 291 additions and 175 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ install:
- sudo python setup.py install
- cd ../../../..

- cd src/photon/lib/python
- cd src/photon
- sudo python setup.py install
- cd ../../../..
- cd ../..

- source src/plasma/setup-env.sh
- cd lib/python
- sudo python setup.py install
- cd ../..

script:
- python src/common/test/test.py
Expand Down
26 changes: 23 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,36 @@ else
exit 1
fi

pushd "$ROOT_DIR/src/common"
COMMON_DIR="$ROOT_DIR/src/common"
PLASMA_DIR="$ROOT_DIR/src/plasma"
PHOTON_DIR="$ROOT_DIR/src/photon"

PYTHON_DIR="$ROOT_DIR/lib/python"
PYTHON_COMMON_DIR="$PYTHON_DIR/common"
PYTHON_PLASMA_DIR="$PYTHON_DIR/plasma"
PYTHON_PHOTON_DIR="$PYTHON_DIR/photon"

pushd "$COMMON_DIR"
make
make test
popd
cp "$COMMON_DIR/thirdparty/redis-3.2.3/src/redis-server" "$PYTHON_COMMON_DIR/thirdparty/redis-3.2.3/src/"

pushd "$ROOT_DIR/src/plasma"
pushd "$PLASMA_DIR"
make
make test
popd
cp "$PLASMA_DIR/build/plasma_store" "$PYTHON_PLASMA_DIR/build/"
cp "$PLASMA_DIR/build/plasma_manager" "$PYTHON_PLASMA_DIR/build/"
cp "$PLASMA_DIR/build/plasma_client.so" "$PYTHON_PLASMA_DIR/build/"
cp "$PLASMA_DIR/lib/python/plasma.py" "$PYTHON_PLASMA_DIR/lib/python/"

pushd "$ROOT_DIR/src/photon"
pushd "$PHOTON_DIR"
make
pushd "$PHOTON_DIR/build"
cmake ..
make install
popd
popd
cp "$PHOTON_DIR/build/photon_scheduler" "$PYTHON_PHOTON_DIR/build"
cp "$PHOTON_DIR/photon/libphoton.so" "$PYTHON_PHOTON_DIR/"
Empty file added lib/python/common/__init__.py
Empty file.
Empty file.
1 change: 1 addition & 0 deletions lib/python/photon/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from libphoton import *
Empty file.
1 change: 1 addition & 0 deletions lib/python/plasma/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from lib.python.plasma import *
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion lib/python/ray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Ray version string
__version__ = "0.1"
__version__ = "0.01"

import ctypes
# Windows only
Expand Down
36 changes: 22 additions & 14 deletions lib/python/setup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import sys
import subprocess

from setuptools import setup, Extension, find_packages
import setuptools
from setuptools import setup, find_packages
import setuptools.command.install as _install

# because of relative paths, this must be run from inside ray/lib/python/
class install(_install.install):
def run(self):
subprocess.check_call(["../../build.sh"])
# Calling _install.install.run(self) does not fetch required packages and
# instead performs an old-style install. See command/install.py in
# setuptools. So, calling do_egg_install() manually here.
self.do_egg_install()

setup(
name = "ray",
version = "0.1.dev0",
use_2to3=True,
packages=find_packages(),
package_data = {
"ray": ["libraylib.so", "scheduler", "objstore"]
},
zip_safe=False
)
setup(name="ray",
version="0.0.1",
packages=find_packages(),
package_data={"common": ["thirdparty/redis-3.2.3/src/redis-server"],
"plasma": ["build/plasma_store",
"build/plasma_manager",
"build/plasma_client.so"],
"photon": ["build/photon_scheduler",
"libphoton.so"]},
cmdclass={"install": install},
include_package_data=True,
zip_safe=False)
73 changes: 73 additions & 0 deletions src/photon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
cmake_minimum_required(VERSION 2.8)

project(photon)

if(NOT APPLE)
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
set(CUSTOM_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
else()
find_program(CUSTOM_PYTHON_EXECUTABLE python)
message("-- Found Python program: ${CUSTOM_PYTHON_EXECUTABLE}")
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
"import sys; print 'python' + sys.version[0:3]"
OUTPUT_VARIABLE PYTHON_LIBRARY_NAME OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
"import sys; print sys.exec_prefix"
OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
FIND_LIBRARY(PYTHON_LIBRARIES
NAMES ${PYTHON_LIBRARY_NAME}
HINTS "${PYTHON_PREFIX}"
PATH_SUFFIXES "lib" "libs"
NO_DEFAULT_PATH)
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
"from distutils.sysconfig import *; print get_python_inc()"
OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE)
if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS)
SET(PYTHONLIBS_FOUND TRUE)
message("-- Found PythonLibs: " ${PYTHON_LIBRARIES})
message("-- -- Used custom search path")
else()
find_package(PythonLibs REQUIRED)
message("-- -- Used find_package(PythonLibs)")
endif()
endif()

if(APPLE)
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif(APPLE)

include_directories("${PYTHON_INCLUDE_DIRS}")

set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} --std=c99 -Werror")

if (UNIX AND NOT APPLE)
link_libraries(rt)
endif()

set(PHOTON_CLIENT_LIB "${CMAKE_SOURCE_DIR}/build/photon_client.a" CACHE STRING
"Path to photon_client.a")

set(COMMON_LIB "${CMAKE_SOURCE_DIR}/../common/build/libcommon.a" CACHE STRING
"Path to libcommon.a")

include_directories("${CMAKE_SOURCE_DIR}/")
include_directories("${CMAKE_SOURCE_DIR}/../")
include_directories("${CMAKE_SOURCE_DIR}/../common/")
include_directories("${CMAKE_SOURCE_DIR}/../common/thirdparty/")
include_directories("${CMAKE_SOURCE_DIR}/../common/lib/python/")

add_library(photon SHARED
photon_extension.c
../common/lib/python/common_extension.c)

get_filename_component(PYTHON_SHARED_LIBRARY ${PYTHON_LIBRARIES} NAME)
if(APPLE)
add_custom_command(TARGET photon
POST_BUILD COMMAND
${CMAKE_INSTALL_NAME_TOOL} -change ${PYTHON_SHARED_LIBRARY} ${PYTHON_LIBRARIES} libphoton.so)
endif(APPLE)

target_link_libraries(photon ${PHOTON_CLIENT_LIB} ${COMMON_LIB} ${PYTHON_LIBRARIES})

install(TARGETS photon DESTINATION ${CMAKE_SOURCE_DIR}/photon)
140 changes: 0 additions & 140 deletions src/photon/lib/python/photon_extension.c

This file was deleted.

14 changes: 0 additions & 14 deletions src/photon/lib/python/setup.py

This file was deleted.

1 change: 1 addition & 0 deletions src/photon/photon/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from libphoton import *
Loading

0 comments on commit 47851ee

Please sign in to comment.