Skip to content

Commit 88045ff

Browse files
committed
fix path to dylib
1 parent d47af1a commit 88045ff

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

HISTORY.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
History
33
=======
44

5-
0.7.6 (2017-06-18)
5+
0.7.7 (2017-06-20)
66
------------------
77

88
* First release on PyPI.

rust_pypi_example/rust_pypi_example.py

+46
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,52 @@
3535
rust_lib = ffi.dlopen(DLPATH)
3636

3737

38+
def main():
39+
assert rust_lib.is_prime(13) == 1
40+
assert rust_lib.is_prime(12) == 0
41+
42+
43+
if __name__ == '__main__':
44+
main()
45+
46+
47+
# -*- coding: utf-8 -*-
48+
import os.path
49+
import os
50+
import sys
51+
from cffi import FFI
52+
53+
# See https://github.com/SimonSapin/hello-pyrust
54+
55+
56+
if sys.platform == 'win32':
57+
DYNAMIC_LIB_FORMAT = '%s.dll'
58+
elif sys.platform == 'darwin':
59+
DYNAMIC_LIB_FORMAT = 'lib%s.dylib'
60+
elif "linux" in sys.platform:
61+
DYNAMIC_LIB_FORMAT = 'lib%s.so'
62+
else:
63+
raise NotImplementedError('No implementation for "{}".'
64+
' Supported platforms are '
65+
'"win32", "darwin", and "linux"'
66+
''.format(sys.platform))
67+
ffi = FFI()
68+
(file_path, _) = os.path.split(__file__)
69+
cwd = os.getcwd()
70+
71+
h_path = os.path.join(file_path, 'rust', 'src', 'rust_pypi_example.h',)
72+
h_rel_path = os.path.join(os.curdir, os.path.relpath(h_path, cwd))
73+
74+
dlib_path = os.path.join(file_path, 'rust', 'target', 'release',
75+
DYNAMIC_LIB_FORMAT % 'rust_pypi_example')
76+
dlib_rel_path = os.path.join(os.curdir, os.path.relpath(dlib_path, cwd))
77+
78+
with open(h_rel_path) as h:
79+
ffi.cdef(h.read())
80+
81+
rust_lib = ffi.dlopen(dlib_rel_path)
82+
83+
3884
def main():
3985
assert rust_lib.is_prime(13) == 1
4086
assert rust_lib.is_prime(12) == 0

setup.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ replace = {new_version}
1919
search = {current_version}
2020
replace = {new_version}
2121

22+
2223
[flake8]
2324
exclude = docs
2425

@@ -27,5 +28,4 @@ test = pytest
2728

2829
[tool:pytest]
2930
testpaths = tests
30-
addopts = --verbose
31-
31+
addopts = --verbose

0 commit comments

Comments
 (0)