Commit b4feee6f authored by Kirill Smelkov's avatar Kirill Smelkov

pyx.build: Allow to use custom build_ext

setuptools_dso hardcodes to use its own build_ext in its setup.
We amend that build_ext and inject our own version carefully while
setup() is run - see 7ae8c4f3 (pyx.build: Allow to combine C and C++
sources in one extension). However, currently, if user uses cmdclass =
{'build_ext': ...} in his own setup, this will be ignored and
overwritten by golang.pyx.build.build_ext . One example where this
breaks things is wendelin.core which hooks into build_ext to first
configure/build CCAN before any extension:

https://lab.nexedi.com/nexedi/wendelin.core/blob/b26ba558/setup.py#L147-153

-> Fix it by taking into account what user could put into cmdclass.
parent 14a249cb
...@@ -111,10 +111,10 @@ class build_ext(_dso_build_ext): ...@@ -111,10 +111,10 @@ class build_ext(_dso_build_ext):
# setup should be used instead of setuptools.setup # setup should be used instead of setuptools.setup
def setup(**kw): def setup(**kw):
# setuptools_dso.setup hardcodes setuptools_dso.build_ext to be used. # setuptools_dso.setup hardcodes setuptools_dso.build_ext to be used.
# temporarily inject our code there. # temporarily inject what user specified in cmdclass, or our code there.
_ = setuptools_dso.build_ext _ = setuptools_dso.build_ext
try: try:
setuptools_dso.build_ext = build_ext setuptools_dso.build_ext = kw.get('cmdclass', {}).get('build_ext', build_ext)
setuptools_dso.setup(**kw) setuptools_dso.setup(**kw)
finally: finally:
setuptools_dso.build_ext = _ setuptools_dso.build_ext = _
......
...@@ -23,9 +23,11 @@ from __future__ import print_function, absolute_import ...@@ -23,9 +23,11 @@ from __future__ import print_function, absolute_import
from golang.golang_test import pyrun, pyout from golang.golang_test import pyrun, pyout
from os.path import dirname from os.path import dirname
testprog = dirname(__file__) + "/testprog"
# verify that we can build/run external package that uses pygolang in pyx mode. # verify that we can build/run external package that uses pygolang in pyx mode.
def test_pyx_build(): def test_pyx_build():
pyxuser = dirname(__file__) + "/testprog/golang_pyx_user" pyxuser = testprog + "/golang_pyx_user"
pyrun(["setup.py", "build_ext", "-i"], cwd=pyxuser) pyrun(["setup.py", "build_ext", "-i"], cwd=pyxuser)
# run built test. # run built test.
...@@ -37,3 +39,9 @@ def test_pyx_build(): ...@@ -37,3 +39,9 @@ def test_pyx_build():
"import golang;" + "import golang;" +
"from pyxuser import test; test.main()"], cwd=pyxuser) "from pyxuser import test; test.main()"], cwd=pyxuser)
assert _ == b"test.pyx: OK\n" assert _ == b"test.pyx: OK\n"
# verify that custom classes can be used via cmdclass
def test_pyx_build_cmdclass():
_ = pyout(["cmdclass_custom.py", "build_ext"], cwd=testprog)
assert b"pyx.build:RUN_BUILD_EXT" in _
# Copyright (C) 2019 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""cmdclass_custom.py helps tests to verify that e.g. custom build_ext can be used"""
from __future__ import print_function, absolute_import
from golang.pyx.build import setup, build_ext
class mybuild_ext(build_ext):
def run(self):
print('pyx.build:RUN_BUILD_EXT')
# just print - _not_ recursing into build_ext.run
setup(
cmdclass = {'build_ext': mybuild_ext},
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment