Skip to content

Commit c63bad4

Browse files
authored
Merge pull request PyO3#1203 from messense/path-strip-prefix
Use `unwrap` instead of `?` operator for some `strip_prefix` calls
2 parents 5f2c219 + 1b8ccf6 commit c63bad4

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/module_writer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ pub fn write_bindings_module(
659659

660660
let relative = project_layout
661661
.rust_module
662-
.strip_prefix(python_module.parent().unwrap())?;
662+
.strip_prefix(python_module.parent().unwrap())
663+
.unwrap();
663664
writer.add_file_with_permissions(relative.join(&so_filename), &artifact, 0o755)?;
664665
}
665666
} else {
@@ -729,7 +730,8 @@ pub fn write_cffi_module(
729730

730731
let relative = project_layout
731732
.rust_module
732-
.strip_prefix(python_module.parent().unwrap())?;
733+
.strip_prefix(python_module.parent().unwrap())
734+
.unwrap();
733735
module = relative.join(&project_layout.extension_name);
734736
if !editable {
735737
writer.add_directory(&module)?;
@@ -839,7 +841,9 @@ pub fn write_python_part(
839841
) -> Result<()> {
840842
for absolute in WalkBuilder::new(&python_module).hidden(false).build() {
841843
let absolute = absolute?.into_path();
842-
let relative = absolute.strip_prefix(python_module.as_ref().parent().unwrap())?;
844+
let relative = absolute
845+
.strip_prefix(python_module.as_ref().parent().unwrap())
846+
.unwrap();
843847
if absolute.is_dir() {
844848
writer.add_directory(relative)?;
845849
} else {
@@ -936,7 +940,7 @@ pub fn add_data(writer: &mut impl ModuleWriter, data: Option<&Path>) -> Result<(
936940
.build()
937941
{
938942
let file = file?;
939-
let relative = file.path().strip_prefix(data.parent().unwrap())?;
943+
let relative = file.path().strip_prefix(data.parent().unwrap()).unwrap();
940944

941945
if file.path_is_symlink() {
942946
// Copy the actual file contents, not the link, so that you can create a

src/source_distribution.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ fn add_crate_to_source_distribution(
323323

324324
let local_deps_folder = if cargo_toml_in_subdir {
325325
let level = abs_manifest_dir
326-
.strip_prefix(pyproject_dir)?
326+
.strip_prefix(pyproject_dir)
327+
.unwrap()
327328
.components()
328329
.count();
329330
format!("{}{}", "../".repeat(level), LOCAL_DEPENDENCIES_FOLDER)
@@ -342,7 +343,7 @@ fn add_crate_to_source_distribution(
342343
writer.add_directory(prefix)?;
343344

344345
let cargo_toml = if cargo_toml_in_subdir {
345-
let relative_manifest_path = abs_manifest_path.strip_prefix(pyproject_dir)?;
346+
let relative_manifest_path = abs_manifest_path.strip_prefix(pyproject_dir).unwrap();
346347
prefix.join(relative_manifest_path)
347348
} else {
348349
prefix.join(manifest_path.file_name().unwrap())
@@ -482,9 +483,9 @@ pub fn source_distribution(
482483
if cargo_lock_required || cargo_lock_path.exists() {
483484
let project_root = pyproject_toml_path.parent().unwrap();
484485
let relative_cargo_lock = if cargo_lock_path.starts_with(project_root) {
485-
cargo_lock_path.strip_prefix(project_root)?
486+
cargo_lock_path.strip_prefix(project_root).unwrap()
486487
} else {
487-
cargo_lock_path.strip_prefix(&abs_manifest_dir)?
488+
cargo_lock_path.strip_prefix(&abs_manifest_dir).unwrap()
488489
};
489490
writer.add_file(root_dir.join(relative_cargo_lock), &cargo_lock_path)?;
490491
} else {
@@ -512,7 +513,7 @@ pub fn source_distribution(
512513
continue;
513514
}
514515
let source = fs::canonicalize(source)?;
515-
let target = root_dir.join(source.strip_prefix(&pyproject_dir)?);
516+
let target = root_dir.join(source.strip_prefix(&pyproject_dir).unwrap());
516517
if source.is_dir() {
517518
writer.add_directory(target)?;
518519
} else {
@@ -542,7 +543,7 @@ pub fn source_distribution(
542543
.expect("No files found for pattern")
543544
.filter_map(Result::ok)
544545
{
545-
let target = root_dir.join(&source.strip_prefix(pyproject_dir)?);
546+
let target = root_dir.join(&source.strip_prefix(pyproject_dir).unwrap());
546547
if source.is_dir() {
547548
writer.add_directory(target)?;
548549
} else {

0 commit comments

Comments
 (0)