Skip to content

Commit b5cda32

Browse files
authored
Python feature flags (#337)
* Python feature flags * fixup! Python feature flags
1 parent d8b2e66 commit b5cda32

2 files changed

Lines changed: 54 additions & 21 deletions

File tree

python/Cargo.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ doc = false
1515

1616
[dependencies]
1717
arrow = { workspace = true }
18-
arrow-flight = {workspace = true}
18+
arrow-flight = {workspace = true, optional = true}
1919
datafusion = { workspace = true, features = ["pyarrow"] }
2020
datafusion-ffi = { workspace = true }
21-
datafusion-table-providers = { workspace = true, features = ["sqlite", "duckdb", "odbc", "mysql", "postgres", "flight"] }
21+
datafusion-table-providers = { workspace = true }
2222
pyo3 = { version = "0.23" }
2323
tokio = { version = "1.44", features = ["macros", "rt", "rt-multi-thread", "sync"] }
24-
duckdb = { workspace = true }
24+
duckdb = { workspace = true, optional = true}
25+
26+
[features]
27+
default = ["duckdb", "sqlite", "mysql", "postgres", "odbc", "flight"]
28+
duckdb = ["dep:duckdb", "datafusion-table-providers/duckdb-federation"]
29+
sqlite = ["datafusion-table-providers/sqlite-federation"]
30+
mysql = ["datafusion-table-providers/mysql-federation"]
31+
postgres = ["datafusion-table-providers/postgres-federation"]
32+
odbc = ["datafusion-table-providers/odbc-federation"]
33+
flight = ["dep:arrow-flight", "datafusion-table-providers/flight"]

python/src/lib.rs

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ impl RawTableProvider {
2828
}
2929
}
3030

31+
#[cfg(feature = "duckdb")]
3132
pub mod duckdb;
33+
#[cfg(feature = "flight")]
3234
pub mod flight;
35+
#[cfg(feature = "mysql")]
3336
pub mod mysql;
37+
#[cfg(feature = "odbc")]
3438
pub mod odbc;
39+
#[cfg(feature = "postgres")]
3540
pub mod postgres;
41+
#[cfg(feature = "sqlite")]
3642
pub mod sqlite;
3743
pub mod utils;
3844

@@ -41,29 +47,47 @@ pub mod utils;
4147
fn _internal(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
4248
m.add_class::<RawTableProvider>()?;
4349

44-
let sqlite = PyModule::new(py, "sqlite")?;
45-
sqlite::init_module(&sqlite)?;
46-
m.add_submodule(&sqlite)?;
50+
#[cfg(feature = "sqlite")]
51+
{
52+
let sqlite = PyModule::new(py, "sqlite")?;
53+
sqlite::init_module(&sqlite)?;
54+
m.add_submodule(&sqlite)?;
55+
}
4756

48-
let duckdb = PyModule::new(py, "duckdb")?;
49-
duckdb::init_module(&duckdb)?;
50-
m.add_submodule(&duckdb)?;
57+
#[cfg(feature = "duckdb")]
58+
{
59+
let duckdb = PyModule::new(py, "duckdb")?;
60+
duckdb::init_module(&duckdb)?;
61+
m.add_submodule(&duckdb)?;
62+
}
5163

52-
let odbc = PyModule::new(py, "odbc")?;
53-
odbc::init_module(&odbc)?;
54-
m.add_submodule(&odbc)?;
64+
#[cfg(feature = "odbc")]
65+
{
66+
let odbc = PyModule::new(py, "odbc")?;
67+
odbc::init_module(&odbc)?;
68+
m.add_submodule(&odbc)?;
69+
}
5570

56-
let mysql = PyModule::new(py, "mysql")?;
57-
mysql::init_module(&mysql)?;
58-
m.add_submodule(&mysql)?;
71+
#[cfg(feature = "mysql")]
72+
{
73+
let mysql = PyModule::new(py, "mysql")?;
74+
mysql::init_module(&mysql)?;
75+
m.add_submodule(&mysql)?;
76+
}
5977

60-
let postgres = PyModule::new(py, "postgres")?;
61-
postgres::init_module(&postgres)?;
62-
m.add_submodule(&postgres)?;
78+
#[cfg(feature = "postgres")]
79+
{
80+
let postgres = PyModule::new(py, "postgres")?;
81+
postgres::init_module(&postgres)?;
82+
m.add_submodule(&postgres)?;
83+
}
6384

64-
let flight = PyModule::new(py, "flight")?;
65-
flight::init_module(&flight)?;
66-
m.add_submodule(&flight)?;
85+
#[cfg(feature = "flight")]
86+
{
87+
let flight = PyModule::new(py, "flight")?;
88+
flight::init_module(&flight)?;
89+
m.add_submodule(&flight)?;
90+
}
6791

6892
Ok(())
6993
}

0 commit comments

Comments
 (0)