From ba6cb7d7e77e4775c2fbc4eadefbda5dcd0bbccd Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 14 Oct 2021 09:45:33 +0800 Subject: [PATCH] Add only .pth file to editable wheels --- src/build_context.rs | 9 +++++++-- src/develop.rs | 3 +++ src/module_writer.rs | 36 ++++++++++++++++++++++++------------ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/build_context.rs b/src/build_context.rs index 7abd556d4..4a4b4bee1 100644 --- a/src/build_context.rs +++ b/src/build_context.rs @@ -273,6 +273,7 @@ impl BuildContext { None, &self.target, false, + self.editable, ) .context("Failed to add the files to the wheel")?; @@ -330,6 +331,7 @@ impl BuildContext { Some(python_interpreter), &self.target, false, + self.editable, ) .context("Failed to add the files to the wheel")?; @@ -421,6 +423,7 @@ impl BuildContext { artifact, &self.interpreter[0].executable, false, + self.editable, )?; self.add_pth(&mut writer)?; @@ -463,8 +466,10 @@ impl BuildContext { ref extension_name, .. } => { - write_python_part(&mut writer, python_module, extension_name) - .context("Failed to add the python module to the package")?; + if !self.editable { + write_python_part(&mut writer, python_module, extension_name) + .context("Failed to add the python module to the package")?; + } } ProjectLayout::PureRust { .. } => {} } diff --git a/src/develop.rs b/src/develop.rs index b2c51e14e..3915a4e9f 100644 --- a/src/develop.rs +++ b/src/develop.rs @@ -146,6 +146,7 @@ pub fn develop( &artifact, &interpreter.executable, true, + false, )?; } BridgeModel::Bindings(_) => { @@ -164,6 +165,7 @@ pub fn develop( Some(&interpreter), &target, true, + false, )?; } BridgeModel::BindingsAbi3(_, _) => { @@ -183,6 +185,7 @@ pub fn develop( None, &target, true, + false, )?; } } diff --git a/src/module_writer.rs b/src/module_writer.rs index 2fa054bb6..e9594ae0c 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -600,6 +600,7 @@ pub fn write_bindings_module( python_interpreter: Option<&PythonInterpreter>, target: &Target, develop: bool, + editable: bool, ) -> Result<()> { let ext_name = project_layout.extension_name(); let so_filename = match python_interpreter { @@ -621,10 +622,12 @@ pub fn write_bindings_module( ref rust_module, .. } => { - write_python_part(writer, python_module, &module_name) - .context("Failed to add the python module to the package")?; + if !editable { + write_python_part(writer, python_module, &module_name) + .context("Failed to add the python module to the package")?; + } - if develop { + if develop || editable { let target = rust_module.join(&so_filename); fs::copy(&artifact, &target).context(format!( "Failed to copy {} to {}", @@ -633,8 +636,10 @@ pub fn write_bindings_module( ))?; } - let relative = rust_module.strip_prefix(python_module.parent().unwrap())?; - writer.add_file_with_permissions(relative.join(&so_filename), &artifact, 0o755)?; + if !editable { + let relative = rust_module.strip_prefix(python_module.parent().unwrap())?; + writer.add_file_with_permissions(relative.join(&so_filename), &artifact, 0o755)?; + } } ProjectLayout::PureRust { ref rust_module, .. @@ -675,6 +680,7 @@ pub fn write_cffi_module( artifact: &Path, python: &Path, develop: bool, + editable: bool, ) -> Result<()> { let cffi_declarations = generate_cffi_declarations(crate_dir, python)?; @@ -686,10 +692,12 @@ pub fn write_cffi_module( ref rust_module, ref extension_name, } => { - write_python_part(writer, python_module, &module_name) - .context("Failed to add the python module to the package")?; + if !editable { + write_python_part(writer, python_module, &module_name) + .context("Failed to add the python module to the package")?; + } - if develop { + if develop || editable { let base_path = python_module.join(&module_name); fs::create_dir_all(&base_path)?; let target = base_path.join("native.so"); @@ -705,7 +713,9 @@ pub fn write_cffi_module( let relative = rust_module.strip_prefix(python_module.parent().unwrap())?; module = relative.join(extension_name); - writer.add_directory(&module)?; + if !editable { + writer.add_directory(&module)?; + } } ProjectLayout::PureRust { ref rust_module, .. @@ -724,9 +734,11 @@ pub fn write_cffi_module( } }; - writer.add_bytes(&module.join("__init__.py"), cffi_init_file().as_bytes())?; - writer.add_bytes(&module.join("ffi.py"), cffi_declarations.as_bytes())?; - writer.add_file_with_permissions(&module.join("native.so"), &artifact, 0o755)?; + if !editable { + writer.add_bytes(&module.join("__init__.py"), cffi_init_file().as_bytes())?; + writer.add_bytes(&module.join("ffi.py"), cffi_declarations.as_bytes())?; + writer.add_file_with_permissions(&module.join("native.so"), &artifact, 0o755)?; + } Ok(()) }