Thanks for the reviewing.
On 2020/05/11 0:57, Daniel Shahaf wrote:
Jun Omae wrote on Sun, 10 May 2020 13:27 +0900:
+def _dll_paths():
+ import os
+ if hasattr(os, 'add_dll_directory'): # Python 3.8+ on Windows
+ cookies = []
+ for path in os.environ.get('PATH', '').split(';'):
Use os.pathsep in the split() call? That would make the code
self-documenting and be forward compatible with… well, with anything
that implements os.add_dll_directory() and uses another value of
os.pathsep. I guess Cygwin's Python package might fit this bill.
Indeed. Revised the patch by your suggestion.
However python3.8 on cygwin doesn't have os.add_dll_directory.
$ python3.8
Python 3.8.2 (default, Apr 9 2020, 21:39:49)
[GCC 9.3.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
import os
os.add_dll_directory
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'os' has no attribute 'add_dll_directory'
+ if path and os.path.isabs(path):
+ try:
+ cookie = os.add_dll_directory(path)
+ except:
+ continue
Should this really catch _all_ exceptions?
+ else:
+ cookies.append(cookie)
+ return cookies
+ else:
+ return ()
Okay. Confirmed OSError is raised when os.add_dll_directory() fails (e.g. for
non existent directory).
Revised the patch to catch only OSError.
See attached patch py38-windows-add-dll-directory--v2.diff.
--
Jun Omae <jun6...@gmail.com> (大前 潤)
* subversion/bindings/swig/include/svn_global.swg
(SVN_PYTHON_MODULEIMPORT): Add custom code to add search paths to resolve DLL
dependencies when importing libsvn/*.pyd file.
* subversion/bindings/swig/core.i
* subversion/bindings/swig/svn_client.i
* subversion/bindings/swig/svn_delta.i
* subversion/bindings/swig/svn_diff.i
* subversion/bindings/swig/svn_fs.i
* subversion/bindings/swig/svn_ra.i
* subversion/bindings/swig/svn_repos.i
* subversion/bindings/swig/svn_wc.i
Add moduleimport option with SVN_PYTHON_MODULEIMPORT to %module directive for
Python.
Index: subversion/bindings/swig/core.i
===================================================================
--- subversion/bindings/swig/core.i (revision 1877480)
+++ subversion/bindings/swig/core.i (working copy)
@@ -23,8 +23,10 @@
* of the more specific module files.
*/
+%include svn_global.swg
+
#if defined(SWIGPYTHON)
-%module(package="libsvn") core
+%module(package="libsvn", moduleimport=SVN_PYTHON_MODULEIMPORT) core
#elif defined(SWIGPERL)
%module "SVN::_Core"
#elif defined(SWIGRUBY)
@@ -31,8 +33,6 @@
%module "svn::ext::core"
#endif
-%include svn_global.swg
-
%{
#include <apr.h>
#include <apr_general.h>
Index: subversion/bindings/swig/include/svn_global.swg
===================================================================
--- subversion/bindings/swig/include/svn_global.swg (revision 1877480)
+++ subversion/bindings/swig/include/svn_global.swg (working copy)
@@ -242,3 +242,40 @@
/* Now, include the main Subversion typemap library. */
%include svn_types.swg
%include proxy.swg
+
+
+#ifdef SWIGPYTHON
+/* Since Python 3.8+ on Windows, DLL dependencies when loading *.pyd file
+ * searches only the system paths, the directory containing the *.pyd file and
+ * the directories added with os.add_dll_directory().
+ * See also https://bugs.python.org/issue36085.
+ */
+%define SVN_PYTHON_MODULEIMPORT
+"
+def _dll_paths():
+ import os
+ if hasattr(os, 'add_dll_directory'): # Python 3.8+ on Windows
+ cookies = []
+ for path in os.environ.get('PATH', '').split(os.pathsep):
+ if path and os.path.isabs(path):
+ try:
+ cookie = os.add_dll_directory(path)
+ except OSError:
+ continue
+ else:
+ cookies.append(cookie)
+ return cookies
+ else:
+ return ()
+
+_dll_paths = _dll_paths()
+try:
+ from . import $module
+finally:
+ _dll_path = None
+ for _dll_path in _dll_paths:
+ _dll_path.close()
+ del _dll_paths, _dll_path
+"
+%enddef
+#endif
Index: subversion/bindings/swig/svn_client.i
===================================================================
--- subversion/bindings/swig/svn_client.i (revision 1877480)
+++ subversion/bindings/swig/svn_client.i (working copy)
@@ -21,8 +21,10 @@
* svn_client.i: SWIG interface file for svn_client.h
*/
+%include svn_global.swg
+
#if defined(SWIGPYTHON)
-%module(package="libsvn") client
+%module(package="libsvn", moduleimport=SVN_PYTHON_MODULEIMPORT) client
#elif defined(SWIGPERL)
%module "SVN::_Client"
#elif defined(SWIGRUBY)
@@ -29,7 +31,6 @@
%module "svn::ext::client"
#endif
-%include svn_global.swg
%import core.i
%import svn_delta.i
%import svn_wc.i
Index: subversion/bindings/swig/svn_delta.i
===================================================================
--- subversion/bindings/swig/svn_delta.i (revision 1877480)
+++ subversion/bindings/swig/svn_delta.i (working copy)
@@ -21,8 +21,10 @@
* svn_delta.i: SWIG interface file for svn_delta.h
*/
+%include svn_global.swg
+
#if defined(SWIGPYTHON)
-%module(package="libsvn") delta
+%module(package="libsvn", moduleimport=SVN_PYTHON_MODULEIMPORT) delta
#elif defined(SWIGPERL)
%module "SVN::_Delta"
#elif defined(SWIGRUBY)
@@ -29,7 +31,6 @@
%module "svn::ext::delta"
#endif
-%include svn_global.swg
%import core.i
#ifdef SWIGRUBY
Index: subversion/bindings/swig/svn_diff.i
===================================================================
--- subversion/bindings/swig/svn_diff.i (revision 1877480)
+++ subversion/bindings/swig/svn_diff.i (working copy)
@@ -21,8 +21,10 @@
* svn_diff.i: SWIG interface file for svn_diff.h
*/
+%include svn_global.swg
+
#if defined(SWIGPYTHON)
-%module(package="libsvn") diff
+%module(package="libsvn", moduleimport=SVN_PYTHON_MODULEIMPORT) diff
#elif defined(SWIGPERL)
%module "SVN::_Diff"
#elif defined(SWIGRUBY)
@@ -29,7 +31,6 @@
%module "svn::ext::diff"
#endif
-%include svn_global.swg
%import core.i
/* -----------------------------------------------------------------------
Index: subversion/bindings/swig/svn_fs.i
===================================================================
--- subversion/bindings/swig/svn_fs.i (revision 1877480)
+++ subversion/bindings/swig/svn_fs.i (working copy)
@@ -21,8 +21,10 @@
* svn_fs.i: SWIG interface file for svn_fs.h
*/
+%include svn_global.swg
+
#if defined(SWIGPYTHON)
-%module(package="libsvn") fs
+%module(package="libsvn", moduleimport=SVN_PYTHON_MODULEIMPORT) fs
#elif defined(SWIGPERL)
%module "SVN::_Fs"
#elif defined(SWIGRUBY)
@@ -29,7 +31,6 @@
%module "svn::ext::fs"
#endif
-%include svn_global.swg
%import core.i
%import svn_delta.i
Index: subversion/bindings/swig/svn_ra.i
===================================================================
--- subversion/bindings/swig/svn_ra.i (revision 1877480)
+++ subversion/bindings/swig/svn_ra.i (working copy)
@@ -21,8 +21,10 @@
* svn_ra.i: SWIG interface file for svn_ra.h
*/
+%include svn_global.swg
+
#if defined(SWIGPYTHON)
-%module(package="libsvn") ra
+%module(package="libsvn", moduleimport=SVN_PYTHON_MODULEIMPORT) ra
#elif defined(SWIGPERL)
%module "SVN::_Ra"
#elif defined(SWIGRUBY)
@@ -29,7 +31,6 @@
%module "svn::ext::ra"
#endif
-%include svn_global.swg
%import core.i
%import svn_delta.i
Index: subversion/bindings/swig/svn_repos.i
===================================================================
--- subversion/bindings/swig/svn_repos.i (revision 1877480)
+++ subversion/bindings/swig/svn_repos.i (working copy)
@@ -21,8 +21,10 @@
* svn_repos.i: SWIG interface file for svn_repos.h
*/
+%include svn_global.swg
+
#if defined(SWIGPYTHON)
-%module(package="libsvn") repos
+%module(package="libsvn", moduleimport=SVN_PYTHON_MODULEIMPORT) repos
#elif defined(SWIGPERL)
%module "SVN::_Repos"
#elif defined(SWIGRUBY)
@@ -29,7 +31,6 @@
%module "svn::ext::repos"
#endif
-%include svn_global.swg
%import core.i
%import svn_delta.i
%import svn_fs.i
Index: subversion/bindings/swig/svn_wc.i
===================================================================
--- subversion/bindings/swig/svn_wc.i (revision 1877480)
+++ subversion/bindings/swig/svn_wc.i (working copy)
@@ -21,8 +21,10 @@
* svn_wc.i: SWIG interface file for svn_wc.h
*/
+%include svn_global.swg
+
#if defined(SWIGPYTHON)
-%module(package="libsvn") wc
+%module(package="libsvn", moduleimport=SVN_PYTHON_MODULEIMPORT) wc
#elif defined(SWIGPERL)
%module "SVN::_Wc"
#elif defined(SWIGRUBY)
@@ -29,7 +31,6 @@
%module "svn::ext::wc"
#endif
-%include svn_global.swg
%import core.i
%import svn_delta.i
%import svn_ra.i