Skip to content

Commit

Permalink
make python build work
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKaum committed Aug 19, 2024
1 parent 87ca97f commit 7ec7023
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 15 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,25 @@

## developing

- build only the outlines-core package `cd outlines-core && cargo build`
- dev build of python bindings `cd bindings/python && maturin develop`. If you have the conda `outlines-dev` environment activated, the outlines-core module is installed within the env automatically

There's also a [justfile](https://github.com/casey/just) for running these easier:

- `just dev-core`
- `just dev-python`

# Developer Notes

Setup a virtual environment
There's a [justfile](https://github.com/casey/just) for most dev & build tasks

- build only the outlines-core rust crate `cd outlines-core && cargo build`
- install an editable pip package with the recepie `just dev-python` which is:
```bash
uv venv
source .venv/bin/activate
cd bindings/python && pip install -e .
```

install the python bindings with

- to build the python package, run `just build-python`, which is equivalent to:
```bash
uv pip install bindings/python
cd bindings/python && \
ln -sf ../../outlines-core outlines-core-lib && \
sed -i '' 's|path = "../../outlines-core"|path = "outlines-core-lib"|' Cargo.toml && \
python -m build && \
rm outlines-core-lib && \
sed -i '' 's|path = "outlines-core-lib"|path = "../../outlines-core"|' Cargo.toml
```

# Testing
### Developer Notes

```bash
python -c "import outlines_core._lib;print(dir(outlines_core._lib))"
python -c "import outlines_core._lib;print(outlines_core._lib.show_me_the_flag())"
```
- Setup a virtual environment before running the build or dev commands

- If you get the `LookupError: setuptools-scm was unable to detect version for...` error, set the env var `SETUPTOOLS_SCM_PRETEND_VERSION=0.1.0-dev` before running the build or dev command.
2 changes: 1 addition & 1 deletion bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ name = "_lib"
crate-type = ["cdylib"]
path = "rust/lib.rs"

[dependencies.outlines-core-rs]
[dependencies.outlines-core]
path = "../../outlines-core"
8 changes: 4 additions & 4 deletions bindings/python/Manifest.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
graft python
graft src
graft rust
graft tests
include Cargo.toml

global-exclude */__pycache__/*
global-exclude *.pyc

recursive-include rust *
recursive-include outlines-core *
recursive-include outlines-core-lib *
recursive-exclude outlines-core/target *
8 changes: 6 additions & 2 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2", "setuptools-rust"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -67,6 +67,10 @@ repository = "https://github.com/outlines-dev/outlines-core/"
file = "README.md"
content-type = "text/markdown"

[tool.setuptools]
packages = ["outlines_core"]
package-dir = {"" = "src"}

[tool.setuptools.package-data]
"outlines" = ["py.typed"]

Expand All @@ -86,7 +90,7 @@ filterwarnings = [
]

[tool.mypy]
exclude = ["examples"]
exclude=["examples"]
enable_incomplete_feature = ["Unpack"]

[[tool.mypy.overrides]]
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pyo3::{pyfunction, pymodule, wrap_pyfunction, Bound, PyResult};

#[pymodule]
mod _lib {
use outlines_core_rs::FLAG;
use outlines_core::FLAG;
use pyo3::prelude::*;

/// Formats the sum of two numbers as string.
Expand Down
8 changes: 7 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ dev-python:
cd bindings/python && pip install -e .

build-python:
cd bindings/python && python -m build
cd bindings/python && \
ln -sf ../../outlines-core outlines-core-lib && \
sed -i '' 's|path = "../../outlines-core"|path = "outlines-core-lib"|' Cargo.toml && \
python -m build && \
rm outlines-core-lib && \
sed -i '' 's|path = "outlines-core-lib"|path = "../../outlines-core"|' Cargo.toml

0 comments on commit 7ec7023

Please sign in to comment.