Skip to content

Commit

Permalink
Support user install of swig python module (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarmy authored Mar 9, 2024
1 parent 6da1edb commit d5a3644
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ For usage information, see [the documentation](doc/README.md).
## Building python plugin
Requirements:
- rizin > 0.4.1 (needs commit [59b38e6](https://github.com/rizinorg/rizin/commit/59b38e6efaf00b9b9869e0ec5baba4f1b9605f37))
- meson >= 0.62.2
- meson >= 1.1.0
- ninja
- python >= 3.7
- python >= 3.10
- libclang
- SWIG

Expand Down
10 changes: 6 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ if target_swig
'-python', '-c++',
'-outdir', '@OUTDIR@', '@INPUT@'
],
install: true,
install: host_machine.system() == 'windows',
install_dir: [py.get_install_dir(), false]
)
swig_py = swig_output[0]
Expand All @@ -127,15 +127,18 @@ if target_swig
rz_core = dependency('rz_core')
endif

py.extension_module(
ext_mod = py.extension_module(
'_rizin',
swig_wrap,
dependencies: [
py.dependency(),
rz_core,
],
install: true,
install: host_machine.system() == 'windows',
)
if host_machine.system() != 'windows'
meson.add_install_script('py_install.py', swig_py.full_path(), ext_mod.full_path())
endif
endif

if target_sphinx
Expand All @@ -155,4 +158,3 @@ endif
if get_option('plugin').enabled()
subdir('plugin')
endif

26 changes: 26 additions & 0 deletions py_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3
"""
SPDX-FileCopyrightText: 2024 kazarmy <[email protected]>
SPDX-License-Identifier: LGPL-3.0-only
"""

import os
import shutil
import sys
import sysconfig

def install_files(scheme):
for file in sys.argv[1:]:
if file.endswith(".py"):
dest_type = 'purelib'
elif file.endswith(".so"):
dest_type = 'platlib'
install_dir = sysconfig.get_path(dest_type, scheme)
shutil.copy(file, install_dir)
print(f"Installing {os.path.basename(file)} to {install_dir}")

try:
install_files(sysconfig.get_default_scheme())
except PermissionError:
print("Installing to user site-packages since normal site-packages is not writeable")
install_files(f"{os.name}_user")

0 comments on commit d5a3644

Please sign in to comment.