Skip to content

Commit

Permalink
describe the need for module-name (#1604)
Browse files Browse the repository at this point in the history
* describe the need for module-name

* update to show how to set the module name in mixed python environment

* update to remove reference to cargo.toml

* Update README.md

---------

Co-authored-by: messense <messense@icloud.com>
  • Loading branch information
krpatter-intc and messense authored May 18, 2023
1 parent 87ac3d9 commit 2c4573c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ You can specify a different python source directory in `pyproject.toml` by setti
```toml
[tool.maturin]
python-source = "python"
module-name = "my_project._lib_name"
```

then the project structure would look like this:
Expand Down Expand Up @@ -153,12 +154,24 @@ my-project
├── my_project
│   ├── __init__.py
│   ├── bar.py
│   └── my_project.cpython-36m-x86_64-linux-gnu.so
│   └── _lib_name.cpython-36m-x86_64-linux-gnu.so
├── README.md
└── src
   └── lib.rs
```

When doing this also be sure to set the module name in your code to match the last part of `module-name` (don't include the package path):

```
#[pymodule]
#[pyo3(name="_lib_name")]
fn my_lib_name(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<MyPythonRustClass>()?;
Ok(())
}
```


## Python metadata

maturin supports [PEP 621](https://www.python.org/dev/peps/pep-0621/), you can specify python package metadata in `pyproject.toml`.
Expand Down

0 comments on commit 2c4573c

Please sign in to comment.