Skip to content

Commit 65fa30a

Browse files
author
BEHRING Carsten
committed
use python.edn
1 parent 724a76c commit 65fa30a

File tree

4 files changed

+49
-218
lines changed

4 files changed

+49
-218
lines changed

deps.edn

Lines changed: 1 addition & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -82,171 +82,5 @@
8282
:artifact "target/libpython-clj.jar"}}
8383

8484
}
85-
86-
:python-version "3.13.7"
87-
:python-deps [
88-
"openai==1.58.1"
89-
]
9085

91-
:renv-deps {:R
92-
{:Version "4.4.1",
93-
:Repositories [{:Name "CRAN", :URL "https://cloud.r-project.org"}]},
94-
:Packages
95-
{:tidyselect
96-
{:Package "tidyselect",
97-
:Version "1.2.1",
98-
:Source "Repository",
99-
:Repository "CRAN",
100-
:Requirements
101-
["R" "cli" "glue" "lifecycle" "rlang" "vctrs" "withr"],
102-
:Hash "829f27b9c4919c16b593794a6344d6c0"},
103-
:withr
104-
{:Package "withr",
105-
:Version "3.0.1",
106-
:Source "Repository",
107-
:Repository "CRAN",
108-
:Requirements ["R" "grDevices" "graphics"],
109-
:Hash "07909200e8bbe90426fbfeb73e1e27aa"},
110-
:utf8
111-
{:Package "utf8",
112-
:Version "1.2.4",
113-
:Source "Repository",
114-
:Repository "CRAN",
115-
:Requirements ["R"],
116-
:Hash "62b65c52671e6665f803ff02954446e9"},
117-
:rlang
118-
{:Package "rlang",
119-
:Version "1.1.4",
120-
:Source "Repository",
121-
:Repository "CRAN",
122-
:Requirements ["R" "utils"],
123-
:Hash "3eec01f8b1dee337674b2e34ab1f9bc1"},
124-
:glue
125-
{:Package "glue",
126-
:Version "1.7.0",
127-
:Source "Repository",
128-
:Repository "CRAN",
129-
:Requirements ["R" "methods"],
130-
:Hash "e0b3a53876554bd45879e596cdb10a52"},
131-
:vctrs
132-
{:Package "vctrs",
133-
:Version "0.6.5",
134-
:Source "Repository",
135-
:Repository "CRAN",
136-
:Requirements ["R" "cli" "glue" "lifecycle" "rlang"],
137-
:Hash "c03fa420630029418f7e6da3667aac4a"},
138-
:tibble
139-
{:Package "tibble",
140-
:Version "3.2.1",
141-
:Source "Repository",
142-
:Repository "CRAN",
143-
:Requirements
144-
["R"
145-
"fansi"
146-
"lifecycle"
147-
"magrittr"
148-
"methods"
149-
"pillar"
150-
"pkgconfig"
151-
"rlang"
152-
"utils"
153-
"vctrs"],
154-
:Hash "a84e2cc86d07289b3b6f5069df7a004c"},
155-
:magrittr
156-
{:Package "magrittr",
157-
:Version "2.0.3",
158-
:Source "Repository",
159-
:Repository "CRAN",
160-
:Requirements ["R"],
161-
:Hash "7ce2733a9826b3aeb1775d56fd305472"},
162-
:lifecycle
163-
{:Package "lifecycle",
164-
:Version "1.0.4",
165-
:Source "Repository",
166-
:Repository "CRAN",
167-
:Requirements ["R" "cli" "glue" "rlang"],
168-
:Hash "b8552d117e1b808b09a832f589b79035"},
169-
:dplyr
170-
{:Package "dplyr",
171-
:Version "1.1.4",
172-
:Source "Repository",
173-
:Repository "CRAN",
174-
:Requirements
175-
["R"
176-
"R6"
177-
"cli"
178-
"generics"
179-
"glue"
180-
"lifecycle"
181-
"magrittr"
182-
"methods"
183-
"pillar"
184-
"rlang"
185-
"tibble"
186-
"tidyselect"
187-
"utils"
188-
"vctrs"],
189-
:Hash "fedd9d00c2944ff00a0e2696ccf048ec"},
190-
:pkgconfig
191-
{:Package "pkgconfig",
192-
:Version "2.0.3",
193-
:Source "Repository",
194-
:Repository "CRAN",
195-
:Requirements ["utils"],
196-
:Hash "01f28d4278f15c76cddbea05899c5d6f"},
197-
:fansi
198-
{:Package "fansi",
199-
:Version "1.0.6",
200-
:Source "Repository",
201-
:Repository "CRAN",
202-
:Requirements ["R" "grDevices" "utils"],
203-
:Hash "962174cf2aeb5b9eea581522286a911f"},
204-
:renv
205-
{:Package "renv",
206-
:Version "1.0.7",
207-
:Source "Repository",
208-
:Repository "CRAN",
209-
:Requirements ["utils"],
210-
:Hash "397b7b2a265bc5a7a06852524dabae20"},
211-
:pillar
212-
{:Package "pillar",
213-
:Version "1.9.0",
214-
:Source "Repository",
215-
:Repository "CRAN",
216-
:Requirements
217-
["cli" "fansi" "glue" "lifecycle" "rlang" "utf8" "utils" "vctrs"],
218-
:Hash "15da5a8412f317beeee6175fbc76f4bb"},
219-
:generics
220-
{:Package "generics",
221-
:Version "0.1.3",
222-
:Source "Repository",
223-
:Repository "CRAN",
224-
:Requirements ["R" "methods"],
225-
:Hash "15e9634c0fcd294799e9b2e929ed1b86"},
226-
:cli
227-
{:Package "cli",
228-
:Version "3.6.3",
229-
:Source "Repository",
230-
:Repository "CRAN",
231-
:Requirements ["R" "utils"],
232-
:Hash "b21916dd77a27642b447374a5d30ecf3"},
233-
:R6
234-
{:Package "R6",
235-
:Version "2.5.1",
236-
:Source "Repository",
237-
:Repository "CRAN",
238-
:Requirements ["R"],
239-
:Hash "470851b6d5d0ac559e9d01bb352b4021"}
240-
:Rserve
241-
{:Package "Rserve",
242-
:Version "1.8-13",
243-
:Source "Repository",
244-
:Repository "CRAN",
245-
:Requirements ["R"],
246-
:Hash "589ebd25cffe93ab5ab61e66936d2678"}
247-
}}
248-
249-
250-
251-
252-
}
86+
}

python.edn

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
:python-version "3.10.16"
3+
:python-deps ["openai==1.58.1"
4+
"langextract"]
5+
:python-executable ".venv/Scripts/python"
6+
:pre-initialize-fn libpython-clj2.python.uv/sync-python-setup!
7+
8+
}

src/libpython_clj2/python.clj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,17 @@ user> (py/py. np linspace 2 3 :num 10)
114114
(catch java.io.FileNotFoundException _ "{}"))
115115
clojure.edn/read-string)
116116
_ (log/infof "Pre-initialize-fn %s" (some-> python-edn-opts :pre-initialize-fn))
117+
_ (def python-edn-opts python-edn-opts)
117118
_ (some-> python-edn-opts :pre-initialize-fn requiring-resolve (apply []))
119+
_ (some-> python-edn-opts :pre-initialize-fn)
120+
;_ ( (requiring-resolve 'libpython-clj2.python.uv/sync-python-setup))
121+
122+
;(require 'libpython-clj2.python.uv)
123+
124+
;(requiring-resolve )
125+
126+
;(-> 'libpython-clj2.python.uv/char-seq namespace symbol require)
127+
;(resolve 'libpython-clj2.python.uv/char-seq)
118128
options (merge python-edn-opts options)
119129
info (py-info/detect-startup-info options)
120130
_ (log/infof "Startup info %s" info)
@@ -820,3 +830,13 @@ user> c
820830
[symbols input]
821831
`(let [~symbols ~input]
822832
~@(for [s symbols] `(def ~s ~s))))
833+
834+
835+
(comment
836+
(require 'libpython-clj2.python)
837+
(require 'libpython-clj2.python.uv)
838+
839+
(libpython-clj2.python/initialize!)
840+
(libpython-clj2.python/run-simple-string "import sys; print(sys.path)")
841+
(libpython-clj2.python/import-module "openai")
842+
(libpython-clj2.python/import-module "langextract"))

src/libpython_clj2/python/uv.clj

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@
77

88
(defn write-pyproject-toml! [deps-edn]
99

10-
(let [
11-
12-
python-deps
13-
(:python-deps deps-edn)
14-
10+
(let [python-deps
11+
(:python-deps deps-edn)
12+
1513
;python-version (:python-version deps-edn)
16-
14+
1715
py-project-header-lines ["[project]"
1816
"name = \"temp\""
1917
"version = \"0.0\""
2018
;(format "requires-python = \"==%s\"" python-version)
21-
]
19+
]
2220
python-deps-lines
2321
(map
2422
(fn [dep]
@@ -28,18 +26,17 @@
2826
py-project-lines
2927
(concat
3028
py-project-header-lines
31-
[ "dependencies = ["]
29+
["dependencies = ["]
3230
python-deps-lines
33-
"]\n")
34-
]
31+
"]\n")]
3532

3633
(spit "pyproject.toml"
3734
(str/join "\n" py-project-lines))))
3835

3936
(defn char-seq
4037
[^java.io.Reader rdr]
4138
(let [chr (.read rdr)]
42-
(if (>= chr 0)
39+
(when (>= chr 0)
4340
(do
4441
;(def chr chr)
4542
(print (char (Integer. chr)))
@@ -48,12 +45,12 @@
4845

4946

5047
(defn start-and-print! [process-args]
51-
(let [args
52-
(concat [{:env { "RENV_CONFIG_INSTALL_VERBOSE" "TRUE"}}]
53-
process-args)
54-
p
48+
(let [args
49+
(concat [{:env {"RENV_CONFIG_INSTALL_VERBOSE" "TRUE"}}]
50+
process-args)
51+
p
5552
(apply process/start args)]
56-
53+
5754
(with-open [in-rdr (java.io.InputStreamReader. (.getInputStream p))
5855
err-rdr (java.io.InputStreamReader. (.getErrorStream p))]
5956

@@ -63,42 +60,14 @@
6360
(dorun (char-seq err-rdr)))))
6461

6562

66-
(defn setup-python! []
67-
(println "Synchronize python venv with uv sync. This might take a few minutes")
63+
(defn sync-python-setup! []
64+
(println "Synchronize python venv at .venv with 'uv sync'. This might take a few minutes")
6865
(let [deps-edn
6966
(->
70-
(slurp "deps.edn")
71-
edn/read-string)
72-
73-
]
67+
(slurp "python.edn")
68+
edn/read-string)]
7469
(write-pyproject-toml! deps-edn)
75-
(start-and-print! [ "unbuffer" "uv" "sync" "--python" (-> deps-edn :python-version)]))
76-
)
70+
(start-and-print! ["uv" "sync" "--python" (-> deps-edn :python-version)])))
71+
72+
7773

78-
(defn setup-r! []
79-
(let [renv-lock
80-
(->
81-
(slurp "deps.edn")
82-
edn/read-string
83-
:renv-deps
84-
(json/generate-string {:pretty true}))]
85-
(spit "renv.lock" renv-lock))
86-
87-
(start-and-print! ["rm" "-rf" "renv"])
88-
(start-and-print! ["rm" ".Rprofile"])
89-
(start-and-print! ["Rscript" "-e" "renv::init()"])
90-
(start-and-print! ["Rscript" "-e" "renv::restore()"]))
91-
92-
(defn setup! [& args]
93-
(setup-python!)
94-
;(setup-r!)
95-
)
96-
97-
(comment
98-
(require 'libpython-clj2.python)
99-
(require 'libpython-clj2.python.uv)
100-
(libpython-clj2.python.uv/setup!)
101-
(libpython-clj2.python/initialize! :python-executable ".venv/bin/python")
102-
(libpython-clj2.python/run-simple-string "import sys; print(sys.path)")
103-
(libpython-clj2.python/import-module "openai")
104-
)

0 commit comments

Comments
 (0)