Merge pull request #263599 from andir/fix-freecad-python-3.11

Fix FreeCAD with Python 3.11

authored by

Andreas Rammhold and committed by
GitHub
9d5d25bb 47ab3596

+65 -9
+60
pkgs/applications/graphics/freecad/0001-NIXOS-don-t-ignore-PYTHONPATH.patch
··· 1 + From c4f452ef6ae083ed21095313582f6d1bd775cbf3 Mon Sep 17 00:00:00 2001 2 + From: Andreas Rammhold <andreas@rammhold.de> 3 + Date: Thu, 2 Nov 2023 17:32:07 +0100 4 + Subject: [PATCH] NIXOS: don't ignore PYTHONPATH 5 + 6 + On NixOS or rather within nixpkgs we provide the runtime Python 7 + packages via the PYTHONPATH environment variable. FreeCAD tries its 8 + best to ignore Python environment variables that are being inherited 9 + from the environment. For Python versions >=3.11 it also tries to 10 + initialize the interpreter config without any environmental data. We 11 + have to initialize the configuration *with* the information from the 12 + environment for our packaging to work. 13 + 14 + Upstream has purposely isolated the environments AFAIK and thus 15 + shouldn't accept this patch (as is). What they might accept (once 16 + support for older Python versions has been dropped) is removing the 17 + PYTHONPATH specific putenv calls. 18 + --- 19 + src/Base/Interpreter.cpp | 2 +- 20 + src/Main/MainGui.cpp | 3 --- 21 + 2 files changed, 1 insertion(+), 4 deletions(-) 22 + 23 + diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp 24 + index 52c47168af..9966bd0013 100644 25 + --- a/src/Base/Interpreter.cpp 26 + +++ b/src/Base/Interpreter.cpp 27 + @@ -554,7 +554,7 @@ void initInterpreter(int argc,char *argv[]) 28 + { 29 + PyStatus status; 30 + PyConfig config; 31 + - PyConfig_InitIsolatedConfig(&config); 32 + + PyConfig_InitPythonConfig(&config); 33 + 34 + status = PyConfig_SetBytesArgv(&config, argc, argv); 35 + if (PyStatus_Exception(status)) { 36 + diff --git a/src/Main/MainGui.cpp b/src/Main/MainGui.cpp 37 + index 48ae847ef4..28813df383 100644 38 + --- a/src/Main/MainGui.cpp 39 + +++ b/src/Main/MainGui.cpp 40 + @@ -112,17 +112,14 @@ int main( int argc, char ** argv ) 41 + // See https://forum.freecad.org/viewtopic.php?f=18&t=20600 42 + // See Gui::Application::runApplication() 43 + putenv("LC_NUMERIC=C"); 44 + - putenv("PYTHONPATH="); 45 + #elif defined(FC_OS_MACOSX) 46 + (void)QLocale::system(); 47 + - putenv("PYTHONPATH="); 48 + #elif defined(__MINGW32__) 49 + const char* mingw_prefix = getenv("MINGW_PREFIX"); 50 + const char* py_home = getenv("PYTHONHOME"); 51 + if (!py_home && mingw_prefix) 52 + _putenv_s("PYTHONHOME", mingw_prefix); 53 + #else 54 + - _putenv("PYTHONPATH="); 55 + // https://forum.freecad.org/viewtopic.php?f=4&t=18288 56 + // https://forum.freecad.org/viewtopic.php?f=3&t=20515 57 + const char* fc_py_home = getenv("FC_PYTHONHOME"); 58 + -- 59 + 2.42.0 60 +
+4 -3
pkgs/applications/graphics/freecad/default.nix
··· 108 108 qtx11extras 109 109 ]; 110 110 111 + patches = [ 112 + ./0001-NIXOS-don-t-ignore-PYTHONPATH.patch 113 + ]; 114 + 111 115 cmakeFlags = [ 112 116 "-Wno-dev" # turns off warnings which otherwise makes it hard to see what is going on 113 117 "-DBUILD_FLAT_MESH:BOOL=ON" ··· 127 131 export NIX_LDFLAGS="-L${gfortran.cc}/lib64 -L${gfortran.cc}/lib $NIX_LDFLAGS"; 128 132 ''; 129 133 130 - # Their main() removes PYTHONPATH=, and we rely on it. 131 134 preConfigure = '' 132 - sed '/putenv("PYTHONPATH/d' -i src/Main/MainGui.cpp 133 - 134 135 qtWrapperArgs+=(--prefix PYTHONPATH : "$PYTHONPATH") 135 136 ''; 136 137
+1 -6
pkgs/development/python-modules/pyside2/default.nix
··· 10 10 , qt5 11 11 , shiboken2 12 12 }: 13 - 14 - # Only build when Python<=3.10 15 - # See https://bugreports.qt.io/browse/PYSIDE-1864 16 - # "There are no plans to support Python versions > 3.10 in the 5.15 branch." 17 - disabledIf (pythonAtLeast "3.11") ( 18 13 stdenv.mkDerivation rec { 19 14 pname = "pyside2"; 20 15 version = "5.15.11"; ··· 80 75 homepage = "https://wiki.qt.io/Qt_for_Python"; 81 76 maintainers = with maintainers; [ gebner ]; 82 77 }; 83 - }) 78 + }