I'm trying to use a line_profiler on my Cython code and asked this question, I now realize that the question was not clear. The problem is that the function that I import from Cython hasn't got any __code__
attribute.
Should Cython cpdef
, cdef
or def
functions have this attribute? Any ideas why mine hasn't got one?
This is my cython_agri.pyx file:
# cython: linetrace=True
cimport cython
import numpy as np
from datetime import timedelta, datetime
@cython.binding(True)
cpdef list read_static_binary_data(data_row: list, read_point: int, binary_data: object, tlg_dict: dict, dt: np.dtype,
start_date: datetime):
"""Function to obtain the position and time data """
cdef int nr_d = 3
cdef float ten_minus_seven = pow(10, -7)
....
return [data_row, nr_dlvs, nr_d - 1]
This is my setup.py
import setuptools
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Compiler.Options import get_directive_defaults
directive_defaults = get_directive_defaults()
directive_defaults['linetrace'] = True
directive_defaults['binding'] = True
extensions = [
Extension("pyAgriculture", ["pyAgriculture\cython_agri.pyx"], define_macros=[('CYTHON_TRACE', '1')])
]
setup(ext_modules=cythonize(extensions, language_level="3"))
I compile the code using this command: py pyAgriculture\setup.py build_ext --inplace
.