chitralverma commented on code in PR #7812:
URL: https://github.com/apache/opendal/pull/7812#discussion_r3467453855


##########
bindings/python/src/lib.rs:
##########
@@ -43,72 +43,95 @@ use pyo3_stub_gen::{define_stub_info_gatherer, derive::*};
 pub use services::*;
 
 #[pymodule(gil_used = false)]
-fn _opendal(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
-    // Add version
-    m.add("__version__", env!("CARGO_PKG_VERSION"))?;
-
-    // Operator module
-    add_pymodule!(py, m, "operator", [Operator, AsyncOperator])?;
-
-    // File module
-    add_pymodule!(py, m, "file", [File, AsyncFile])?;
-
-    // Capability module
-    add_pymodule!(py, m, "capability", [Capability])?;
-
-    // Services module
-    add_pymodule!(py, m, "services", [PyScheme])?;
-
-    // Layers module
-    add_pymodule!(
-        py,
-        m,
-        "layers",
-        [
-            Layer,
-            CapabilityOverrideLayer,
-            RetryLayer,
-            ConcurrentLimitLayer,
-            MimeGuessLayer
-        ]
-    )?;
-
-    // Types module
-    add_pymodule!(
-        py,
-        m,
-        "types",
-        [Entry, EntryMode, Metadata, PresignedRequest]
-    )?;
-
-    m.add_class::<WriteOptions>()?;
-    m.add_class::<ReadOptions>()?;
-    m.add_class::<ListOptions>()?;
-    m.add_class::<StatOptions>()?;
-    m.add_class::<DeleteOptions>()?;
-
-    // Exceptions module
-    add_pyexceptions!(
-        py,
-        m,
-        "exceptions",
-        [
-            Error,
-            Unexpected,
-            Unsupported,
-            ConfigInvalid,
-            NotFound,
-            PermissionDenied,
-            IsADirectory,
-            NotADirectory,
-            AlreadyExists,
-            IsSameFile,
-            ConditionNotMatch,
-            RateLimited,
-            RangeNotSatisfied,
-        ]
-    )?;
-    Ok(())
+mod _opendal {

Review Comment:
   Yes — declarative module syntax is exactly what this PR uses; `mod _opendal` 
here is the `#[pymodule] mod` form (converted from the old `fn _opendal`).
   
   The name has to stay `_opendal`, not `opendal`, because this is a mixed 
layout: `module-name = "opendal._opendal"` makes maturin build 
`python/opendal/_opendal.*.so`, and the hand-written 
`python/opendal/__init__.py` is the real `opendal` package that 
imports/re-exports from it. The `#[pymodule] mod` name must match the 
extension's last path component so `PyInit__opendal` matches the `.so` 
filename. Naming the mod `opendal` would require the native module to *be* the 
top-level package, which collides with the pure-Python `opendal/` package dir + 
its `__init__.py` (and locally it doesn't even compile, since the crate already 
binds `opendal` via `pub use ::opendal as ocore`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to