diff options
author | Matti Picus <matti.picus@gmail.com> | 2022-07-17 20:54:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-17 19:54:15 +0200 |
commit | 344389e9be01a34b0d8a79260396c791b1183f69 (patch) | |
tree | 06b66865fea1e663611defddb90aa419a28c8ca6 | |
parent | 1b284442bb9f9ea59dddf069c63c3cc042cd9696 (diff) | |
download | cython-344389e9be01a34b0d8a79260396c791b1183f69.tar.gz |
pyximport: 'cd' into common dir to prevent too-long filenames (mostly for windows) (GH-4630)
-rw-r--r-- | pyximport/_pyximport2.py | 26 | ||||
-rw-r--r-- | pyximport/_pyximport3.py | 26 |
2 files changed, 40 insertions, 12 deletions
diff --git a/pyximport/_pyximport2.py b/pyximport/_pyximport2.py index b2077826a..00e88a8ac 100644 --- a/pyximport/_pyximport2.py +++ b/pyximport/_pyximport2.py @@ -185,12 +185,26 @@ def build_module(name, pyxfilename, pyxbuild_dir=None, inplace=False, language_l build_in_temp = sargs.pop('build_in_temp',build_in_temp) from . import pyxbuild - so_path = pyxbuild.pyx_to_dll(pyxfilename, extension_mod, - build_in_temp=build_in_temp, - pyxbuild_dir=pyxbuild_dir, - setup_args=sargs, - inplace=inplace, - reload_support=pyxargs.reload_support) + olddir = os.getcwd() + common = '' + if pyxbuild_dir: + # Windows concantenates the pyxbuild_dir to the pyxfilename when + # compiling, and then complains that the filename is too long + common = os.path.commonprefix([pyxbuild_dir, pyxfilename]) + if len(common) > 30: + pyxfilename = os.path.relpath(pyxfilename) + pyxbuild_dir = os.path.relpath(pyxbuild_dir) + os.chdir(common) + try: + so_path = pyxbuild.pyx_to_dll(pyxfilename, extension_mod, + build_in_temp=build_in_temp, + pyxbuild_dir=pyxbuild_dir, + setup_args=sargs, + inplace=inplace, + reload_support=pyxargs.reload_support) + finally: + os.chdir(olddir) + so_path = os.path.join(common, so_path) assert os.path.exists(so_path), "Cannot find: %s" % so_path junkpath = os.path.join(os.path.dirname(so_path), name+"_*") #very dangerous with --inplace ? yes, indeed, trying to eat my files ;) diff --git a/pyximport/_pyximport3.py b/pyximport/_pyximport3.py index dccd1d09e..4fa811f8a 100644 --- a/pyximport/_pyximport3.py +++ b/pyximport/_pyximport3.py @@ -183,12 +183,26 @@ def build_module(name, pyxfilename, pyxbuild_dir=None, inplace=False, language_l build_in_temp = sargs.pop('build_in_temp',build_in_temp) from . import pyxbuild - so_path = pyxbuild.pyx_to_dll(pyxfilename, extension_mod, - build_in_temp=build_in_temp, - pyxbuild_dir=pyxbuild_dir, - setup_args=sargs, - inplace=inplace, - reload_support=pyxargs.reload_support) + olddir = os.getcwd() + common = '' + if pyxbuild_dir: + # Windows concantenates the pyxbuild_dir to the pyxfilename when + # compiling, and then complains that the filename is too long + common = os.path.commonprefix([pyxbuild_dir, pyxfilename]) + if len(common) > 30: + pyxfilename = os.path.relpath(pyxfilename) + pyxbuild_dir = os.path.relpath(pyxbuild_dir) + os.chdir(common) + try: + so_path = pyxbuild.pyx_to_dll(pyxfilename, extension_mod, + build_in_temp=build_in_temp, + pyxbuild_dir=pyxbuild_dir, + setup_args=sargs, + inplace=inplace, + reload_support=pyxargs.reload_support) + finally: + os.chdir(olddir) + so_path = os.path.join(common, so_path) assert os.path.exists(so_path), "Cannot find: %s" % so_path junkpath = os.path.join(os.path.dirname(so_path), name+"_*") #very dangerous with --inplace ? yes, indeed, trying to eat my files ;) |