Skip to content

Commit 41120cb

Browse files
authored
python312Packages.kaleido: init at 0.2.1 (#339136)
2 parents 8ec8fd5 + 7edc3b6 commit 41120cb

File tree

5 files changed

+148
-1
lines changed

5 files changed

+148
-1
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
lib,
3+
stdenv,
4+
python,
5+
buildPythonPackage,
6+
callPackage,
7+
fetchurl,
8+
autoPatchelfHook,
9+
bash,
10+
dejavu_fonts,
11+
expat,
12+
fontconfig,
13+
lato,
14+
libGL,
15+
makeWrapper,
16+
nspr,
17+
nss,
18+
sbclPackages,
19+
sqlite,
20+
}:
21+
22+
buildPythonPackage rec {
23+
pname = "kaleido";
24+
version = "0.2.1";
25+
format = "wheel";
26+
27+
src =
28+
{
29+
# This library is so cursed that I have to use fetchurl instead of fetchPypi. I am not happy.
30+
x86_64-linux = fetchurl {
31+
url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-manylinux1_x86_64.whl";
32+
hash = "sha256-qiHPG/HHj4+lCp99ReEAPDh709b+CnZ8+780S5W9w6g=";
33+
};
34+
aarch64-linux = fetchurl {
35+
url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-manylinux2014_aarch64.whl";
36+
hash = "sha256-hFgZhEyAgslGnZwX5CYh+/hcKyN++KhuyKhSf5i2USo=";
37+
};
38+
x86_64-darwin = fetchurl {
39+
url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-macosx_10_11_x86_64.whl";
40+
hash = "sha256-ym9z5/8AquvyhD9z8dO6zeGTDvUEEJP+drg6FXhQSac=";
41+
};
42+
aarch64-darwin = fetchurl {
43+
url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-macosx_11_0_arm64.whl";
44+
hash = "sha256-u5pdH3EDV9XUMu4kDvZlim0STD5hCTWBe0tC2px4fAU=";
45+
};
46+
}
47+
."${stdenv.hostPlatform.system}"
48+
or (throw "Unsupported system for ${pname}: ${stdenv.hostPlatform.system}");
49+
50+
nativeBuildInputs = (lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ]) ++ [
51+
makeWrapper
52+
];
53+
buildInputs = [
54+
bash
55+
dejavu_fonts
56+
expat
57+
fontconfig
58+
lato
59+
libGL
60+
nspr
61+
nss
62+
sbclPackages.cl-dejavu
63+
sqlite
64+
];
65+
66+
pythonImportsCheck = [ "kaleido" ];
67+
68+
postInstall = ''
69+
# Expose kaleido binary
70+
mkdir -p $out/bin
71+
ln -s $out/${python.sitePackages}/kaleido/executable/bin/kaleido $out/bin/kaleido
72+
73+
# Replace bundled swiftshader with libGL
74+
rm -rf $out/${python.sitePackages}/kaleido/executable/bin/swiftshader
75+
ln -s ${libGL}/lib $out/${python.sitePackages}/kaleido/executable/bin/swiftshader
76+
77+
# Relace bundled libraries with nixpkgs-packaged libraries
78+
rm -rf $out/${python.sitePackages}/kaleido/executable/lib
79+
mkdir -p $out/${python.sitePackages}/kaleido/executable/lib
80+
ln -s ${expat}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/
81+
ln -s ${nspr}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/
82+
ln -s ${nss}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/
83+
ln -s ${sqlite}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/
84+
85+
# Replace bundled font configuration with nixpkgs-packaged font configuration
86+
rm -rf $out/${python.sitePackages}/kaleido/executable/etc/fonts
87+
mkdir -p $out/${python.sitePackages}/kaleido/executable/etc/fonts/conf.d
88+
ln -s ${fontconfig}/etc/fonts/fonts.conf $out/${python.sitePackages}/kaleido/executable/etc/fonts/
89+
ls -s ${fontconfig}/etc/fonts/conf.d/* $out/${python.sitePackages}/kaleido/executable/etc/fonts/conf.d/
90+
ln -s ${sbclPackages.cl-dejavu}/dejavu-fonts-ttf-2.37/fontconfig/* $out/${python.sitePackages}/kaleido/executable/etc/fonts/conf.d/
91+
92+
# Replace bundled fonts with nixpkgs-packaged fonts
93+
# Currently this causes an issue where the fonts aren't found. I'm not sure why, so I'm leaving this commented out for now.
94+
#rm -rf $out/${python.sitePackages}/kaleido/executable/xdg/fonts
95+
#mkdir -p $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/dejavu $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/lato
96+
#ln -s ${dejavu_fonts}/share/fonts/truetype/* $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/dejavu/
97+
#ln -s ${lato}/share/fonts/lato/* $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/lato/
98+
'';
99+
100+
passthru.tests.kaleido = callPackage ./tests.nix { };
101+
102+
meta = {
103+
description = "Fast static image export for web-based visualization libraries with zero dependencies";
104+
homepage = "https://github.com/plotly/Kaleido";
105+
changelog = "https://github.com/plotly/Kaleido/releases";
106+
platforms = [
107+
"x86_64-linux"
108+
"x86_64-darwin"
109+
"aarch64-linux"
110+
"aarch64-darwin"
111+
];
112+
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; # Trust me, I'm not happy. But after literal hours of trying to reverse-engineer their build system and getting nowhere, I'll use the stupid binaries >:(
113+
license = lib.licenses.mit;
114+
maintainers = with lib.maintainers; [ pandapip1 ];
115+
broken = stdenv.isDarwin; # Tests fail on darwin for some reason
116+
};
117+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
runCommand,
3+
python,
4+
plotly,
5+
pandas,
6+
kaleido,
7+
}:
8+
9+
runCommand "${kaleido.pname}-tests" {
10+
nativeBuildInputs = [
11+
python
12+
plotly
13+
pandas
14+
];
15+
} "python3 ${./tests.py}"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import plotly.express as px
2+
import os
3+
import os.path
4+
5+
out = os.environ["out"]
6+
if not os.path.exists(out):
7+
os.makedirs(out)
8+
9+
outfile = os.path.join(out, "figure.png")
10+
fig = px.scatter(px.data.iris(), x="sepal_length", y="sepal_width", color="species")
11+
fig.write_image(outfile, engine="kaleido")

pkgs/development/python-modules/plotly/default.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
setuptools,
66
packaging,
77
tenacity,
8+
kaleido,
89
}:
910

1011
buildPythonPackage rec {
@@ -29,6 +30,7 @@ buildPythonPackage rec {
2930
dependencies = [
3031
packaging
3132
tenacity
33+
kaleido
3234
];
3335

3436
pythonImportsCheck = [ "plotly" ];
@@ -41,6 +43,6 @@ buildPythonPackage rec {
4143
downloadPage = "https://github.com/plotly/plotly.py";
4244
homepage = "https://plot.ly/python/";
4345
license = with licenses; [ mit ];
44-
maintainers = [ ];
46+
maintainers = with maintainers; [ pandapip1 ];
4547
};
4648
}

pkgs/top-level/python-packages.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6616,6 +6616,8 @@ self: super: with self; {
66166616

66176617
kaldi-active-grammar = callPackage ../development/python-modules/kaldi-active-grammar { };
66186618

6619+
kaleido = callPackage ../development/python-modules/kaleido { };
6620+
66196621
kanidm = callPackage ../development/python-modules/kanidm { };
66206622

66216623
kaptan = callPackage ../development/python-modules/kaptan { };

0 commit comments

Comments
 (0)