rustPlatform.importCargoLock: fix [package] section handling

Members of the [package] table in Cargo.toml can be either subtables, or
values like strings and bools. Python is happy to check for membership
of "workspace" in a string, since Python strings are iterables, but if
the value is a bool, Python will throw an exception.

+21 -3
+1 -1
pkgs/build-support/rust/import-cargo-lock.nix
··· 108 108 109 109 # Replaces values inherited by workspace members. 110 110 replaceWorkspaceValues = writers.writePython3 "replace-workspace-values" 111 - { libraries = with python3Packages; [ tomli tomli-w ]; flakeIgnore = [ "E501" ]; } 111 + { libraries = with python3Packages; [ tomli tomli-w ]; flakeIgnore = [ "E501" "W503" ]; } 112 112 (builtins.readFile ./replace-workspace-values.py); 113 113 114 114 # Fetch and unpack a crate.
+5 -1
pkgs/build-support/rust/replace-workspace-values.py
··· 18 18 def replace_key( 19 19 workspace_manifest: dict[str, Any], table: dict[str, Any], section: str, key: str 20 20 ) -> bool: 21 - if "workspace" in table[key] and table[key]["workspace"] is True: 21 + if ( 22 + isinstance(table[key], dict) 23 + and "workspace" in table[key] 24 + and table[key]["workspace"] is True 25 + ): 22 26 print("replacing " + key) 23 27 24 28 replaced = table[key]
+1 -1
pkgs/build-support/rust/test/import-cargo-lock/default.nix
··· 14 14 v1 = callPackage ./v1 { }; 15 15 gitDependencyWorkspaceInheritance = callPackage ./git-dependency-workspace-inheritance { 16 16 replaceWorkspaceValues = writers.writePython3 "replace-workspace-values" 17 - { libraries = with python3Packages; [ tomli tomli-w ]; flakeIgnore = [ "E501" ]; } 17 + { libraries = with python3Packages; [ tomli tomli-w ]; flakeIgnore = [ "E501" "W503" ]; } 18 18 (builtins.readFile ../../replace-workspace-values.py); 19 19 }; 20 20 }
+7
pkgs/build-support/rust/test/import-cargo-lock/git-dependency-workspace-inheritance/crate.toml
··· 1 1 [package] 2 + name = "im_using_workspaces" 2 3 version = { workspace = true } 4 + publish = false 5 + keywords = [ 6 + "workspace", 7 + "other_thing", 8 + "third_thing", 9 + ] 3 10 4 11 [dependencies] 5 12 foo = { workspace = true, features = ["cat"] }
+7
pkgs/build-support/rust/test/import-cargo-lock/git-dependency-workspace-inheritance/want.toml
··· 1 1 [package] 2 + name = "im_using_workspaces" 2 3 version = "1.0.0" 4 + publish = false 5 + keywords = [ 6 + "workspace", 7 + "other_thing", 8 + "third_thing", 9 + ] 3 10 4 11 [dependencies] 5 12 bar = "1.0.0"