Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix module name when it's specified in package.metadata.maturin.name #1524

Merged
merged 1 commit into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ impl BuildContext {
write_bindings_module(
&mut writer,
&self.project_layout,
&self.module_name,
&artifact.path,
self.interpreter.first(),
true,
Expand Down Expand Up @@ -611,7 +610,6 @@ impl BuildContext {
write_bindings_module(
&mut writer,
&self.project_layout,
&self.module_name,
&artifact.path,
Some(python_interpreter),
false,
Expand Down
17 changes: 7 additions & 10 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ fn handle_cffi_call_result(
pub fn write_bindings_module(
writer: &mut impl ModuleWriter,
project_layout: &ProjectLayout,
module_name: &str,
artifact: &Path,
python_interpreter: Option<&PythonInterpreter>,
is_abi3: bool,
Expand Down Expand Up @@ -762,25 +761,23 @@ pub fn write_bindings_module(
writer.add_file_with_permissions(relative.join(&so_filename), artifact, 0o755)?;
}
} else {
let module = PathBuf::from(module_name);
let module = PathBuf::from(ext_name);
writer.add_directory(&module)?;
// Reexport the shared library as if it were the top level module
writer.add_bytes(
&module.join("__init__.py"),
format!(
r#"from .{module_name} import *
r#"from .{ext_name} import *

__doc__ = {module_name}.__doc__
if hasattr({module_name}, "__all__"):
__all__ = {module_name}.__all__"#
__doc__ = {ext_name}.__doc__
if hasattr({ext_name}, "__all__"):
__all__ = {ext_name}.__all__"#
)
.as_bytes(),
)?;
let type_stub = project_layout
.rust_module
.join(format!("{module_name}.pyi"));
let type_stub = project_layout.rust_module.join(format!("{ext_name}.pyi"));
if type_stub.exists() {
eprintln!("📖 Found type stub file at {module_name}.pyi");
eprintln!("📖 Found type stub file at {ext_name}.pyi");
writer.add_file(&module.join("__init__.pyi"), type_stub)?;
writer.add_bytes(&module.join("py.typed"), b"")?;
}
Expand Down