Skip to content

Commit

Permalink
automatic python version switch (#2)
Browse files Browse the repository at this point in the history
* delete meta-package and add puginxml cmake module

* add python package files

* make it work with python3

* get setup.py working

* clean up

* clean up

* minor update

* update dependencies

* track the original readme

* update

* ~_~ add the missing setup ignored by the original .gitignore file

* add pip3 and setuptools install command

* update

* fix import error

* more robust import

* add needed package and cmake module

* update readme

* minor update

* ignore generated files

* fix linking issue

* automatical switch version according to python version

* update readme

* resolve conflicts
  • Loading branch information
yuzhangbit authored Jan 14, 2019
1 parent 164f4f1 commit 4564901
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-backtrace-limit=0")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

find_package(Boost REQUIRED COMPONENTS python-py35 serialization system filesystem)
find_package(PythonLibs 3.5 REQUIRED) # sets ${PYTHON_INCLUDE_DIRS}
option(USE_PYTHON3 "Use python 3 to build libraries." ON)
if (USE_PYTHON3)
find_package(Boost REQUIRED COMPONENTS python-py35 serialization system filesystem)
find_package(PythonLibs 3.5 REQUIRED) # sets ${PYTHON_INCLUDE_DIRS}
else()
find_package(Boost REQUIRED COMPONENTS python serialization system filesystem)
find_package(PythonLibs 2.7 REQUIRED) # sets ${PYTHON_INCLUDE_DIRS}
endif()
find_package(Eigen3 QUIET)
if(NOT EIGEN3_FOUND)
find_package(PkgConfig REQUIRED)
Expand Down Expand Up @@ -65,7 +70,6 @@ foreach(SUBMODULE ${MODUELS})
lanelet2_python/python_api/${SUBMODULE}.cpp # binding codes
)
target_compile_definitions(${API_LIBRARY_NAME} PRIVATE -DPYTHON_API_MODULE_NAME=lib${API_LIBRARY_NAME})
#target_compile_options(${API_LIBRARY_NAME} PRIVATE -Wl,-rpath='$ORIGIN')
target_link_libraries(${API_LIBRARY_NAME}
${Boost_LIBRARIES}
${PYTHON_LIBRARY}
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# lanelet2_standalone

## Overview
This is a standalone lanelet2 **python3** package for the [Lanelet2](https://github.com/fzi-forschungszentrum-informatik/Lanelet2) library, which **does not** require the ROS and catkin.
This is a standalone lanelet2 **python3/python2** package for the [Lanelet2](https://github.com/fzi-forschungszentrum-informatik/Lanelet2) library, which **does not** require the ROS and catkin.

## Installation
pylanelet2 uses cmake and setuptools for building and packaging and is targeted towards Linux.
Expand All @@ -10,13 +10,13 @@ At least C++14 is required.

### Tested Configuration
* `Ubuntu 16.04 LTS`
* `python3.5`
* `python2.7/python3.5`

### Dependencies
* `Boost` (from 1.58, for lanelet2_io)
* `eigen3`
* `pugixml` (for lanelet2_io)
* `boost-python/python3`
* `boost-python2/python3`
* `geographiclib` (for lanelet2_projection)

For Ubuntu:
Expand All @@ -25,13 +25,22 @@ sudo apt-get install -y cmake libboost-all-dev libeigen3-dev libgeographic-dev l
```

### Installing
In the repo root folder,
* Building
```bash
git clone https://github.com/yuzhangbit/lanelet2_standalone.git
cd lanelet2_standalone
```
* Install lanelet2 for system python3:
```shell
sudo python3 setup.py install
```
or
* Or install lanelet2 for system python2:
```bash
/path/to/your/python3 setup.py install
sudo python setup.py install
```
* Or install lanelet2 for other python version:
```
/path/to/python setup.py install
```

## Usage
Expand All @@ -49,7 +58,7 @@ p.id = getId()
```

**Note:
Importing submodules from the raw `liblanelet2_core_pyapi.so` library like below is not supported.**
Importing submodules from the raw `liblanelet2_core_pyapi.so` library like below is not supported.**
If you do this,
```python
from lanelet2.liblanelet2_core_pyapi import AttributeMap # not supported!!!
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python3
#! /usr/bin/env python
from setuptools import setup, Extension
from io import open
import subprocess
Expand All @@ -25,12 +25,18 @@ def run(self):
def build_extension(self, ext):
extdir = os.path.abspath(
os.path.dirname(self.get_ext_fullpath(ext.name)))
# python version
self.python_version = sys.version_info.major
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable]

cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
if self.python_version == 3:
cmake_args += ['-DUSE_PYTHON3=ON']
else:
cmake_args += ['-DUSE_PYTHON3=OFF']
build_args += ['--', '-j4']

env = os.environ.copy()
Expand All @@ -54,6 +60,7 @@ def build_extension(self, ext):
'Intended Audience :: Developers',
'Topic :: Software Development :: autonomous driving',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 2.7',
],
license='BSD 3-Clause',
packages=['lanelet2'],
Expand Down

0 comments on commit 4564901

Please sign in to comment.