From 7a4542c6e04e8f358bfe541383a6f27ed633a0bc Mon Sep 17 00:00:00 2001 From: burgersmoke Date: Sat, 12 Sep 2020 19:54:48 -0600 Subject: [PATCH 1/3] Making two changes so that quickumls_simstring can build again on Windows. Since Windows default locale encoding for open() is cp1252, the encoding for reading a file is now explicit as utf8. Also, there was a "unresolved external" link time error once the extension was changed to 'quickumls_simstring/_simstring' but is now set to '_simstring' for Windows. --- setup.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index b6029a0..8ea0203 100644 --- a/setup.py +++ b/setup.py @@ -48,6 +48,7 @@ def install(self): library_dirs = None extra_compile_args = None libs = [] +extension_name = 'quickumls_simstring/_simstring' if sys.platform.startswith("darwin") or sys.platform.startswith("cygwin"): libs = ['-liconv'] elif 'conda' in sys.version.lower() and sys.platform.startswith("win"): @@ -59,6 +60,10 @@ def install(self): anaconda_lib_dir = os.path.join(python_executable_dir, 'Library/lib') use_conda_deps = True + # this extension name needs to be changed for Windows or there will + # be an unresolved external error at linking time + extension_name = '_simstring' + # let's check if these pieces are actually here before we try to give the include/lib hints below if not os.path.isfile(os.path.join(anaconda_include_dir, 'iconv.h')): print('Could not find header iconv.h at [{0}] so bypassing setup hints. Verify that iconv was installed with conda.'.format(anaconda_include_dir)) @@ -89,11 +94,11 @@ def install(self): libs += ["-stdlib=libc++", '-Wl,-undefined,dynamic_lookup'] extra_compile_args = ["-stdlib=libc++"] -with open('README.md') as reader: +with open('README.md', encoding = 'utf8') as reader: readme = reader.read() simstring_module = Extension( - 'quickumls_simstring/_simstring', + extension_name, sources = [ 'quickumls_simstring/export.cpp', 'quickumls_simstring/export_wrap.cpp', From 395aa5dc26b9fb0cd2d6057e4ceda2e6d3c88514 Mon Sep 17 00:00:00 2001 From: burgersmoke Date: Sat, 19 Sep 2020 16:04:08 -0600 Subject: [PATCH 2/3] After previous commit to fix linking error, realized that .PYD files were being installed to install_dir instead of install_dir/quickumls_simstring which would prevent the lib from being found in Windows after install. Tried several other options to make this work but since the documentation for Extension says that the name of an extension should not be a filename (https://docs.python.org/3/distutils/apiref.html#distutils.core.Extension) this was the best solution I could find. --- setup.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/setup.py b/setup.py index 8ea0203..dd3921e 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ """ import sys +import shutil import re import os.path from distutils.core import setup, Extension @@ -41,6 +42,17 @@ def install(self): # for each file, match string between # second last and last dot and trim it matcher = re.compile('\.([^.]+)\.so$') + + for i, outfile in enumerate(outfiles): + # NOTE that since Windows cannot link with an extention name like 'quickumls_simstring/_simstring' + # we must work around an install-time issue to make sure that PYD libs still go to installdir/quickumls_simstring + if '.pyd' in outfile.lower(): + # let's copy any .PYD files from the root into the installdir/quickumls_simstring + source_path = os.path.join(self.build_dir, pyd_file) + target_path = os.path.join(self.install_dir, 'quickumls_simstring', pyd_file) + print('Manually copying a Windows PYD from {0} to {1}'.format(source_path, target_path)) + shutil.copy(source_path, target_path) + return [batch_rename(file, re.sub(matcher, '.so', file)) for file in outfiles] From d30812883262984f8b08f56ceb564a215c336003 Mon Sep 17 00:00:00 2001 From: burgersmoke Date: Sat, 19 Sep 2020 16:46:24 -0600 Subject: [PATCH 3/3] Re-adding a line which was accidentally removed during cleanup leading up to a pull request. --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index dd3921e..8d90c18 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,7 @@ def install(self): # NOTE that since Windows cannot link with an extention name like 'quickumls_simstring/_simstring' # we must work around an install-time issue to make sure that PYD libs still go to installdir/quickumls_simstring if '.pyd' in outfile.lower(): + pyd_file = os.path.basename(outfile) # let's copy any .PYD files from the root into the installdir/quickumls_simstring source_path = os.path.join(self.build_dir, pyd_file) target_path = os.path.join(self.install_dir, 'quickumls_simstring', pyd_file)