This is an automated email from the ASF dual-hosted git repository.

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 15cc86a107 fix(dev): derive python generated services from cargo 
metadata (#8561)
15cc86a107 is described below

commit 15cc86a107a5456fa96ff20301d0865f003c0896
Author: Trim21 <[email protected]>
AuthorDate: Sun Nov 22 04:38:30 2026 +0800

    fix(dev): derive python generated services from cargo metadata (#8561)
    
    * fix(dev): derive python generated services from cargo metadata
    
    The generator kept a hand-maintained exclusion list that duplicated the
    service features declared in bindings/python/Cargo.toml. Resolve the
    `services-platform-*` wheel feature sets through `cargo metadata` and
    union the services they enable, so the manifest is the single source of
    truth for the generated scheme and config surface.
    
    The release workflow now selects one `services-platform-*` set per wheel
    target instead of spelling out the features inline, and the regenerated
    files drop cloudflare-kv and vercel-blob, which no wheel enables.
    
    * chore(bindings/python): format the platform feature sets with taplo
    
    * fix(dev): derive the python service set from the opendal crate features
    
    Parse the `services-platform-*` names from bindings/python/Cargo.toml and
    read the resolved `services-*` features of the `opendal` facade crate
    instead of the binding's own feature namespace, so aggregate feature sets
    need no special-case filtering.
---
 .github/workflows/release_python.yml        |  18 ++--
 bindings/python/Cargo.toml                  |  14 ++-
 bindings/python/README.md                   |  21 +++--
 bindings/python/python/opendal/config.py    |  32 -------
 bindings/python/python/opendal/services.pyi |   2 -
 bindings/python/src/services.rs             |   8 --
 dev/src/generate/parser.rs                  |   2 +-
 dev/src/generate/python.rs                  | 139 ++++++++++++++++++++++++++--
 scripts/constants.py                        |   9 +-
 9 files changed, 170 insertions(+), 75 deletions(-)

diff --git a/.github/workflows/release_python.yml 
b/.github/workflows/release_python.yml
index 1110c5c419..0aee0ee9c1 100644
--- a/.github/workflows/release_python.yml
+++ b/.github/workflows/release_python.yml
@@ -64,37 +64,37 @@ jobs:
       matrix:
         include:
           - os: windows-latest
-            services: services-all,services-foyer
+            services: services-platform-windows
           - os: macos-15-intel
             target: x86_64-apple-darwin
-            services: services-all,services-foyer,services-sftp
+            services: services-platform-macos
           - os: macos-15
             target: aarch64-apple-darwin
-            services: services-all,services-foyer,services-sftp
+            services: services-platform-macos
           - os: ubuntu-latest
             target: x86_64
-            services: services-all,services-foyer,services-sftp
+            services: services-platform-linux
           - os: ubuntu-latest
             target: aarch64
             manylinux: manylinux_2_28
-            services: services-all,services-foyer,services-sftp
+            services: services-platform-linux
           - os: ubuntu-latest
             target: x86_64-unknown-linux-musl
             manylinux: musllinux_1_1
-            services: services-all,services-foyer,services-sftp
+            services: services-platform-linux
           - os: ubuntu-latest
             target: aarch64-unknown-linux-musl
             manylinux: musllinux_1_1
-            services: services-all,services-foyer,services-sftp
+            services: services-platform-linux
           # ARMv7 lacks prebuilt io-uring bindings and cannot build SFTP's
           # OpenSSH dependency chain at the supported Rust version.
           - os: ubuntu-latest
             target: armv7l
-            services: services-all
+            services: services-platform-linux-armv7
           - os: ubuntu-latest
             target: armv7-unknown-linux-musleabihf
             manylinux: musllinux_1_1
-            services: services-all
+            services: services-platform-linux-armv7
     steps:
       - uses: actions/checkout@v7
       - name: Prepare release candidate version
diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml
index 6924a94412..342cfc6582 100644
--- a/bindings/python/Cargo.toml
+++ b/bindings/python/Cargo.toml
@@ -47,8 +47,8 @@ default = [
   "services-webhdfs",
 ]
 
-# Common service set for all PyPI wheels. The release matrix adds 
platform-specific features.
-# Keep the generated service list in dev/src/generate/python.rs in sync.
+# Common service set for all PyPI wheels. Every wheel also enables one of the
+# `services-platform-*` feature sets below.
 services-all = [
   'default',
   'services-aliyun-drive',
@@ -86,6 +86,16 @@ services-all = [
   'services-yandex-disk',
 ]
 
+# Service sets of the PyPI wheel platforms. The release workflow enables 
exactly
+# one of these per wheel, see .github/workflows/release_python.yml.
+# dev/src/generate/python.rs unions all of them via `cargo metadata` to derive
+# the generated service list, so it does not need to know which platform a
+# wheel is built for.
+services-platform-linux = ['services-all', 'services-foyer', 'services-sftp']
+services-platform-linux-armv7 = ['services-all']
+services-platform-macos = ['services-all', 'services-foyer', 'services-sftp']
+services-platform-windows = ['services-all', 'services-foyer']
+
 # List of feature-flags for all services provided by opendal.
 services-aliyun-drive = ["opendal/services-aliyun-drive"]
 services-alluxio = ["opendal/services-alluxio"]
diff --git a/bindings/python/README.md b/bindings/python/README.md
index ee5f778c46..cafdc98718 100644
--- a/bindings/python/README.md
+++ b/bindings/python/README.md
@@ -49,18 +49,19 @@ conda install conda-forge::opendal
 ## Services in PyPI wheels
 
 Official PyPI wheels ship the largest verified service set for each target.
-Every wheel enables the common `services-all` group in the binding's
+Every wheel enables the common `services-all` group plus one of the
+`services-platform-*` sets in the binding's
 
[Cargo.toml](https://github.com/apache/opendal/blob/main/bindings/python/Cargo.toml).
 The [release 
workflow](https://github.com/apache/opendal/blob/main/.github/workflows/release_python.yml)
-builds the following additional services for both standard and free-threaded 
CPython.
-
-| Wheel platform | Architecture | Additional services |
-| --- | --- | --- |
-| Linux (manylinux) | x86_64, aarch64 | Foyer, SFTP |
-| Linux (musllinux) | x86_64, aarch64 | Foyer, SFTP |
-| Linux (manylinux and musllinux) | ARMv7 (32-bit) | None |
-| macOS | x86_64, arm64 | Foyer, SFTP |
-| Windows | x86_64 | Foyer |
+selects the set for each target and builds both standard and free-threaded 
CPython.
+
+| Wheel platform | Architecture | Feature set | Additional services |
+| --- | --- | --- | --- |
+| Linux (manylinux) | x86_64, aarch64 | `services-platform-linux` | Foyer, 
SFTP |
+| Linux (musllinux) | x86_64, aarch64 | `services-platform-linux` | Foyer, 
SFTP |
+| Linux (manylinux and musllinux) | ARMv7 (32-bit) | 
`services-platform-linux-armv7` | None |
+| macOS | x86_64, arm64 | `services-platform-macos` | Foyer, SFTP |
+| Windows | x86_64 | `services-platform-windows` | Foyer |
 
 Foyer's Linux dependency `io-uring` lacks prebuilt ARMv7 bindings. SFTP
 requires the OpenSSH `ssh` executable at runtime. Its Rust dependency chain
diff --git a/bindings/python/python/opendal/config.py 
b/bindings/python/python/opendal/config.py
index dc8f0ced14..2afbd40a38 100644
--- a/bindings/python/python/opendal/config.py
+++ b/bindings/python/python/opendal/config.py
@@ -184,23 +184,6 @@ class CacacheConfig(TypedDict):
     """That path to the cacache data directory."""
 
 
-class CloudflareKvConfig(TypedDict):
-    """Configuration for the `cloudflare-kv` service."""
-
-    scheme: Required[Literal["cloudflare-kv"]]
-    """The service scheme; fixed to `"cloudflare-kv"`."""
-    account_id: NotRequired[str]
-    """The account ID used to authenticate with CloudFlare. Used as URI path 
parameter."""
-    api_token: NotRequired[str]
-    """The token used to authenticate with CloudFlare."""
-    default_ttl: NotRequired[str | timedelta]
-    """The default ttl for write operations. A datetime.timedelta or human 
readable duration string, e.g. "5s" (see 
https://docs.rs/humantime/latest/humantime/fn.parse_duration.html)."""
-    namespace_id: NotRequired[str]
-    """The namespace ID. Used as URI path parameter."""
-    root: NotRequired[str | os.PathLike[str]]
-    """Root within this backend."""
-
-
 class CosConfig(TypedDict):
     """Configuration for the `cos` service."""
 
@@ -1007,17 +990,6 @@ class VercelArtifactsConfig(TypedDict):
     """The Vercel team slug. When set, the `slug` query parameter is appended 
to all API requests."""
 
 
-class VercelBlobConfig(TypedDict):
-    """Configuration for the `vercel-blob` service."""
-
-    scheme: Required[Literal["vercel-blob"]]
-    """The service scheme; fixed to `"vercel-blob"`."""
-    root: NotRequired[str | os.PathLike[str]]
-    """root of this backend.  All operations will happen under this root."""
-    token: NotRequired[str]
-    """vercel blob token."""
-
-
 class WebdavConfig(TypedDict):
     """Configuration for the `webdav` service."""
 
@@ -1085,7 +1057,6 @@ ServiceConfig = (
     | AzfileConfig
     | B2Config
     | CacacheConfig
-    | CloudflareKvConfig
     | CosConfig
     | DashmapConfig
     | DropboxConfig
@@ -1126,7 +1097,6 @@ ServiceConfig = (
     | TosConfig
     | UpyunConfig
     | VercelArtifactsConfig
-    | VercelBlobConfig
     | WebdavConfig
     | WebhdfsConfig
     | YandexDiskConfig
@@ -1142,7 +1112,6 @@ __all__ = [
     "AzfileConfig",
     "B2Config",
     "CacacheConfig",
-    "CloudflareKvConfig",
     "CosConfig",
     "DashmapConfig",
     "DropboxConfig",
@@ -1183,7 +1152,6 @@ __all__ = [
     "TosConfig",
     "UpyunConfig",
     "VercelArtifactsConfig",
-    "VercelBlobConfig",
     "WebdavConfig",
     "WebhdfsConfig",
     "YandexDiskConfig",
diff --git a/bindings/python/python/opendal/services.pyi 
b/bindings/python/python/opendal/services.pyi
index b1df245f0d..d038c0ffbd 100644
--- a/bindings/python/python/opendal/services.pyi
+++ b/bindings/python/python/opendal/services.pyi
@@ -26,7 +26,6 @@ class Scheme:
     Azfile: Final[Scheme]
     B2: Final[Scheme]
     Cacache: Final[Scheme]
-    CloudflareKv: Final[Scheme]
     Cos: Final[Scheme]
     Dashmap: Final[Scheme]
     Dropbox: Final[Scheme]
@@ -67,7 +66,6 @@ class Scheme:
     Tos: Final[Scheme]
     Upyun: Final[Scheme]
     VercelArtifacts: Final[Scheme]
-    VercelBlob: Final[Scheme]
     Webdav: Final[Scheme]
     Webhdfs: Final[Scheme]
     YandexDisk: Final[Scheme]
diff --git a/bindings/python/src/services.rs b/bindings/python/src/services.rs
index 7ff60f2a73..c9b87344dd 100644
--- a/bindings/python/src/services.rs
+++ b/bindings/python/src/services.rs
@@ -43,8 +43,6 @@ pub enum Scheme {
     B2,
     #[cfg(feature = "services-cacache")]
     Cacache,
-    #[cfg(feature = "services-cloudflare-kv")]
-    CloudflareKv,
     #[cfg(feature = "services-cos")]
     Cos,
     #[cfg(feature = "services-dashmap")]
@@ -125,8 +123,6 @@ pub enum Scheme {
     Upyun,
     #[cfg(feature = "services-vercel-artifacts")]
     VercelArtifacts,
-    #[cfg(feature = "services-vercel-blob")]
-    VercelBlob,
     #[cfg(feature = "services-webdav")]
     Webdav,
     #[cfg(feature = "services-webhdfs")]
@@ -189,8 +185,6 @@ impl_enum_to_str!(
         B2 => "b2",
         #[cfg(feature = "services-cacache")]
         Cacache => "cacache",
-        #[cfg(feature = "services-cloudflare-kv")]
-        CloudflareKv => "cloudflare-kv",
         #[cfg(feature = "services-cos")]
         Cos => "cos",
         #[cfg(feature = "services-dashmap")]
@@ -271,8 +265,6 @@ impl_enum_to_str!(
         Upyun => "upyun",
         #[cfg(feature = "services-vercel-artifacts")]
         VercelArtifacts => "vercel-artifacts",
-        #[cfg(feature = "services-vercel-blob")]
-        VercelBlob => "vercel-blob",
         #[cfg(feature = "services-webdav")]
         Webdav => "webdav",
         #[cfg(feature = "services-webhdfs")]
diff --git a/dev/src/generate/parser.rs b/dev/src/generate/parser.rs
index df200daaa0..3c7d097571 100644
--- a/dev/src/generate/parser.rs
+++ b/dev/src/generate/parser.rs
@@ -29,7 +29,7 @@ use syn::{
 
 pub type Services = HashMap<String, Service>;
 
-pub fn sorted_services(services: Services, test: fn(&str) -> bool) -> Services 
{
+pub fn sorted_services(services: Services, test: impl Fn(&str) -> bool) -> 
Services {
     let mut srvs = Services::new();
     for (k, srv) in services.into_iter() {
         if !test(k.as_str()) {
diff --git a/dev/src/generate/python.rs b/dev/src/generate/python.rs
index 2011dfda4c..ca60b1c7e2 100644
--- a/dev/src/generate/python.rs
+++ b/dev/src/generate/python.rs
@@ -17,25 +17,146 @@
 
 use crate::generate::options;
 use crate::generate::parser::{Config, ConfigType, Services, sorted_services};
-use anyhow::Result;
+use anyhow::{Context, Result, bail};
 use minijinja::value::ViaDeserialize;
 use minijinja::{Environment, context};
+use serde::Deserialize;
+use std::collections::HashSet;
 use std::fs;
 use std::path::Path;
 use std::path::PathBuf;
+use std::process::Command;
+use toml_edit::{DocumentMut, Item};
+
+/// Naming of the service sets the PyPI wheels are built with per platform, for
+/// example `services-platform-linux`.
+const PLATFORM_FEATURE_PREFIX: &str = "services-platform-";
+
+/// Subset of the `cargo metadata --format-version 1` output consumed here.
+/// The schema is controlled by cargo, so only the fields this generator reads
+/// are declared; serde ignores everything else.
+#[derive(Deserialize)]
+struct CargoMetadata {
+    packages: Vec<MetadataPackage>,
+    resolve: MetadataResolve,
+}
+
+#[derive(Deserialize)]
+struct MetadataPackage {
+    name: String,
+    id: String,
+}
 
-fn enabled_service(srv: &str) -> bool {
-    match srv {
-        // Services omitted from the generated Python API.
-        "etcd" | "foundationdb" | "hdfs" | "rocksdb" | "tikv" | 
"cloudflare_kv" | "monoiofs"
-        | "dbfs" | "surrealdb" | "d1" | "opfs" | "compfs" | "lakefs" | 
"pcloud" | "vercel_blob"
-        | "goosefs" | "git" | "smb" => false,
-        _ => true,
+#[derive(Deserialize)]
+struct MetadataResolve {
+    nodes: Vec<MetadataResolveNode>,
+}
+
+#[derive(Deserialize)]
+struct MetadataResolveNode {
+    id: String,
+    features: Vec<String>,
+}
+
+fn cargo_metadata(workspace_dir: &Path, features: &[String]) -> 
Result<CargoMetadata> {
+    let mut command = Command::new("cargo");
+    command
+        .arg("metadata")
+        .arg("--format-version")
+        .arg("1")
+        .arg("--manifest-path")
+        .arg(workspace_dir.join("bindings/python/Cargo.toml"));
+    if !features.is_empty() {
+        command.arg("--features").arg(features.join(","));
     }
+
+    let output = command
+        .output()
+        .context("failed to run `cargo metadata` for bindings/python")?;
+    if !output.status.success() {
+        bail!(
+            "`cargo metadata` failed: {}",
+            String::from_utf8_lossy(&output.stderr)
+        );
+    }
+
+    serde_json::from_slice(&output.stdout).context("failed to parse `cargo 
metadata` output")
+}
+
+/// Parse the `services-platform-*` feature names declared in the `[features]`
+/// table of `bindings/python/Cargo.toml`.
+fn platform_features(workspace_dir: &Path) -> Result<Vec<String>> {
+    let manifest_path = workspace_dir.join("bindings/python/Cargo.toml");
+    let manifest = fs::read_to_string(&manifest_path)
+        .with_context(|| format!("failed to read {}", 
manifest_path.display()))?;
+    let document = manifest
+        .parse::<DocumentMut>()
+        .with_context(|| format!("failed to parse {}", 
manifest_path.display()))?;
+    let features = document
+        .get("features")
+        .and_then(Item::as_table)
+        .with_context(|| format!("no [features] table in {}", 
manifest_path.display()))?;
+
+    let mut platforms: Vec<String> = features
+        .iter()
+        .map(|(name, _)| name.to_string())
+        .filter(|name| name.starts_with(PLATFORM_FEATURE_PREFIX))
+        .collect();
+    platforms.sort();
+    if platforms.is_empty() {
+        bail!(
+            "no `{PLATFORM_FEATURE_PREFIX}*` feature declared in {}",
+            manifest_path.display()
+        );
+    }
+
+    Ok(platforms)
+}
+
+/// Union the services enabled by every `services-platform-*` feature, i.e. the
+/// service sets the PyPI wheels are built with on their respective platforms.
+/// `cargo metadata` only resolves features and never compiles, so services 
that
+/// build on a subset of the wheel platforms, such as SFTP and Foyer, are still
+/// resolved on every host.
+///
+/// The enabled services are read from the resolve node of the `opendal` facade
+/// crate, whose `services-*` features are exactly one per service, instead of
+/// the binding's own feature namespace, which also carries aggregate sets such
+/// as `services-all` and `services-platform-*`.
+fn enabled_services(workspace_dir: &Path) -> Result<HashSet<String>> {
+    let platforms = platform_features(workspace_dir)?;
+    let metadata = cargo_metadata(workspace_dir, &platforms)?;
+
+    let package = metadata
+        .packages
+        .iter()
+        .find(|package| package.name == "opendal")
+        .with_context(|| "package `opendal` not found in `cargo metadata` 
output")?;
+    let node = metadata
+        .resolve
+        .nodes
+        .iter()
+        .find(|node| node.id == package.id)
+        .with_context(|| "resolve node for `opendal` not found in `cargo 
metadata` output")?;
+
+    // Service keys are directory names under core/services, which mix `-` and
+    // `_` (e.g. `aliyun-drive` vs `mini_moka`), so normalize both sides.
+    let services: HashSet<String> = node
+        .features
+        .iter()
+        .filter_map(|name| name.strip_prefix("services-"))
+        .map(|service| service.replace('-', "_"))
+        .collect();
+    if services.is_empty() {
+        bail!("no `services-*` feature enabled by the 
`{PLATFORM_FEATURE_PREFIX}*` features");
+    }
+
+    Ok(services)
 }
 
 pub fn generate(workspace_dir: PathBuf, services: Services) -> Result<()> {
-    let srvs = sorted_services(services, enabled_service);
+    let enabled = enabled_services(&workspace_dir)?;
+    let srvs = sorted_services(services, |srv| 
enabled.contains(&srv.replace('-', "_")));
     let mut env = Environment::new();
     env.add_template("python", include_str!("python.j2"))?;
     env.add_template("python_config", include_str!("python_config.j2"))?;
diff --git a/scripts/constants.py b/scripts/constants.py
index d131b48bd0..1dc6bd272f 100755
--- a/scripts/constants.py
+++ b/scripts/constants.py
@@ -42,6 +42,11 @@ PACKAGES = list_packages()
 
 PACKAGE_FEATURES: dict[Path, list[str]] = {
     Path("bindings/nodejs"): ["services-all"],
-    # Include the union of services selected by the Python wheel matrix.
-    Path("bindings/python"): ["services-all", "services-foyer", 
"services-sftp"],
+    # Include the union of the service sets selected by the Python wheel 
matrix.
+    Path("bindings/python"): [
+        "services-platform-linux",
+        "services-platform-linux-armv7",
+        "services-platform-macos",
+        "services-platform-windows",
+    ],
 }

Reply via email to