forked from clj-python/libpython-clj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython.clj
85 lines (73 loc) · 2.45 KB
/
python.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(ns libpython-clj.python
(:require [libpython-clj.jna :as libpy]
[libpython-clj.jna.base :as libpy-base]
[libpython-clj.python.logging
:refer [log-error log-warn log-info]]
[tech.parallel.utils :refer [export-symbols]]
[libpython-clj.python.interop :as pyinterop]
[libpython-clj.python.interpreter :as pyinterp
:refer [with-gil with-interpreter]]
[libpython-clj.python.object :as pyobject])
(:import [com.sun.jna Pointer]
[java.io Writer]
[libpython_clj.jna PyObject]))
(set! *warn-on-reflection* true)
(defn initialize!
[& {:keys [program-name no-redirect?]}]
(when-not @pyinterp/*main-interpreter*
(pyinterp/initialize! program-name)
;;setup bridge mechansim and io redirection
(when-not no-redirect?)
)
:ok)
(defn finalize!
[]
(pyinterp/finalize!))
(export-symbols libpython-clj.python.object
->py-dict
->py-float
->py-list
->py-long
->py-string
->py-tuple
->pyobject
copy-to-jvm
copy-to-python
get-attr
has-attr?
incref-wrap-pyobject
obj-get-item
obj-has-item?
obj-set-item
py-dir
py-false
py-none
py-not-implemented
py-raw-type
py-string->string
py-true
py-type-keyword
pyobj->string
python->jvm-copy-hashmap
python->jvm-copy-iterable
python->jvm-copy-persistent-vector
set-attr
wrap-pyobject)
(export-symbols libpython-clj.python.interop
run-simple-string
run-string
create-function
create-module
py-import-module)
(comment
(initialize!)
(def mm (create-module "mm"))
(def tt (pyinterop/register-bridge-type! mm))
(def writer-iface (pyinterop/wrap-var-writer #'*err*))
(def writer (pyinterop/expose-bridge-to-python! writer-iface mm))
(pyinterop/setup-std-writer #'*err* mm "stderr")
(pyinterop/setup-std-writer #'*out* mm "stdout")
(def sys-module (py-import-module "sys"))
(def stderr-item (get-attr sys-module "stderr"))
(def test-fn (get-attr stderr-item "write"))
)