Skip to content

Commit efcfe26

Browse files
committed
python3Packages.xgrammar: init at 0.1.11
1 parent 160d866 commit efcfe26

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
lib,
3+
stdenv,
4+
buildPythonPackage,
5+
fetchPypi,
6+
python,
7+
pythonOlder,
8+
pythonAtLeast,
9+
pydantic,
10+
sentencepiece,
11+
tiktoken,
12+
torch,
13+
transformers,
14+
triton,
15+
}:
16+
17+
let
18+
pyShortVersion = "cp" + builtins.replaceStrings [ "." ] [ "" ] python.pythonVersion;
19+
platforms = rec {
20+
aarch64-darwin = "macosx_13_0_arm64";
21+
x86_64-darwin = "macosx_10_15_x86_64";
22+
x86_64-linux = "manylinux_2_27_x86_64.manylinux_2_28_x86_64";
23+
};
24+
platform = platforms.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
25+
# hashes retrieved via the following command
26+
# curl https://pypi.org/pypi/xgrammar/${version}/json | jq -r '.urls[] | "\(.digests.sha256) \(.filename)"'
27+
hashes = rec {
28+
cp39-aarch64-darwin = "12dd579a7073c14981e01aeee566d20e60001bf90af23024e0e6692a770ff535";
29+
cp39-x86_64-darwin = "035ec93306543b99bf2141dcc7f1a6dd0c255753fc8b5a2b5f3289a59fed8e37";
30+
cp39-x86_64-linux = "3b3975dcf4b3ed7b16bbe3c068738b09847f841793e1c5e1b4a07dff36bbdc37";
31+
cp310-aarch64-darwin = "93bb6c10cbdf1a2bda3b458d97b47436657d780f98dccf3d266e17e13568c0a9";
32+
cp310-x86_64-darwin = "5ed31db2669dc499d9d29bb16f30b3395332ff9d0fb80b759697190a5ef5258b";
33+
cp310-x86_64-linux = "9c6f571121e4af45e3b5dc55f3dadd751cffff1f85f1c6fc5c4276db2bbed222";
34+
cp311-aarch64-darwin = "b293443725eddad31cf7b407bb24d5f3156c4b12a2c8041743cb7068a69fadcb";
35+
cp311-x86_64-darwin = "b2106bceb2ce313628af915f2c2b1c9865612026dd3c9feddbfcc69e4ee6c971";
36+
cp311-x86_64-linux = "7934c968371d55759cac35be3b218cdf4b13f323f535ea0faa233240bab803b9";
37+
cp312-aarch64-darwin = "561f8d4307db8cf5d3c3b3ff46eda6d95379f6e801278dbf9153a9d5e8b6126c";
38+
cp312-x86_64-darwin = "6ac3cbb0a82a3a9d07f0739f63b2e26cbef7855149d236057dcc7fee74b37970";
39+
cp312-x86_64-linux = "1854d0fe6b908a3d2d42251a62e627224dbf6035a4322b844b1b5a277e3d0461";
40+
};
41+
hash =
42+
hashes."${pyShortVersion}-${stdenv.system}"
43+
or (throw "Unsupported Python version: ${python.pythonVersion}");
44+
in
45+
buildPythonPackage rec {
46+
pname = "xgrammar";
47+
version = "0.1.11";
48+
format = "wheel";
49+
50+
disabled = pythonOlder "3.9" || pythonAtLeast "3.13";
51+
52+
src = fetchPypi {
53+
inherit pname version format;
54+
dist = pyShortVersion;
55+
python = pyShortVersion;
56+
abi = pyShortVersion;
57+
platform = platform;
58+
sha256 = hash;
59+
};
60+
61+
pythonImportCheck = [ "xgrammar" ];
62+
63+
dependencies = [
64+
pydantic
65+
sentencepiece
66+
tiktoken
67+
torch
68+
transformers
69+
triton
70+
];
71+
72+
meta = with lib; {
73+
description = "Efficient, Flexible and Portable Structured Generation";
74+
homepage = "https://xgrammar.mlc.ai";
75+
license = licenses.asl20;
76+
};
77+
}

pkgs/top-level/python-packages.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18357,6 +18357,8 @@ self: super: with self; {
1835718357
inherit (pkgs) xgboost;
1835818358
};
1835918359

18360+
xgrammar = callPackage ../development/python-modules/xgrammar { };
18361+
1836018362
xhtml2pdf = callPackage ../development/python-modules/xhtml2pdf { };
1836118363

1836218364
xiaomi-ble = callPackage ../development/python-modules/xiaomi-ble { };

0 commit comments

Comments
 (0)