chore: clean up matplotlib expression

This commit is contained in:
Phillip Cloud 2024-05-26 11:02:34 -04:00
parent a0dacddeb8
commit a9d091ece2
No known key found for this signature in database
GPG key ID: D908212070FD785E

View file

@ -1550,6 +1550,7 @@ lib.composeManyExtensions [
inherit (pkgs.xorg) libX11; inherit (pkgs.xorg) libX11;
inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa; inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa;
mpl39 = lib.versionAtLeast prev.matplotlib.version "3.9.0"; mpl39 = lib.versionAtLeast prev.matplotlib.version "3.9.0";
isSrc = !(old.src.isWheel or false);
in in
{ {
XDG_RUNTIME_DIR = "/tmp"; XDG_RUNTIME_DIR = "/tmp";
@ -1572,58 +1573,56 @@ lib.composeManyExtensions [
] ]
++ lib.optionals enableGtk3 [ pkgs.cairo pkgs.librsvg final.pycairo pkgs.gtk3 pkgs.gobject-introspection final.pygobject3 ] ++ lib.optionals enableGtk3 [ pkgs.cairo pkgs.librsvg final.pycairo pkgs.gtk3 pkgs.gobject-introspection final.pygobject3 ]
++ lib.optionals enableTk [ pkgs.tcl pkgs.tk final.tkinter pkgs.libX11 ] ++ lib.optionals enableTk [ pkgs.tcl pkgs.tk final.tkinter pkgs.libX11 ]
++ lib.optionals enableQt [ final.pyqt5 ] ++ lib.optionals enableQt [ final.pyqt5 ];
;
dontUseMesonConfigure = mpl39; dontUseMesonConfigure = isSrc && mpl39;
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [ nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [ pkg-config ];
pkg-config
];
mesonFlags = lib.optionals mpl39 [ mesonFlags = lib.optionals (isSrc && mpl39) [
"-Dsystem-freetype=true" "-Dsystem-freetype=true"
"-Dsystem-qhull=true" "-Dsystem-qhull=true"
# broken for linux in matplotlib 3.9.0 # broken for linux in matplotlib 3.9.0
"-Db_lto=false" "-Db_lto=false"
]; ];
# Clang doesn't understand -fno-strict-overflow, and matplotlib builds with -Werror # Clang doesn't understand -fno-strict-overflow, and matplotlib
hardeningDisable = if stdenv.isDarwin then [ "strictoverflow" ] else [ ]; # builds with -Werror
hardeningDisable = lib.optionals stdenv.isDarwin [ "strictoverflow" ];
passthru = old.passthru or { } // passthru; passthru = old.passthru or { } // passthru;
MPLSETUPCFG = pkgs.writeText "mplsetup.cfg" (lib.generators.toINI { } passthru.config); MPLSETUPCFG = pkgs.writeText "mplsetup.cfg" (lib.generators.toINI { } passthru.config);
# Matplotlib tries to find Tcl/Tk by opening a Tk window and asking the # Matplotlib tries to find Tcl/Tk by opening a Tk window and asking
# corresponding interpreter object for its library paths. This fails if # the corresponding interpreter object for its library paths. This
# `$DISPLAY` is not set. The fallback option assumes that Tcl/Tk are both # fails if `$DISPLAY` is not set. The fallback option assumes that
# installed under the same path which is not true in Nix. # Tcl/Tk are both installed under the same path which is not true in
# With the following patch we just hard-code these paths into the install # Nix. With the following patch we just hard-code these paths into
# script. # the install script.
postPatch = postPatch =
let let
tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"''; tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"'';
in in
lib.optionalString isSrc (
lib.optionalString enableTk '' lib.optionalString enableTk ''
sed -i '/final.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py sed -i '/final.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py
'' + lib.optionalString (stdenv.isLinux && interactive && !(old.src.isWheel or false)) '' '' + lib.optionalString (stdenv.isLinux && interactive) ''
# fix paths to libraries in dlopen calls (headless detection) # fix paths to libraries in dlopen calls (headless detection)
substituteInPlace src/_c_internal_utils.c \ substituteInPlace src/_c_internal_utils.c \
--replace libX11.so.6 ${libX11}/lib/libX11.so.6 \ --replace libX11.so.6 ${libX11}/lib/libX11.so.6 \
--replace libwayland-client.so.0 ${wayland}/lib/libwayland-client.so.0 --replace libwayland-client.so.0 ${wayland}/lib/libwayland-client.so.0
'' ''
+ lib.optionalString mpl39 ''patchShebangs .''
# avoid matplotlib trying to download dependencies # avoid matplotlib trying to download dependencies
+ lib.optionalString mpl39 + lib.optionalString (!mpl39) ''
{
echo '[libs]'
echo 'system_freetype = true'
echo 'system_qhull = true'
} > mplsetup.cfg
'' ''
patchShebangs . );
''
# avoid matplotlib trying to download dependencies
+ ''
echo "[libs]
system_freetype=true
system_qhull=true" > mplsetup.cfg
'';
} }
); );