From 576cef0810e78805e4ac5d8b019e4773bc58bebb Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Thu, 14 Nov 2024 15:55:45 +0100 Subject: just-import-cargo: handle special case when a local repository is staged... ...in a directory with the same name of the crate. If crate "foo", version 1.0.0 is staged in directory "/dir/bar", it will reported in the output of `cargo metadata` as path+file:///dir/bar#foo@1.0.0 However, if the same crate "foo" is staged is "/dir/foo", `cargo metadata` will report path+file:///dir/foo#1.0.0 --- bin/just-import-cargo.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/just-import-cargo.py b/bin/just-import-cargo.py index ad22478..86d55da 100755 --- a/bin/just-import-cargo.py +++ b/bin/just-import-cargo.py @@ -107,7 +107,7 @@ def split_id(id: str): # metadata provided by stable cargo, as of 2024-03-18 name, version, source = id.split() source = source[1:-1] - except Exception as e: + except ValueError as e: if id.startswith("registry"): # "registry+https://github.com/rust-lang/crates.io-index#libc@0.2.153" source, name_version = id.split("#") @@ -115,11 +115,20 @@ def split_id(id: str): elif id.startswith("path"): # path+file:///home/username/opt/src/commonlibrary_rust_ylong_runtime#ylong_io@1.0.0 - source, name_version = id.split("#") - name, version = name_version.split("@") + # or + # path+file:///tmp/hashbrown#0.14.3 + if id.find("@") >= 0: + source, name_version = id.split("#") + name, version = name_version.split("@") + else: + source, version = id.split("#") + name = source.split("/")[-1] else: print(f"while processing {id=}: {e}", file=sys.stderr) exit(1) + except Exception as e: + print(f"while processing {id=}: {e}", file=sys.stderr) + exit(1) return name, version, source -- cgit v1.2.3