Can't figure out how to use #cython to define a reusable #python extension class.

In the .pxd

cdef class CountFingerprint:
cdef:
...

In the .pyx

from . import _typing

def _err(s):
return ValueError(s)

cdef class CountFingerprint:
def to_pandas(...) -> _typing.PDF:
..
raise _get_value_error(..)

cythonize says "Unknown type declaration '_typing.PDF' in annotation, ignoring" and "undeclared name not builtin: _get_err".

I don't get it. Those are defined in the .pyx.

Help?

Figured it out while brushing my teeth - the pyx and pxd need the same base name. In my case, "countfp.pyx" and "countfp.pxd".

I had put the .pxd information in another .pxd file (in my case, "chemfp_countfp.pxd", which contains the Cython definitions for "chemfp_countfp.c").

Note to self. I have kids who wake at 6.30 for school. I shouldn't program past 22.30, much less 23.30, as it's far too easy to make mistakes while tired.

In this case, what I thought was a fix, didn't work. So I'm back to trying to figure out what's up with getting #cython to build a #python extension class.

Here's a repo:

from setuptools import Extension
from Cython.Build import cythonize

ext = Extension(
"chemfp.countops",
sources = ["src/countops.pyx"])

# First works, second fails
cythonize("src/countops.pyx", force=True)
cythonize(ext, force=True)
# Adding include_path=["src"] does not help

## output starts
# [1/1] Cythonizing src/countops.pyx
# [1/1] Cythonizing src/countops.pyx

The later fails saying src/countops.pyx can't be converted due to missing types -- which are in the .pyx file!

I think I figured it out.

I have Python code in chemfp/*.py and C code in src/*.c.

I put the Cython code in src/*.pyx. This worked for years, until I switched using a Cython .pxd file with a class def.

This must be chemfp/countops.pxd where the path matches the implementation code in chemfp/countops.pyx.

I thought of them too much like .h header files, when they need to work within Python's import structure, to know how to import the class.

Lots of code rearranging. Tests pass. G'night.