diff --git a/Cargo.lock b/Cargo.lock index 9fdad03a..86f60309 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,7 +133,7 @@ dependencies = [ name = "python-bindings" version = "0.1.0" dependencies = [ - "outlines-core-rs", + "outlines-core", "pyo3", ] diff --git a/README.md b/README.md index 4141d637..df4d1a7e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index 1c936ccf..a97f9dda 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -14,5 +14,5 @@ name = "_lib" crate-type = ["cdylib"] path = "rust/lib.rs" -[dependencies.outlines-core-rs] +[dependencies.outlines-core] path = "../../outlines-core" diff --git a/bindings/python/Manifest.in b/bindings/python/Manifest.in index a4111c30..8b5bea03 100644 --- a/bindings/python/Manifest.in +++ b/bindings/python/Manifest.in @@ -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 * \ No newline at end of file diff --git a/bindings/python/pyproject.toml b/bindings/python/pyproject.toml index e2eb6fca..356cb06f 100644 --- a/bindings/python/pyproject.toml +++ b/bindings/python/pyproject.toml @@ -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] @@ -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"] @@ -86,7 +90,7 @@ filterwarnings = [ ] [tool.mypy] -exclude = ["examples"] +exclude=["examples"] enable_incomplete_feature = ["Unpack"] [[tool.mypy.overrides]] diff --git a/bindings/python/rust/lib.rs b/bindings/python/rust/lib.rs index cba0a30f..b1bfb828 100644 --- a/bindings/python/rust/lib.rs +++ b/bindings/python/rust/lib.rs @@ -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. diff --git a/justfile b/justfile index 491a1066..21f1be7a 100644 --- a/justfile +++ b/justfile @@ -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 +