From afacb4ca7092f18e9c0cba893c2483b8f216ebff Mon Sep 17 00:00:00 2001 From: Danny McClanahan <1305167+cosmicexplorer@users.noreply.github.com> Date: Sun, 29 Jul 2018 17:29:51 -0700 Subject: [PATCH] now also blocked on setup_requires fix --- .../hello/distutils_extensions/BUILD | 7 ++++--- .../hello/distutils_extensions/hello.c | 11 +++++++++-- .../hello/distutils_extensions/setup.py | 3 +-- .../pants/backend/python/distutils_extensions.py | 6 ++++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/examples/src/python/example/python_distribution/hello/distutils_extensions/BUILD b/examples/src/python/example/python_distribution/hello/distutils_extensions/BUILD index 1a0b6384e30..31ae97dbf4c 100644 --- a/examples/src/python/example/python_distribution/hello/distutils_extensions/BUILD +++ b/examples/src/python/example/python_distribution/hello/distutils_extensions/BUILD @@ -3,9 +3,10 @@ python_dist( sources=['setup.py', 'hello.c'], - setup_requires=[ - 'testprojects/pants-plugins/3rdparty/python/pants', - ], + # FIXME: setup_requires needs to provide transitive deps of all the requested packages too! + # setup_requires=[ + # 'testprojects/pants-plugins/3rdparty/python/pants', + # ], ) python_binary( diff --git a/examples/src/python/example/python_distribution/hello/distutils_extensions/hello.c b/examples/src/python/example/python_distribution/hello/distutils_extensions/hello.c index 63d0c247e0c..857a66ab254 100644 --- a/examples/src/python/example/python_distribution/hello/distutils_extensions/hello.c +++ b/examples/src/python/example/python_distribution/hello/distutils_extensions/hello.c @@ -4,9 +4,16 @@ #include -static PyObject *hello(PyObject *self, PyObject *args) { +#ifdef PANTS_PYTHON_DIST +static const char *hello_str = "Hello from Pants!"; +#else +static const char *hello_str = "Hello from outside of Pants!"; +#endif + + static PyObject * + hello(PyObject *self, PyObject *args) { /* FIXME: make this depend on some env var we pass in!? */ - return Py_BuildValue("s", "Hello from C!"); + return Py_BuildValue("s", hello_str); } static PyMethodDef Methods[] = { diff --git a/examples/src/python/example/python_distribution/hello/distutils_extensions/setup.py b/examples/src/python/example/python_distribution/hello/distutils_extensions/setup.py index 86af316ff47..d7b1946b0de 100644 --- a/examples/src/python/example/python_distribution/hello/distutils_extensions/setup.py +++ b/examples/src/python/example/python_distribution/hello/distutils_extensions/setup.py @@ -11,14 +11,13 @@ try: from pants.backend.python.distutils_extensions import pants_setup as setup except ImportError as e: - raise e from setuptools import setup c_module = Extension(b'hello', sources=[b'hello.c']) setup( - name='distutils_extensions' + name='distutils_extensions', version='0.0.1', ext_modules=[c_module], packages=find_packages(), diff --git a/src/python/pants/backend/python/distutils_extensions.py b/src/python/pants/backend/python/distutils_extensions.py index 34d1a8f3070..1f01e669db9 100644 --- a/src/python/pants/backend/python/distutils_extensions.py +++ b/src/python/pants/backend/python/distutils_extensions.py @@ -32,7 +32,7 @@ def customize_compiler_from_env(compiler): linker_so=link_cmd) -class env_only_build_ext(distutils_build_ext): +class pants_build_ext(distutils_build_ext): """???""" def _append_to_compiler_property(elements, append_fun): @@ -96,6 +96,8 @@ def run(self): self._append_to_compiler_property(self.rpath, self.compiler.add_runtime_library_dir) self._append_to_compiler_property(self.link_objects, self.compiler.add_link_object) + self.compiler.define_macro('PANTS_PYTHON_DIST', None) + # Now actually compile and link everything. self.build_extensions() @@ -109,6 +111,6 @@ def pants_setup(cmdclass=None, *args, **kwargs): "Overriding 'build_ext' in the 'cmdclass' keyword argument of pants_setup() " "is not supported.") - cmdclass.add('build_ext', env_only_build_ext) + cmdclass.add('build_ext', pants_build_ext) setuptools_setup(*args, cmdclass=cmdclass, **kwargs)