Skip to content

Commit cda49b2

Browse files
committed
Update docs
1 parent 97cd756 commit cda49b2

7 files changed

Lines changed: 37 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ $ dune exec ./run.exe
6363

6464
For information on installing and using `pyml_bindgen`, check out the [docs](https://mooreryan.github.io/ocaml_python_bindgen/).
6565

66+
Additionally, you can find examples in the [examples](https://github.com/mooreryan/ocaml_python_bindgen/tree/main/examples) directory. One neat thing about these examples is that you can see how to write Dune [rules](https://dune.readthedocs.io/en/stable/dune-files.html#rule) to automatically generate your `pyml` bindings.
67+
6668
## License
6769

6870
[![license MIT or Apache

_docs_src/mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ nav:
1414
- Handling Dictionaries 2: dictionaries-2.md
1515
- Recursive Classes: recursive.md
1616
- Rules:
17+
- Overview: rules-overview.md
1718
- Types: types.md
1819
- Function & Argument Names: names.md
1920
- Attributes & Properties: attributes.md
2021
- Instance Methods: instance-methods.md
2122
- Class & Static Methods; Functions: static-methods.md
2223
- Miscellaneous:
24+
- Auto-generating bindings: auto-gen-bindings.md
2325
- CLI Options: cli-options.md
2426
- Converting `pyobjects` to OCaml types: of-pyobject.md
2527
- Handling Tuples: tuples.md

_docs_src/src/auto-gen-bindings.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Automatically Generating Bindings
2+
3+
Sometimes it can be a bit of a pain to always have to run `pyml_bindgen` by hand.
4+
5+
One way to avoid this is by adding a [rule](https://dune.readthedocs.io/en/stable/dune-files.html#rule) to your Dune file.
6+
7+
For an example of this, check out the `dune` file in the [quick start](https://github.com/mooreryan/ocaml_python_bindgen/tree/main/examples/quick_start) example on GitHub. It has lots of comments to show you how it is working.

_docs_src/src/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ $ pyml_bindgen --help
4747

4848
## Quick start
4949

50+
*Note: You can find full examples in the [examples](https://github.com/mooreryan/ocaml_python_bindgen/tree/main/examples) directory on GitHub. One neat thing about the examples there is that you can see how to write Dune [rules](https://dune.readthedocs.io/en/stable/dune-files.html#rule) to automatically generate your `pyml` bindings.*
51+
5052
`pyml_bindgen` is a CLI program that generates OCaml modules that bind Python classes via [pyml](https://github.com/thierry-martinez/pyml).
5153

5254
Here's a small example. Take a Python class, `Thing`. (Put it in a file called `thing.py`...this means the Python module will be called `thing`.)

_docs_src/src/rules-overview.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Rules Overview
2+
3+
The following pages are an informal description of some of the rules you have to follow when using `pyml_bindgen`.
4+
5+
I will try and keep them updated and (reasonably) complete. However, if you really want to know how something is working, you may want to have a look at the [tests](https://github.com/mooreryan/ocaml_python_bindgen/tree/main/test).

examples/quick_start/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is a simple example where all files including the Python module that we want to bind are in a single directory.
44

5-
For more details about this example, see the [Quick Start](https://github.com/mooreryan/ocaml_python_bindgen#quick-start).
5+
For more details about this example, see the [Quick Start](https://github.com/mooreryan/ocaml_python_bindgen#quick-start). There you will see an explanation of how to run `pyml_bindgen` to generate the bindings you see here.
66

77
## Files
88

@@ -16,12 +16,11 @@ For more details about this example, see the [Quick Start](https://github.com/mo
1616

1717
`lib.ml` is the file of `pyml` bindings generated by `pyml_bindgen`.
1818

19-
The `dune` file has a rule to automatically generate this file for you when you run `dune build` in the root of the repository.
19+
The `dune` file has a rule to automatically generate this file for you when you run `dune build` in the root of the repository. Check out the `dune` file to see how to do this...it has lots of comments in there!
2020

2121
However, if you wanted to make this file manually, you could do so like this:
2222

2323
```
2424
$ pyml_bindgen val_specs.txt adder Adder --caml-module Adder | \
2525
ocamlformat --name lib.ml -
2626
```
27-

examples/quick_start/dune

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,27 @@
33
(libraries pyml))
44

55
(rule
6+
;; The file produced by this rule will be called `lib.ml`.
7+
(target lib.ml)
8+
;; Put the resulting lib.ml file in this directory. When you run
9+
;; `dune clean`, it will be removed.
610
(mode
711
(promote (until-clean)))
8-
(target lib.ml)
912
(action
13+
;; `pyml_bindgen` outputs directly to stdout, so we need to redirect
14+
;; the stdout to `lib.ml`. We do this using `with-stdout-to`.
1015
(with-stdout-to
16+
;; This is the name of the file to which the output of the
17+
;; following command will be directed.
1118
lib.ml
19+
;; This step isn't necessary, but I use `ocamlformat` for
20+
;; everything, so I would like to have the output of
21+
;; `pyml_bindgen` also processed by `ocamlformat`. `pipe-stdout`
22+
;; takes the stdout of the first `run` command and pipes it to the
23+
;; stdin of the second `run` command.
1224
(pipe-stdout
25+
;; Here is the acutal `pyml_bindgen` command to generate the
26+
;; bindings.
1327
(run %{bin:pyml_bindgen} val_specs.txt adder Adder --caml-module Adder)
14-
(run ocamlformat --name lib.ml --enable-outside-detected-project -)))))
28+
;; And finally, process the bindings code with ocamlformat.
29+
(run ocamlformat --name lib.ml -)))))

0 commit comments

Comments
 (0)