Skip to content

Commit 1d8bee0

Browse files
authored
Add python3 CI (#118)
1 parent d800ed1 commit 1d8bee0

34 files changed

+217
-72
lines changed

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ SET(EDL_INSTALL_DIR ${CMAKE_BINARY_DIR}/output)
66
SET(CMAKE_INSTALL_RPATH "$ORIGIN" "${CMAKE_INSTALL_RPATH}")
77
project(paddle_edl)
88

9-
include(python)
10-
119
option(WITH_TESTING "Compile EDL with unit testing" ON)
1210
option(WITH_COVERAGE "Compile EDL with code coverage" OFF)
11+
option(PY_VERSION "Compile EDL with python3 support" ${PY_VERSION})
12+
13+
# PY_VERSION
14+
if(NOT PY_VERSION)
15+
set(PY_VERSION 2.7)
16+
endif()
17+
18+
include(python)
1319

1420
IF(WITH_TESTING)
1521
ENABLE_TESTING()

cmake/python.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
1+
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
INCLUDE(python_module)
16+
1517
FIND_PACKAGE(PythonInterp ${PY_VERSION} REQUIRED)
1618
FIND_PACKAGE(PythonLibs ${PY_VERSION} REQUIRED)
1719

@@ -62,4 +64,10 @@ ADD_LIBRARY(python SHARED IMPORTED GLOBAL)
6264
SET_PROPERTY(TARGET python PROPERTY IMPORTED_LOCATION ${PYTHON_LIBRARIES})
6365

6466
SET(py_env "")
67+
IF(PYTHONINTERP_FOUND)
68+
find_python_module(pip REQUIRED)
69+
find_python_module(wheel REQUIRED)
70+
ENDIF(PYTHONINTERP_FOUND)
6571
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR})
72+
INCLUDE_DIRECTORIES(${PYTHON_NUMPY_INCLUDE_DIR})
73+

cmake/python_module.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Find if a Python module is installed
2+
# Found at http://www.cmake.org/pipermail/cmake/2011-January/041666.html
3+
# To use do: find_python_module(PyQt4 REQUIRED)
4+
function(find_python_module module)
5+
string(TOUPPER ${module} module_upper)
6+
if(NOT PY_${module_upper})
7+
if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
8+
set(${module}_FIND_REQUIRED TRUE)
9+
else()
10+
set(${module}_FIND_REQUIRED FALSE)
11+
endif()
12+
# A module's location is usually a directory, but for binary modules
13+
# it's a .so file.
14+
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
15+
"import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
16+
RESULT_VARIABLE _${module}_status
17+
OUTPUT_VARIABLE _${module}_location
18+
ERROR_QUIET
19+
OUTPUT_STRIP_TRAILING_WHITESPACE)
20+
if(NOT _${module}_status)
21+
set(PY_${module_upper} ${_${module}_location} CACHE STRING
22+
"Location of Python module ${module}")
23+
endif(NOT _${module}_status)
24+
endif(NOT PY_${module_upper})
25+
find_package_handle_standard_args(PY_${module} DEFAULT_MSG PY_${module_upper})
26+
if(NOT PY_${module_upper}_FOUND AND ${module}_FIND_REQUIRED)
27+
message(FATAL_ERROR "python module ${module} is not found")
28+
endif()
29+
30+
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
31+
"import sys, ${module}; sys.stdout.write(${module}.__version__)"
32+
OUTPUT_VARIABLE _${module}_version
33+
RESULT_VARIABLE _${module}_status
34+
ERROR_QUIET
35+
OUTPUT_STRIP_TRAILING_WHITESPACE)
36+
if(NOT _${module}_status)
37+
set(PY_${module_upper}_VERSION ${_${module}_version} CACHE STRING
38+
"Version of Python module ${module}")
39+
endif(NOT _${module}_status)
40+
41+
set(PY_${module_upper}_FOUND ${PY_${module_upper}_FOUND} PARENT_SCOPE)
42+
set(PY_${module_upper}_VERSION ${PY_${module_upper}_VERSION} PARENT_SCOPE)
43+
endfunction(find_python_module)
44+

docker/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ ENV PATH=$PATH:${GOROOT}/bin:${GOPATH}/bin
1212

1313
# python
1414
ADD ./docker/requirements.txt /root/paddle_edl/requirements.txt
15-
RUN python -m pip install -r /root/paddle_edl/requirements.txt
15+
RUN python -m pip install pip==20.1.1
16+
RUN python3.6 -m pip install pip==20.1.1
17+
RUN python3.6 -m pip install --upgrade setuptools
18+
RUN python -m pip install -r /root/paddle_edl/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
19+
RUN python3.6 -m pip install -r /root/paddle_edl/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
1620

1721
#etcd
1822
ENV HOME /root

docker/Dockerfile.runtime

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ ENV GOROOT=/usr/local/go GOPATH=/root/gopath
1111
ENV PATH=$PATH:{GOROOT}/bin:${GOPATH}/bin
1212

1313
ADD ./docker/requirements.txt /root/paddle_edl/requirements.txt
14+
RUN python -m pip install pip==20.1.1
15+
RUN python3.6 -m pip install pip==20.1.1
16+
RUN python3.6 -m pip install --upgrade setuptools
1417
RUN python -m pip install -r /root/paddle_edl/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
18+
RUN python3.6 -m pip install -r /root/paddle_edl/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
1519

1620
# etcd
1721
ENV HOME /root
@@ -28,9 +32,10 @@ RUN cd /tmp/ && wget -q https://paddle-edl.bj.bcebos.com/redis-6.0.1.tar.gz &&
2832
cd .. && rm -rf redis-6.0.1.tar.gz redis-6.0.1
2933

3034
# install edl
31-
ADD ./build/python/dist/paddle_edl-0.0.0-py2-none-any.whl /tmp/paddle_edl-0.0.0-py2-none-any.whl
32-
RUN python -m pip install /tmp/paddle_edl-0.0.0-py2-none-any.whl
33-
RUN rm -f /tmp/paddle_edl-0.0.0-py2-none-any.whl
35+
ADD ./build/python/dist/paddle_edl-0.0.0-py2.py3-none-any.whl /tmp/paddle_edl-0.0.0-py2.py3-none-any.whl
36+
RUN python -m pip install /tmp/paddle_edl-0.0.0-py2.py3-none-any.whl
37+
RUN python3.6 -m pip install /tmp/paddle_edl-0.0.0-py2.py3-none-any.whl
38+
RUN rm -f /tmp/paddle_edl-0.0.0-py2.py3-none-any.whl
3439

3540
# add example
3641
ADD ./example /root/paddle_edl/example

docker/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ redis
99
paddle-serving-client
1010
paddle-serving-server-gpu
1111
paddle-serving-app
12+
paddlepaddle-gpu==1.8.0.post107

python/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DI
33
add_custom_command(
44
OUTPUT ${EDL_BINARY_DIR}/.timestamp
55
COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/paddle_edl ${EDL_BINARY_DIR}/python/
6-
COMMAND env ${py_env} ${PYTHON_EXECUTABLE} ./setup.py bdist_wheel
6+
COMMAND python3.6 ./setup.py bdist_wheel --universal
77
DEPENDS ${EDL_FILES})
88
add_custom_target(edl_python ALL DEPENDS ${EDL_BINARY_DIR}/.timestamp)
99
add_subdirectory(paddle_edl/tests/unittests)

python/paddle_edl/collective/edl_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import requests
1717
import time
1818
import sys
19-
from utils import Cluster, Pod, Trainer, logger, Hdfs
20-
from http_store import kv_server
19+
from .utils import Cluster, Pod, Trainer, logger, Hdfs
20+
from .http_store import kv_server
2121

2222

2323
class Edlenv(object):

python/paddle_edl/collective/http_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import multiprocessing
1313
import os
1414
import sys
15-
import utils
15+
from . import utils
1616
import subprocess
17-
from utils import logger
17+
from .utils import logger
1818

1919
app = Flask(__name__)
2020

python/paddle_edl/collective/launch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
from contextlib import closing
4949
import socket
5050

51-
from utils import *
52-
import edl_utils
53-
from http_store import kv_server
51+
from .utils import *
52+
from . import edl_utils
53+
from .http_store import kv_server
5454

5555

5656
def _print_arguments(args):

0 commit comments

Comments
 (0)