Skip to content

Commit 00b0e7a

Browse files
author
Christopher Doris
committed
document writing packages
1 parent 2e5ea05 commit 00b0e7a

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

docs/src/pythoncall.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ at least `python` and `pip`, and is activated.
237237
If your project requires more Python dependencies, use the mechanisms below to ensure they
238238
are automatically installed.
239239

240+
We **strongly recommend that you specify Conda dependencies** if possible, instead of pip
241+
or script dependencies. This is because Conda can account for all inter-dependencies between
242+
packages and so prevent incompatible combinations of packages from being installed.
243+
240244
### PythonCallDeps.toml
241245

242246
If you put a file called `PythonCallDeps.toml` in a project/package/environment which
@@ -275,6 +279,40 @@ PythonCall.Deps.conda_env
275279
PythonCall.Deps.user_deps_file
276280
```
277281

282+
## Writing packages which depend on *PythonCall*
283+
284+
### Example
285+
286+
See https://github.com/cjdoris/FAISS.jl for an example package which wraps the Python FAISS
287+
package.
288+
289+
### Precompilation
290+
291+
You may not interact with Python during module precompilation. Therefore, instead of
292+
```
293+
module MyModule
294+
using PythonCall
295+
const foo = pyimport("foo")
296+
bar() = foo.bar() # will crash when called
297+
end
298+
```
299+
you must do
300+
```
301+
module MyModule
302+
using PythonCall
303+
const foo = PythonCall.pynew() # initially NULL
304+
function __init__()
305+
PythonCall.pycopy!(foo, pyimport("foo"))
306+
end
307+
bar() = foo.bar() # now ok
308+
end
309+
```
310+
311+
### Dependencies
312+
313+
If your package depends on some Python packages, you must write a `PythonCallDeps.toml` file.
314+
See [Managing Python dependencies](@ref).
315+
278316
## Low-level API
279317

280318
The functions here are not exported. They are mostly unsafe in the sense that you can
@@ -283,8 +321,8 @@ crash Julia by using them incorrectly.
283321
```@docs
284322
PythonCall.pynew
285323
PythonCall.pyisnull
286-
PythonCall.getptr
287324
PythonCall.pycopy!
325+
PythonCall.getptr
288326
PythonCall.pydel!
289327
PythonCall.unsafe_pynext
290328
```

0 commit comments

Comments
 (0)