From 25ad2d11ec45cbc6c908b78de63ad49aba401f9f Mon Sep 17 00:00:00 2001 From: Gavin John Date: Mon, 2 Sep 2024 17:54:44 -0700 Subject: [PATCH 1/5] python312Packages.kaleido: init at 0.2.1 --- .../python-modules/kaleido/default.nix | 113 ++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 115 insertions(+) create mode 100644 pkgs/development/python-modules/kaleido/default.nix diff --git a/pkgs/development/python-modules/kaleido/default.nix b/pkgs/development/python-modules/kaleido/default.nix new file mode 100644 index 0000000000000..726ab291845c3 --- /dev/null +++ b/pkgs/development/python-modules/kaleido/default.nix @@ -0,0 +1,113 @@ +{ + lib, + stdenv, + python, + buildPythonPackage, + fetchurl, + autoPatchelfHook, + bash, + dejavu_fonts, + expat, + fontconfig, + lato, + libGL, + makeWrapper, + nspr, + nss, + sbclPackages, + sqlite, +}: + +buildPythonPackage rec { + pname = "kaleido"; + version = "0.2.1"; + format = "wheel"; + + src = + { + # This library is so cursed that I have to use fetchurl instead of fetchPypi. I am not happy. + x86_64-linux = fetchurl { + url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-manylinux1_x86_64.whl"; + hash = "sha256-qiHPG/HHj4+lCp99ReEAPDh709b+CnZ8+780S5W9w6g="; + }; + aarch64-linux = fetchurl { + url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-manylinux2014_aarch64.whl"; + hash = "sha256-hFgZhEyAgslGnZwX5CYh+/hcKyN++KhuyKhSf5i2USo="; + }; + x86_64-darwin = fetchurl { + url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-macosx_10_11_x86_64.whl"; + hash = "sha256-ym9z5/8AquvyhD9z8dO6zeGTDvUEEJP+drg6FXhQSac="; + }; + aarch64-darwin = fetchurl { + url = "https://files.pythonhosted.org/packages/py2.py3/k/kaleido/kaleido-${version}-py2.py3-none-macosx_11_0_arm64.whl"; + hash = "sha256-u5pdH3EDV9XUMu4kDvZlim0STD5hCTWBe0tC2px4fAU="; + }; + } + ."${stdenv.hostPlatform.system}" + or (throw "Unsupported system for ${pname}: ${stdenv.hostPlatform.system}"); + + nativeBuildInputs = (lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ]) ++ [ + makeWrapper + ]; + buildInputs = [ + bash + dejavu_fonts + expat + fontconfig + lato + libGL + nspr + nss + sbclPackages.cl-dejavu + sqlite + ]; + + pythonImportsCheck = [ "kaleido" ]; + + postInstall = '' + # Expose kaleido binary + mkdir -p $out/bin + ln -s $out/${python.sitePackages}/kaleido/executable/bin/kaleido $out/bin/kaleido + + # Replace bundled swiftshader with libGL + rm -rf $out/${python.sitePackages}/kaleido/executable/bin/swiftshader + ln -s ${libGL}/lib $out/${python.sitePackages}/kaleido/executable/bin/swiftshader + + # Relace bundled libraries with nixpkgs-packaged libraries + rm -rf $out/${python.sitePackages}/kaleido/executable/lib + mkdir -p $out/${python.sitePackages}/kaleido/executable/lib + ln -s ${expat}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/ + ln -s ${nspr}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/ + ln -s ${nss}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/ + ln -s ${sqlite}/lib/* $out/${python.sitePackages}/kaleido/executable/lib/ + + # Replace bundled font configuration with nixpkgs-packaged font configuration + rm -rf $out/${python.sitePackages}/kaleido/executable/etc/fonts + mkdir -p $out/${python.sitePackages}/kaleido/executable/etc/fonts/conf.d + ln -s ${fontconfig}/etc/fonts/fonts.conf $out/${python.sitePackages}/kaleido/executable/etc/fonts/ + ls -s ${fontconfig}/etc/fonts/conf.d/* $out/${python.sitePackages}/kaleido/executable/etc/fonts/conf.d/ + ln -s ${sbclPackages.cl-dejavu}/dejavu-fonts-ttf-2.37/fontconfig/* $out/${python.sitePackages}/kaleido/executable/etc/fonts/conf.d/ + + # Replace bundled fonts with nixpkgs-packaged fonts + # 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. + #rm -rf $out/${python.sitePackages}/kaleido/executable/xdg/fonts + #mkdir -p $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/dejavu $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/lato + #ln -s ${dejavu_fonts}/share/fonts/truetype/* $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/dejavu/ + #ln -s ${lato}/share/fonts/lato/* $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/lato/ + ''; + + meta = { + description = "Fast static image export for web-based visualization libraries with zero dependencies"; + homepage = "https://github.com/plotly/Kaleido"; + changelog = "https://github.com/plotly/Kaleido/releases"; + platforms = [ + "x86_64-linux" + "x86_64-darwin" + "aarch64-linux" + "aarch64-darwin" + ]; + 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 >:( + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ pandapip1 ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 2dad059a39659..843f3973acd90 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -6612,6 +6612,8 @@ self: super: with self; { kaldi-active-grammar = callPackage ../development/python-modules/kaldi-active-grammar { }; + kaleido = callPackage ../development/python-modules/kaleido { }; + kanidm = callPackage ../development/python-modules/kanidm { }; kaptan = callPackage ../development/python-modules/kaptan { }; From 534c90d223c32bf88b7aba3399fa69936c25fbf6 Mon Sep 17 00:00:00 2001 From: Gavin John Date: Mon, 2 Sep 2024 21:57:21 -0700 Subject: [PATCH 2/5] python312Packages.plotly: Add kaleido to dependencies --- pkgs/development/python-modules/plotly/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/python-modules/plotly/default.nix b/pkgs/development/python-modules/plotly/default.nix index 6623b8ace1ee1..8327af2ce6c2d 100644 --- a/pkgs/development/python-modules/plotly/default.nix +++ b/pkgs/development/python-modules/plotly/default.nix @@ -5,6 +5,7 @@ setuptools, packaging, tenacity, + kaleido, }: buildPythonPackage rec { @@ -29,6 +30,7 @@ buildPythonPackage rec { dependencies = [ packaging tenacity + kaleido ]; pythonImportsCheck = [ "plotly" ]; From 46c1ce890a749f6c17b07ce87237e7ebccf5af42 Mon Sep 17 00:00:00 2001 From: Gavin John Date: Mon, 2 Sep 2024 22:06:59 -0700 Subject: [PATCH 3/5] python312Packages.kaleido: Add passthru.tests --- .../python-modules/kaleido/default.nix | 3 +++ pkgs/development/python-modules/kaleido/tests.nix | 15 +++++++++++++++ pkgs/development/python-modules/kaleido/tests.py | 11 +++++++++++ 3 files changed, 29 insertions(+) create mode 100644 pkgs/development/python-modules/kaleido/tests.nix create mode 100644 pkgs/development/python-modules/kaleido/tests.py diff --git a/pkgs/development/python-modules/kaleido/default.nix b/pkgs/development/python-modules/kaleido/default.nix index 726ab291845c3..a0229b95be15e 100644 --- a/pkgs/development/python-modules/kaleido/default.nix +++ b/pkgs/development/python-modules/kaleido/default.nix @@ -3,6 +3,7 @@ stdenv, python, buildPythonPackage, + callPackage, fetchurl, autoPatchelfHook, bash, @@ -96,6 +97,8 @@ buildPythonPackage rec { #ln -s ${lato}/share/fonts/lato/* $out/${python.sitePackages}/kaleido/executable/xdg/fonts/truetype/lato/ ''; + passthru.tests.kaleido = callPackage ./tests.nix { }; + meta = { description = "Fast static image export for web-based visualization libraries with zero dependencies"; homepage = "https://github.com/plotly/Kaleido"; diff --git a/pkgs/development/python-modules/kaleido/tests.nix b/pkgs/development/python-modules/kaleido/tests.nix new file mode 100644 index 0000000000000..e09f4947a563e --- /dev/null +++ b/pkgs/development/python-modules/kaleido/tests.nix @@ -0,0 +1,15 @@ +{ + runCommand, + python, + plotly, + pandas, + kaleido, +}: + +runCommand "${kaleido.pname}-tests" { + nativeBuildInputs = [ + python + plotly + pandas + ]; +} "python3 ${./tests.py}" diff --git a/pkgs/development/python-modules/kaleido/tests.py b/pkgs/development/python-modules/kaleido/tests.py new file mode 100644 index 0000000000000..0cbcaaae60bed --- /dev/null +++ b/pkgs/development/python-modules/kaleido/tests.py @@ -0,0 +1,11 @@ +import plotly.express as px +import os +import os.path + +out = os.environ["out"] +if not os.path.exists(out): + os.makedirs(out) + +outfile = os.path.join(out, "figure.png") +fig = px.scatter(px.data.iris(), x="sepal_length", y="sepal_width", color="species") +fig.write_image(outfile, engine="kaleido") From 6c9867637668f00d0e7f8dac0f3312c525500c9d Mon Sep 17 00:00:00 2001 From: Gavin John Date: Tue, 3 Sep 2024 13:18:58 -0700 Subject: [PATCH 4/5] python312Packages.plotly: adopt --- pkgs/development/python-modules/plotly/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/python-modules/plotly/default.nix b/pkgs/development/python-modules/plotly/default.nix index 8327af2ce6c2d..38b4ed40dca25 100644 --- a/pkgs/development/python-modules/plotly/default.nix +++ b/pkgs/development/python-modules/plotly/default.nix @@ -43,6 +43,6 @@ buildPythonPackage rec { downloadPage = "https://github.com/plotly/plotly.py"; homepage = "https://plot.ly/python/"; license = with licenses; [ mit ]; - maintainers = [ ]; + maintainers = with maintainers; [ pandapip1 ]; }; } From 7edc3b600d3e35e422bed873b9956797aeec801b Mon Sep 17 00:00:00 2001 From: Gavin John Date: Wed, 4 Sep 2024 19:17:15 -0700 Subject: [PATCH 5/5] python312Packages.kaleido: mark as broken on darwin --- pkgs/development/python-modules/kaleido/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/python-modules/kaleido/default.nix b/pkgs/development/python-modules/kaleido/default.nix index a0229b95be15e..0a8e3814fa00b 100644 --- a/pkgs/development/python-modules/kaleido/default.nix +++ b/pkgs/development/python-modules/kaleido/default.nix @@ -112,5 +112,6 @@ buildPythonPackage rec { 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 >:( license = lib.licenses.mit; maintainers = with lib.maintainers; [ pandapip1 ]; + broken = stdenv.isDarwin; # Tests fail on darwin for some reason }; }