Skip to content

Commit 735e13e

Browse files
committed
setup: find system python path for CI hack
The problem appears to be that virtualenv overrides the base_prefix so distutils can no longer find the system python path when adding linker args. This adds an ugly hack to find the system python path, and adds it to the linker flags on Windows. Yay, no more hardcoded paths. This should also make win32 builds work, and avoid adding linker args manually.
1 parent 04ea4eb commit 735e13e

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

setup.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from distutils.command.sdist import sdist
1919
from distutils.cmd import Command
2020
from distutils.dir_util import remove_tree
21-
from distutils.sysconfig import get_python_inc, get_python_lib
21+
from distutils.sysconfig import get_python_inc
2222
from distutils import log
2323
import os, os.path
2424
import glob
@@ -103,6 +103,17 @@ def recursive_package_data(src, package_dir='overviewer_core'):
103103

104104
return ret
105105

106+
# Finds the system-wide path from within a venv.
107+
# Taken from https://github.com/pyinstaller/pyinstaller/blob/master/PyInstaller/hooks/pre_find_module_path/hook-distutils.py
108+
def find_system_module_path():
109+
# opcode is not a virtualenv module, so we can use it to find the stdlib. Technique taken from virtualenv's
110+
# "distutils" package detection at
111+
# https://github.com/pypa/virtualenv/blob/16.3.0/virtualenv_embedded/distutils-init.py#L5
112+
import opcode
113+
114+
system_module_path = os.path.normpath(os.path.dirname(opcode.__file__))
115+
return system_module_path
116+
106117
#
107118
# py2exe options
108119
#
@@ -183,10 +194,20 @@ def recursive_package_data(src, package_dir='overviewer_core'):
183194
c_overviewer_files = ['overviewer_core/src/' + s for s in c_overviewer_files]
184195
c_overviewer_includes = ['overviewer_core/src/' + s for s in c_overviewer_includes]
185196

197+
# really ugly hack for our scuffed CI, remove this once we move
198+
# to something else. The problem is that virtualenv somehow
199+
# now overrides the base_prefix (which it shouldn't do) which
200+
# makes distutils unable to find our Python library
201+
python_lib_dir = ""
202+
if platform.system() == 'Windows':
203+
ci_python_dir = os.path.split(find_system_module_path())[0]
204+
python_lib_dir = os.path.join(ci_python_dir, "Libs")
205+
186206
setup_kwargs['ext_modules'].append(Extension(
187207
'overviewer_core.c_overviewer',
188208
c_overviewer_files,
189209
include_dirs=['.', numpy_include] + pil_include,
210+
library_dirs=[python_lib_dir],
190211
depends=c_overviewer_includes,
191212
extra_link_args=[]
192213
))
@@ -296,9 +317,6 @@ def build_extensions(self):
296317
e.extra_link_args.append("/MANIFEST")
297318
e.extra_link_args.append("/DWINVER=0x060")
298319
e.extra_link_args.append("/D_WIN32_WINNT=0x060")
299-
# workaround for our extremely shitty build system
300-
# yeet this into a fire once we move to github actions
301-
e.extra_link_args.append("/LIBPATH:C:\Python37\Libs")
302320
if c == "unix":
303321
# customize the build options for this compilier
304322
for e in self.extensions:

0 commit comments

Comments
 (0)