Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setuptools python install for linux #221

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ PID of the browser, its name or substring thereof, or both:

##### Python module

To use the Python module, `import` `acacia_atspi`from within your Python script or the Python Interpreter. For example:
To use the Python module, `import` `acacia_atspi` from within your Python script or the Python Interpreter. For example:

```
% cd build/example/atspi/
Expand Down Expand Up @@ -416,6 +416,12 @@ Use the CMAKE variable `CMAKE_INSTALL_PREFIX` to define the root directory where
$ cmake -DCMAKE_INSTALL_PREFIX=/usr ..
```

To install the python library, run

```
make install_python
```

### On Linux

On Linux, the default prefix is `/usr/local`.
Expand Down
17 changes: 0 additions & 17 deletions examples/atspi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@ add_custom_target(
dump_tree_atspi
)

if (ACACIA_PYTHON)
add_custom_target(
dump_tree_atspi.py
ALL
DEPENDS
acacia_atspi
acacia_atspi_python
COMMAND
${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/dump_tree_atspi.py ${CMAKE_CURRENT_BINARY_DIR}/
COMMAND
${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/atspi/_acacia_atspi_python.so ${CMAKE_CURRENT_BINARY_DIR}/_acacia_atspi_python.so
COMMAND
${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/atspi/acacia_atspi.py ${CMAKE_CURRENT_BINARY_DIR}/acacia_atspi.py
VERBATIM
)
endif (ACACIA_PYTHON)

if (ACACIA_NODEJS)
add_custom_target(
dump_tree_atspi.js
Expand Down
69 changes: 39 additions & 30 deletions lib/atspi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,44 +76,53 @@ endif()
# Generate Python bindings using swig + python3

if (ACACIA_PYTHON)
FIND_PACKAGE(Python3 COMPONENTS Interpreter Development.Module)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${Python3_INCLUDE_DIRS})

SET_SOURCE_FILES_PROPERTIES(acacia_atspi.i PROPERTIES CPLUSPLUS ON)

SWIG_ADD_LIBRARY(
# The name of the c++ library used by python module
acacia_atspi_python
TYPE SHARED
LANGUAGE python
SOURCES acacia_atspi.i
)
configure_file(python/setup.py.in python/setup.py)
configure_file(python/pyproject.toml python/pyproject.toml)
configure_file(acacia_atspi.i python/acacia_atspi/acacia_atspi.i)

TARGET_LINK_LIBRARIES(
acacia_atspi_python
acacia_atspi
${python3_LIBRARIES}
find_package(Python COMPONENTS Interpreter Development)

add_custom_target(
python_acacia_atspi ALL
DEPENDS
acacia_atspi
python/setup.py
WORKING_DIRECTORY
python
COMMAND
${Python_EXECUTABLE} -m build .
)

set_property(
TARGET acacia_atspi_python
PROPERTY
SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE
TARGET python_acacia_atspi
APPEND
PROPERTY ADDITIONAL_CLEAN_FILES
${CMAKE_CURRENT_BINARY_DIR}/python/__pycache__
${CMAKE_CURRENT_BINARY_DIR}/python/acacia_atspi.egg-info
${CMAKE_CURRENT_BINARY_DIR}/python/dist
${CMAKE_CURRENT_BINARY_DIR}/python/acacia_atspi.py
${CMAKE_CURRENT_BINARY_DIR}/python/acacia_atspi_wrap.cpp
)

execute_process (
COMMAND python3 -c "import sys; ver_info = sys.version_info; print(f'python{ver_info[0]}.{ver_info[1]}', end='')"
OUTPUT_VARIABLE PY_MODULE_DIR
add_custom_target(
rename_init_py
DEPENDS
python_acacia_atspi
WORKING_DIRECTORY
python/acacia_atspi
COMMAND
${CMAKE_COMMAND} -E rename acacia_atspi.py __init__.py
)

install(TARGETS
acacia_atspi_python
LIBRARY
DESTINATION "lib/${PY_MODULE_DIR}/dist-packages"
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/acacia_atspi.py DESTINATION "lib/${PY_MODULE_DIR}/dist-packages"
add_custom_target(
install_python
DEPENDS
python_acacia_atspi
rename_init_py
WORKING_DIRECTORY
python
COMMAND
${Python_EXECUTABLE} -m pip install .
)
endif()

Expand Down
3 changes: 3 additions & 0 deletions lib/atspi/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
36 changes: 36 additions & 0 deletions lib/atspi/python/setup.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from setuptools import Extension, setup
import pprint

include_dirs = "${ATSPI2_INCLUDE_DIRS}".split(";")
include_dirs.append("${PROJECT_SOURCE_DIR}/include")
pprint.pp(include_dirs)

setup(
name='acacia_atspi',
version='0.0.1',
description='Python bindings for acacia_atspi',
ext_modules=[
Extension(
name='acacia_atspi._acacia_atspi',
swig_opts=[
'-c++',
'-I${PROJECT_SOURCE_DIR}/include',
'-I${ATSPI_INCLUDE_DIRS}',
],
include_dirs=include_dirs,
sources=[
"${CMAKE_CURRENT_BINARY_DIR}/python/acacia_atspi/acacia_atspi.i",
],
library_dirs=[
"${CMAKE_CURRENT_BINARY_DIR}",
],
libraries=[
"acacia_atspi",
"atspi",
],
extra_compile_args=[
'-std=c++11',
],
)
]
)
Loading