[graphics/krita] 3rdparty: Windows: enforce activation of our PYTHONPATH's eggs

L. E. Segovia null at kde.org
Thu Jun 17 03:35:55 BST 2021


Git commit b4139c8de027315767efbbc8d96fca069cc63ab5 by L. E. Segovia.
Committed on 17/06/2021 at 02:34.
Pushed by lsegovia into branch 'master'.

Windows: enforce activation of our PYTHONPATH's eggs

Since setuptools 49.0.0 [1], their easy_install command no longer installs
site.py to PYTHONPATH directories. This didn't hit me (or anyone using,
as per 3rdparty, stock Python 3.8.1) because that version ships
Setuptools 41; but anyone using v49 onwards would've run on importlib
errors when trying to use sip-build or any of our 3rdparty tools.
This bug can be easily triggered by making a virtual environment using
virtualenv and then executing build.cmd inside it.

This commit reuses Iván's sitecustomize.py for macOS and adds
the entry suggested in [2] to inject our directory.

While at it, let's ensure all PYTHONPATH entries are sanitized and
stored in KRITA_PYTHONPATH, not just ours.

[1]: https://setuptools.readthedocs.io/en/latest/history.html#v49-0-0

[2]: https://github.com/pypa/setuptools/issues/2165

CCMAIL: kimageshop at kde.org

M  +3    -3    3rdparty/CMakeLists.txt
M  +2    -2    3rdparty/ext_pyqt/CMakeLists.txt
M  +2    -0    3rdparty/ext_python/CMakeLists.txt
M  +7    -2    3rdparty/ext_python/sitecustomize.py

https://invent.kde.org/graphics/krita/commit/b4139c8de027315767efbbc8d96fca069cc63ab5

diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt
index 26db418e67..0dbe672d8a 100644
--- a/3rdparty/CMakeLists.txt
+++ b/3rdparty/CMakeLists.txt
@@ -178,9 +178,9 @@ endfunction()
 
 function(DumpSitePackages PYTHONPATH)
     if (WIN32)
-        string(REPLACE "//" "/" ___krita_pythonpath ${${PYTHONPATH}})
-        string(REPLACE "/" "\\" __krita_pythonpath ${___krita_pythonpath})
-        string(TOLOWER ${__krita_pythonpath} _krita_pythonpath)
+        string(REPLACE "//" "/" ___krita_pythonpath "${${PYTHONPATH}}")
+        string(REPLACE "/" "\\" __krita_pythonpath "${___krita_pythonpath}")
+        string(TOLOWER "${__krita_pythonpath}" _krita_pythonpath)
     else()
         set(_krita_pythonpath ${${PYTHONPATH}})
     endif()
diff --git a/3rdparty/ext_pyqt/CMakeLists.txt b/3rdparty/ext_pyqt/CMakeLists.txt
index ebc65b0f16..b6a5ef5988 100644
--- a/3rdparty/ext_pyqt/CMakeLists.txt
+++ b/3rdparty/ext_pyqt/CMakeLists.txt
@@ -88,8 +88,8 @@ elseif(WIN32)
     endif()
     string(REPLACE "//" "/" __pyqt_prefix ${PREFIX_ext_pyqt})
     string(REPLACE "/" "\\" _pyqt_prefix ${__pyqt_prefix})
-    string(REPLACE "//" "/" ___krita_pythonpath ${KRITA_PYTHONPATH})
-    string(REPLACE "/" "\\" __krita_pythonpath ${___krita_pythonpath})
+    string(REPLACE "//" "/" ___krita_pythonpath "${KRITA_PYTHONPATH}")
+    string(REPLACE "/" "\\" __krita_pythonpath "${___krita_pythonpath}")
     string(TOLOWER ${__krita_pythonpath} _krita_pythonpath)
 
     ExternalProject_Add(ext_pyqtbuilder
diff --git a/3rdparty/ext_python/CMakeLists.txt b/3rdparty/ext_python/CMakeLists.txt
index 6e42f70256..98b9ec85a6 100644
--- a/3rdparty/ext_python/CMakeLists.txt
+++ b/3rdparty/ext_python/CMakeLists.txt
@@ -56,6 +56,7 @@ elseif(MINGW)
                     COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/python3.dll ${PREFIX_ext_python}/bin
                     COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/python38.dll ${PREFIX_ext_python}/bin
                     COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/vcruntime140.dll ${PREFIX_ext_python}/bin
+                    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/sitecustomize.py ${PREFIX_ext_python}/lib/site-packages/
             UPDATE_COMMAND ""
         )
     else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
@@ -71,6 +72,7 @@ elseif(MINGW)
                     COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/python3.dll ${PREFIX_ext_python}/bin
                     COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/python38.dll ${PREFIX_ext_python}/bin
                     COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/vcruntime140.dll ${PREFIX_ext_python}/bin
+                    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/sitecustomize.py ${PREFIX_ext_python}/lib/site-packages/
             UPDATE_COMMAND ""
         )
     endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
diff --git a/3rdparty/ext_python/sitecustomize.py b/3rdparty/ext_python/sitecustomize.py
index 16e4fbf7e8..4004a65628 100644
--- a/3rdparty/ext_python/sitecustomize.py
+++ b/3rdparty/ext_python/sitecustomize.py
@@ -2,9 +2,14 @@ import os
 import site
 import sysconfig
 
-framework_path = os.path.dirname(os.path.abspath(__file__))
+# https://github.com/pypa/setuptools/issues/2165
+
+if os.name == "nt":
+    import pathlib
+    framework_path = pathlib.Path(__file__).parent.parent
+else:
+    framework_path = os.path.dirname(os.path.abspath(__file__))
 data_path = sysconfig.get_paths()['data']
 site.addsitedir(os.path.join(data_path, 'site-packages'))
 site.addsitedir(os.path.join(framework_path,'site-packages'))
 site.addsitedir(os.path.join(framework_path,'site-packages', 'PyQt5'))
-


More information about the kimageshop mailing list