git.iko.soy/typeable/nixpkgs
on master help sign in
lib/generators: print paths without quotes & move function down
commitc84dad316a8d1eb0b5c2af0bd037c169096683ca authorProfpatsch <mail@profpatsch.de> dateWed 25 Apr 2018, 15:04 (9 years ago) parent4340a15
2 files changed+20−14
lib/generators.nix+15−11 lib/tests/misc.nix+5−3
lib/generators.nix+15−11
@@ -143,18 +143,13 @@ rec {
143143 (This means fn is type Val -> String.) */
144144 allowPrettyValues ? false
145145 }@args: v: with builtins;
146− if isInt v then toString v
146+ let isPath = v: typeOf v == "path";
147+ in if isInt v then toString v
147148 else if isString v then ''"${libStr.escape [''"''] v}"''
148149 else if true == v then "true"
149150 else if false == v then "false"
150− else if null == v then "null"
151− else if isFunction v then
152− let fna = lib.functionArgs v;
153− showFnas = concatStringsSep "," (libAttr.mapAttrsToList
154− (name: hasDefVal: if hasDefVal then "(${name})" else name)
155− fna);
156− in if fna == {} then "<λ>"
157− else "<λ:{${showFnas}}>"
151+ else if null == v then "null"
152+ else if isPath v then toString v
158153 else if isList v then "[ "
159154 + libStr.concatMapStringsSep " " (toPretty args) v
160155 + " ]"
@@ -163,12 +158,21 @@ rec {
163158 if attrNames v == [ "__pretty" "val" ] && allowPrettyValues
164159 then v.__pretty v.val
165160 # TODO: there is probably a better representation?
166− else if v ? type && v.type == "derivation" then "<δ>"
161+ else if v ? type && v.type == "derivation" then
162+ "<δ:${v.name}>"
163+ # "<δ:${concatStringsSep "," (builtins.attrNames v)}>"
167164 else "{ "
168165 + libStr.concatStringsSep " " (libAttr.mapAttrsToList
169166 (name: value:
170167 "${toPretty args name} = ${toPretty args value};") v)
171168 + " }"
172− else abort "generators.toPretty: should never happen (v = ${v})";
169+ else if isFunction v then
170+ let fna = lib.functionArgs v;
171+ showFnas = concatStringsSep "," (libAttr.mapAttrsToList
172+ (name: hasDefVal: if hasDefVal then "(${name})" else name)
173+ fna);
174+ in if fna == {} then "<λ>"
175+ else "<λ:{${showFnas}}>"
176+ else abort "toPretty: should never happen (v = ${v})";
173177
174178}
lib/tests/misc.nix+5−3
@@ -317,7 +317,8 @@ runTests {
317317 expr = mapAttrs (const (generators.toPretty {})) rec {
318318 int = 42;
319319 bool = true;
320− string = "fnord";
320+ string = ''fno"rd'';
321+ path = /. + "/foo"; # toPath returns a string
321322 null_ = null;
322323 function = x: x;
323324 functionArgs = { arg ? 4, foo }: arg;
@@ -328,13 +329,14 @@ runTests {
328329 expected = rec {
329330 int = "42";
330331 bool = "true";
331− string = "\"fnord\"";
332+ string = ''"fno\"rd"'';
333+ path = "/foo";
332334 null_ = "null";
333335 function = "<λ>";
334336 functionArgs = "<λ:{(arg),foo}>";
335337 list = "[ 3 4 ${function} [ false ] ]";
336338 attrs = "{ \"foo\" = null; \"foo bar\" = \"baz\"; }";
337− drv = "<δ>";
339+ drv = "<δ:test>";
338340 };
339341 };
340342