Hi pants team! I'm taking over <this> effort to u...
# plugins
b
Hi pants team! I'm taking over this effort to upgrade our code base from python 3.6 to 3.7, but have gone through the process to upgrade pants first in hopes that newer versions (like 1.30) of pants provide some better support and ability to compile c++ code using cython. The same files that Zack had linked are still in use and haven't changed, however the error that pants throws is as follows:
Copy code
21:15:57 [INFO] initializing pantsd...
21:15:57 [INFO] pantsd initialized.
21:15:58 [ERROR] 1 Exception encountered:

  UnrecognizedTargetTypeException: Target type 'compile_cython' is not registeredfor address submodules/obscura-plugins/plugins:compile-plugins.

All valid target types: ['_python_requirements_file', 'alias', 'annotation_processor', 'benchmark', 'credentials', 'ctypes_compatible_c_library', 'ctypes_compatible_cpp_library', 'external_native_library', 'files', 'jar_library', 'java_agent', 'java_library', 'java_protobuf_library', 'java_thrift_library', 'javac_plugin', 'junit_tests', 'jvm_app', 'jvm_binary', 'jvm_prep_command', 'managed_jar_dependencies', 'netrc_credentials', 'node_bundle', 'node_module', 'node_preinstalled_module', 'node_remote_module', 'node_test', 'packaged_native_library', 'page', 'prep_command', 'python_app', 'python_binary', 'python_dist', 'python_grpcio_library', 'python_library', 'python_requirement_library', 'python_tests', 'python_thrift_library', 'remote_sources', 'resources', 'scala_library', 'scalac_plugin', 'target', 'unpacked_jars', 'unpacked_whls']

(If 'compile_cython' is a custom target type, refer to <https://groups.google.com/forum/#!topic/pants-devel/WsRFODRLVZI> for instructions on writing a light-weight Target API binding.)

(Use --print-exception-stacktrace to see more error details.)
I've looked at the link and docs for adding a new custom target type as well as the solution posted in the thread to the previous slack conversation, however being new to pants, I'm not exactly sure how to go about adding the existing
compile_cython
code that we have as a valid target type so we can build the c++ code.
h
Hi, welcome! We are glad to help. Could you share what you have so far, including your original target definition for
compile_cython
?
b
It's still defined like this: http://ix.io/3PIi The compile cython code is also the same: http://ix.io/3PIj
h
That second link did not work It would help if you can please share the contents of
from cython.compile_cython
b
Ah ok. Let me generate a new link really quick, sorry about that
h
Yes 🙂 Great so this will be fairly simple: everything is the same as
python_library
other than rhe new
output
field. What is the type of that? Like are people typing strings, a list of strings
b
As far as I know the output from this part is a bunch of cythonized c++ code saved to disk so that tests/pex can use them.
Not sure if that helps. I can do some digging on my end to see if I can get some more insight, or if there are other parts of the pants configuration that I should be looking for to determine what the output is
But the build file that uses the
compile_cython
target has this for the output: output='obscura_wrappers.cpython-36m-x86_64-linux-gnu.so',
h
OK cool, that is all we need to know that it is a string you will do this
Copy code
class CythonOutputV2Field(StringField):
    alias = "output"
    help = "fill this in"

class CompileCythonV2Target(Target):
    alias = "compile_cython"
    help = "fill me in"
    core_fields = (CythonOutputV2Field, *PythonLibrary.core_fields)
then in `register.py`:
Copy code
def target_types():
    return [CompileCythonV2Target]
b
In the registry file?
h
Oops I sent early. The first snippet can be wherever
b
Ah ok, That makes sense. I'll give that a shot, thanks!
h
Target
and
StringField
come from
pants.engine.target
. Note that there is a v1 version of
Target
and v2. You may want to do
Copy code
from pants.engine.target import Target as TargetV2
PythonLibrary
comes from
pants.backend.python.target_types
b
I added the code as suggested but received this error when trying to list out the target types.
h
What does your register.py look like now? To be clear, you should not change the original target definition you had nor
build_file_aliases
in
register.py
. There should only be a new code. You are writing "bindings"
b
Yeah, I only added new code. register: https://www.codepile.net/pile/v9JYRVGl compile_cython: https://www.codepile.net/pile/rkA3qAY2
h
for the v1 definition, you need to still use
from pants.backend.python.targets.python_library import PythonLibrary
. You are using the V2 class. You will need to do the
from as
import thing
b
Ok, I was able to get the
compile_cython
to show up in the target types after I fixed that. I'll try running my tests now to see if pants does what I need it to do
👍 1
It's really close, the only thing that seems confusing is that the container that I'm running pants inside is using python3.7 instead of python3.6 which is stored in
/usr/local/bin/python3.6
. Is there any way to tell pants to use a specific interpreter to build things with?
Never mind, I got it working using a compatability flag on the tests that I needed to get working
👍 1