Commit 19713c71 authored by kb's avatar kb
Browse files

python3Packages.tree-sitter-grammars: ensure PEP 440 compatible versions

parent 6e22720f
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -12,8 +12,20 @@
  grammarDrv,
}:
let
  inherit (grammarDrv) version;

  # Map nix style `0-unstable-YYYY-MM-DD` version identifiers to a PEP 440
  # compatible form (`0+unstableYYYYMMDD`).
  version = lib.pipe grammarDrv [
    lib.getVersion
    (lib.splitString "-")
    (
      parts:
      let
        version = lib.head parts;
        metadata = lib.join "" (lib.tail parts);
      in
      if (metadata == "") then version else "${version}+${metadata}"
    )
  ];
  snakeCaseName = lib.replaceStrings [ "-" ] [ "_" ] name;
  drvPrefix = "python-${name}";
  # If the name of the grammar attribute differs from the grammar's symbol name,