Skip to content

Commit bb5ef1b

Browse files
daviesrobpkang-ca
authored andcommitted
Added build wrapper so build_ext runs before build_py
SWIG, run by build_ext, generates a shared object file and a python library. The latter needs to be generated before build_py is run so that build_py finds it. Unfortunately the default in setuptools is to run build_py before build_ext. The solution is to override the build class so that the build order can be changed. With this change, "pip install" works better, including when lsf-python-api is a dependency of another module. See: https://bugs.python.org/issue2624 https://bugs.python.org/issue1016626 https://stackoverflow.com/questions/12491328/python-distutils-not-include-the-swig-generated-module https://stackoverflow.com/questions/50239473/building-a-module-with-setuptools-and-swig Signed-off-by: Robert Davies <rmd@sanger.ac.uk>
1 parent e808d4c commit bb5ef1b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

setup.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
else:
1414
from distutils.core import setup, Extension
1515
from distutils.command.bdist_rpm import bdist_rpm
16+
from distutils.command.build import build
1617
from distutils.command.install import INSTALL_SCHEMES
1718

1819
class bdist_rpm_custom(bdist_rpm):
@@ -28,6 +29,21 @@ def finalize_package_data (self):
2829
self.no_autoreq = 1
2930
bdist_rpm.finalize_package_data(self)
3031

32+
# Build extensions before python modules, so the generated pythonlsf/lsf.py
33+
# file is created before attempting to install it. This makes building with
34+
# "pip" easier.
35+
# See:
36+
# https://bugs.python.org/issue2624
37+
# https://bugs.python.org/issue1016626
38+
# https://stackoverflow.com/questions/12491328/python-distutils-not-include-the-swig-generated-module
39+
# https://stackoverflow.com/questions/50239473/building-a-module-with-setuptools-and-swig
40+
41+
class build_ext_first(build):
42+
def finalize_options(self):
43+
super().finalize_options()
44+
new_order = list(filter(lambda x: x[0] == 'build_ext', self.sub_commands)) + list(filter(lambda x: x[0] != 'build_ext', self.sub_commands))
45+
self.sub_commands[:] = new_order
46+
3147
def get_lsf_libdir():
3248
try:
3349
_lsf_envdir = os.environ['LSF_ENVDIR']
@@ -144,7 +160,8 @@ def set_gccflag_lsf_version():
144160
extra_objects=lsf_static_lib,
145161
libraries=lsf_dynamic_lib)],
146162
py_modules=['pythonlsf.lsf'],
147-
cmdclass = { 'bdist_rpm': bdist_rpm_custom },
163+
cmdclass = { 'bdist_rpm': bdist_rpm_custom,
164+
'build': build_ext_first },
148165
classifiers=["Development Status :: 2 - Pre-Alpha",
149166
"License :: OSI Approved :: Eclipse Public License",
150167
"Operating System :: OS Independent",

0 commit comments

Comments
 (0)