Skip to content

Commit 63b8dbd

Browse files
committed
pyoxidizer: add test for add_include of PythonExtensionModule
1 parent a295be1 commit 63b8dbd

3 files changed

Lines changed: 86 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyoxidizer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,5 @@ version = "0.12.0-pre"
117117
path = "../tugger"
118118

119119
[dev-dependencies]
120+
indoc = "1.0"
120121
xml-rs = "0.8"

pyoxidizer/src/starlark/python_packaging_policy.rs

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,13 @@ starlark_module! { python_packaging_policy_module =>
352352
#[cfg(test)]
353353
mod tests {
354354
use {
355-
super::super::python_distribution::PythonDistributionValue, super::super::testutil::*,
356-
super::*, anyhow::Result,
355+
super::super::testutil::*,
356+
super::super::{
357+
python_distribution::PythonDistributionValue, python_executable::PythonExecutableValue,
358+
},
359+
super::*,
360+
anyhow::Result,
361+
indoc::indoc,
357362
};
358363

359364
#[test]
@@ -632,4 +637,71 @@ mod tests {
632637

633638
Ok(())
634639
}
640+
641+
#[test]
642+
fn test_ignore_non_stdlib_extension_module() -> Result<()> {
643+
let mut env = test_evaluation_context_builder()?.into_context()?;
644+
645+
let exe_value = env.eval(indoc! {r#"
646+
dist = default_python_distribution()
647+
policy = dist.make_python_packaging_policy()
648+
policy.resources_location_fallback = "filesystem-relative:lib"
649+
650+
exe = dist.to_python_executable(
651+
name = "myapp",
652+
packaging_policy = policy
653+
)
654+
655+
exe.add_python_resources(exe.pip_install(["zstandard==0.16.0"]))
656+
657+
exe
658+
"#})?;
659+
660+
let exe = exe_value.downcast_ref::<PythonExecutableValue>().unwrap();
661+
let inner = exe.inner("ignored").unwrap();
662+
663+
assert_eq!(
664+
inner
665+
.iter_resources()
666+
.filter(|(_, r)| { r.is_extension_module && r.name == "zstandard.backend_c" })
667+
.count(),
668+
1
669+
);
670+
671+
let exe_value = env.eval(indoc! {r#"
672+
dist = default_python_distribution()
673+
policy = dist.make_python_packaging_policy()
674+
policy.resources_location_fallback = "filesystem-relative:lib"
675+
676+
def cb(policy, resource):
677+
if type(resource) == "PythonExtensionModule":
678+
if resource.name == "zstandard.backend_c":
679+
print("not including zstandard.backend_c")
680+
resource.add_include = False
681+
682+
policy.register_resource_callback(cb)
683+
684+
exe = dist.to_python_executable(
685+
name = "myapp",
686+
packaging_policy = policy,
687+
)
688+
689+
exe.add_python_resources(exe.pip_install(["zstandard==0.16.0"]))
690+
691+
exe
692+
"#})?;
693+
694+
let exe = exe_value.downcast_ref::<PythonExecutableValue>().unwrap();
695+
let inner = exe.inner("ignored").unwrap();
696+
697+
assert_eq!(
698+
inner
699+
.iter_resources()
700+
.filter(|(_, r)| { r.is_extension_module && r.name == "zstandard.backend_c" })
701+
.count(),
702+
0
703+
);
704+
705+
Ok(())
706+
}
635707
}

0 commit comments

Comments
 (0)