Skip to content

Commit ceb4e5e

Browse files
committed
Updates trying to enable pregeneration of all required classes.
1 parent cc745de commit ceb4e5e

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ a.out
1919
/.idea
2020
*.iml
2121
.lsp
22-
.clj-kondo
22+
.clj-kondo
23+
pregen-ffi-test

Diff for: deps.edn

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{:paths ["src"]
22
:deps {org.clojure/clojure {:mvn/version "1.10.2" :scope "provided"}
3-
cnuernber/dtype-next {:mvn/version "9.009"}
3+
cnuernber/dtype-next {:mvn/version "9.015"}
44
net.java.dev.jna/jna {:mvn/version "5.10.0"}
55
org.clojure/data.json {:mvn/version "1.0.0"}}
66

@@ -55,7 +55,7 @@
5555
:exec-fn hf.depstar/jar
5656
:exec-args {:group-id "clj-python"
5757
:artifact-id "libpython-clj"
58-
:version "2.018"
58+
:version "2.019-SNAPSHOT"
5959
:sync-pom true
6060
:aot true
6161
:compile-ns [libpython-clj2.java-api]

Diff for: docs/Usage.html

+9-11
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ <h4>MacOSX</h4>
2828
<h3>Initialize python</h3>
2929
<pre><code class="language-clojure">user&gt;
3030

31-
user&gt; (require '[libpython-clj.python
32-
:refer [as-python as-jvm
33-
-&gt;python -&gt;jvm
34-
get-attr call-attr call-attr-kw
35-
get-item att-type-map
36-
call call-kw initialize!
37-
as-numpy as-tensor -&gt;numpy
38-
run-simple-string
39-
add-module module-dict
40-
import-module
41-
python-type]])
31+
user&gt; (require [libpython-clj2.python
32+
:refer [as-python as-jvm
33+
-&gt;python -&gt;jvm
34+
get-attr call-attr call-attr-kw
35+
get-item initialize!
36+
run-simple-string
37+
add-module module-dict
38+
import-module
39+
python-type]])
4240
nil
4341

4442
; Mac and Linux

Diff for: src/libpython_clj2/python/ffi.clj

+22-17
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,22 @@ Each call must be matched with PyGILState_Release"}
303303
:doc "Mark a python function as being an instance method."}
304304
})
305305

306+
(defn define-library!
307+
[python-lib-classname]
308+
(dt-ffi/define-library
309+
python-library-fns
310+
["_Py_NoneStruct"
311+
"_Py_FalseStruct"
312+
"_Py_TrueStruct"
313+
"PyType_Type"
314+
"PyExc_StopIteration"
315+
"PyRange_Type"
316+
"PyExc_Exception"]
317+
{:classname python-lib-classname}))
318+
319+
320+
(def python-lib-def* (delay (define-library! nil)))
306321

307-
(def python-lib-def* (delay (dt-ffi/define-library
308-
python-library-fns
309-
["_Py_NoneStruct"
310-
"_Py_FalseStruct"
311-
"_Py_TrueStruct"
312-
"PyType_Type"
313-
"PyExc_StopIteration"
314-
"PyRange_Type"
315-
"PyExc_Exception"]
316-
nil
317-
)))
318322
(defonce pyobject-struct-type*
319323
(delay (dt-struct/define-datatype!
320324
:pyobject [{:name :ob_refcnt :datatype (ffi-size-t/size-t-type)}
@@ -345,19 +349,19 @@ Each call must be matched with PyGILState_Release"}
345349

346350

347351
(defn reset-library!
348-
[]
352+
[& [library-definition]]
349353
(when @library-path*
350-
(reset! library* (dt-ffi/instantiate-library @python-lib-def*
354+
(reset! library* (dt-ffi/instantiate-library (or library-definition @python-lib-def*)
351355
(:libpath @library-path*)))))
352356

353357

354358
(defn set-library!
355-
[libpath]
359+
[libpath & [library-definition]]
356360
(when @library*
357361
(log/warnf "Python library is being reinitialized to (%s). Is this what you want?"
358362
libpath))
359363
(reset! library-path* {:libpath libpath})
360-
(reset-library!))
364+
(reset-library! library-definition))
361365

362366
;;Useful for repling around - this regenerates the library function bindings
363367
(reset-library!)
@@ -572,11 +576,12 @@ Each call must be matched with PyGILState_Release"}
572576

573577

574578
(defn initialize!
575-
[libpath python-home & [{:keys [signals? program-name python-home]
579+
[libpath python-home & [{:keys [signals? program-name python-home
580+
library-definition]
576581
:or {signals? true
577582
program-name ""}
578583
:as opts}]]
579-
(set-library! libpath)
584+
(set-library! libpath library-definition)
580585
(when-not (= 1 (Py_IsInitialized))
581586
(log/debug "Initializing Python C Layer")
582587
;;platform specific encoding

0 commit comments

Comments
 (0)