Skip to content

Commit 369db5f

Browse files
committed
Make ontoenv-python CLI optional and fix release workflow
- gate the Rust CLI import behind an optional `cli` feature and provide a stub when it’s disabled - build all wheels with `abi3` + `cli` while letting `cargo publish` verify without the CLI dependency - add `.github/scripts/wait_for_crates.sh` and call it from `publish_crates` - rename upload artifacts so binaries use `ontoenv_*` and Python wheels use `pyontoenv_*`
1 parent 0467c55 commit 369db5f

File tree

6 files changed

+32
-17
lines changed

6 files changed

+32
-17
lines changed

.github/workflows/artifacts.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
cache: pip
132132
cache-dependency-path: '**/requirements.dev.txt'
133133
- run: pip install -r python/requirements.dev.txt
134-
- run: maturin build -m python/Cargo.toml
134+
- run: maturin build -m python/Cargo.toml --features "cli"
135135
- run: pip install --no-index --find-links=target/wheels/ ontoenv
136136
- run: rm -r target/wheels
137137
- run: maturin sdist -m python/Cargo.toml
@@ -243,16 +243,16 @@ jobs:
243243
cache: pip
244244
cache-dependency-path: '**/requirements.dev.txt'
245245
- run: pip install -r python/requirements.dev.txt
246-
- run: maturin build --release --features abi3
246+
- run: maturin build --release --features "abi3 cli"
247247
working-directory: ./python
248248
- run: pip install --no-index --find-links=target/wheels/ ontoenv
249249
- run: rm -r target/wheels
250-
- run: maturin build --release --target universal2-apple-darwin --features abi3
250+
- run: maturin build --release --target universal2-apple-darwin --features "abi3 cli"
251251
working-directory: ./python
252-
- run: maturin build --release --target x86_64-apple-darwin --features abi3
252+
- run: maturin build --release --target x86_64-apple-darwin --features "abi3 cli"
253253
working-directory: ./python
254254
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.run_full_matrix == 'true')
255-
- run: maturin build --release --target aarch64-apple-darwin --features abi3
255+
- run: maturin build --release --target aarch64-apple-darwin --features "abi3 cli"
256256
working-directory: ./python
257257
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.run_full_matrix == 'true')
258258
- uses: actions/upload-artifact@v4
@@ -276,11 +276,11 @@ jobs:
276276
cache-dependency-path: '**/requirements.dev.txt'
277277
- run: Remove-Item -LiteralPath "C:\msys64\" -Force -Recurse
278278
- run: pip install -r python/requirements.dev.txt
279-
- run: maturin build --release --features abi3
279+
- run: maturin build --release --features "abi3 cli"
280280
working-directory: ./python
281281
- run: pip install --no-index --find-links=target/wheels/ ontoenv
282282
- run: rm -r target/wheels
283-
- run: maturin build --release -m python/Cargo.toml --features abi3
283+
- run: maturin build --release -m python/Cargo.toml --features "abi3 cli"
284284
- uses: actions/upload-artifact@v4
285285
with:
286286
name: pyontoenv_windows_${{ github.run_attempt }}

.github/workflows/manylinux_build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ cd python
2020
python3.12 -m venv venv
2121
source venv/bin/activate
2222
pip install -r requirements.dev.txt
23-
maturin develop --release
24-
maturin build --release --features abi3 --compatibility manylinux_2_28
23+
maturin develop --release --features "abi3 cli"
24+
maturin build --release --features "abi3 cli" --compatibility manylinux_2_28
2525
if [ %for_each_version% ]; then
2626
for VERSION in 8 9 10 11 12; do
27-
maturin build --release --interpreter "python3.$VERSION" --compatibility manylinux_2_28
27+
maturin build --release --features "abi3 cli" --interpreter "python3.$VERSION" --compatibility manylinux_2_28
2828
done
2929
for VERSION in 9 10; do
30-
maturin build --release --interpreter "pypy3.$VERSION" --compatibility manylinux_2_28
30+
maturin build --release --features "abi3 cli" --interpreter "pypy3.$VERSION" --compatibility manylinux_2_28
3131
done
3232
fi

.github/workflows/musllinux_build.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ cd python
99
python3.12 -m venv venv
1010
source venv/bin/activate
1111
pip install -r requirements.dev.txt
12-
maturin develop --release
13-
maturin build --release --features abi3 --compatibility musllinux_1_2
12+
maturin develop --release --features "abi3 cli"
13+
maturin build --release --features "abi3 cli" --compatibility musllinux_1_2
1414
if [ %for_each_version% ]; then
1515
for VERSION in 8 9 10 11 12; do
16-
maturin build --release --interpreter "python3.$VERSION" --compatibility musllinux_1_2
16+
maturin build --release --features "abi3 cli" --interpreter "python3.$VERSION" --compatibility musllinux_1_2
1717
done
1818
fi
19-

python/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ doc = false
1818
[dependencies]
1919
pyo3 = { version = "0.25", features = ["extension-module"] }
2020
ontoenv.workspace = true
21-
ontoenv-cli.workspace = true
21+
ontoenv-cli = { workspace = true, optional = true }
2222
anyhow.workspace = true
2323
oxigraph.workspace = true
2424
env_logger.workspace = true
@@ -28,4 +28,6 @@ log.workspace = true
2828
pyo3-build-config = "0.25"
2929

3030
[features]
31+
default = []
3132
abi3 = ["pyo3/abi3-py39"]
33+
cli = ["ontoenv-cli"]

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ license = "bsd-3-clause"
1717
ontoenv = "ontoenv._cli:main"
1818

1919
[tool.maturin]
20-
features = ["pyo3/extension-module"]
20+
features = ["pyo3/extension-module", "cli"]
2121
# This tells maturin to put the compiled native module
2222
# INSIDE the 'ontoenv' package directory.
2323
module-name = "ontoenv._native"

python/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ use ::ontoenv::options::{CacheMode, Overwrite, RefreshStrategy};
66
use ::ontoenv::transform;
77
use ::ontoenv::ToUriString;
88
use anyhow::Error;
9+
#[cfg(feature = "cli")]
910
use ontoenv_cli;
1011
use oxigraph::model::{BlankNode, Literal, NamedNode, NamedOrBlankNodeRef, Term};
1112
use pyo3::{
1213
prelude::*,
1314
types::{IntoPyDict, PyString, PyTuple},
1415
exceptions::PyValueError,
1516
};
17+
#[cfg(not(feature = "cli"))]
18+
use pyo3::exceptions::PyRuntimeError;
1619
use std::borrow::Borrow;
1720
use std::collections::{HashMap, HashSet};
1821
use std::path::PathBuf;
@@ -122,6 +125,7 @@ fn term_to_python<'a>(
122125

123126
/// Run the Rust CLI implementation and return its process-style exit code.
124127
#[pyfunction]
128+
#[cfg(feature = "cli")]
125129
fn run_cli(py: Python<'_>, args: Option<Vec<String>>) -> PyResult<i32> {
126130
let argv = args.unwrap_or_else(|| std::env::args().collect());
127131
let code = py.allow_threads(move || match ontoenv_cli::run_from_args(argv) {
@@ -134,6 +138,16 @@ fn run_cli(py: Python<'_>, args: Option<Vec<String>>) -> PyResult<i32> {
134138
Ok(code)
135139
}
136140

141+
/// Fallback stub when the CLI feature is disabled at compile time.
142+
#[pyfunction]
143+
#[cfg(not(feature = "cli"))]
144+
#[allow(unused_variables)]
145+
fn run_cli(_py: Python<'_>, _args: Option<Vec<String>>) -> PyResult<i32> {
146+
Err(PyErr::new::<PyRuntimeError, _>(
147+
"ontoenv was built without CLI support; rebuild with the 'cli' feature",
148+
))
149+
}
150+
137151
#[pyclass(name = "Ontology")]
138152
#[derive(Clone)]
139153
struct PyOntology {

0 commit comments

Comments
 (0)