JacquesLucke/animation_nodes

I tried to compile a single file my_wiggle_falloff.pyx based on wiggle_falloff.pyx, and it pops up an error relative cimport beyong main package is not allowed. Below is the setup.py. Is it possible to compile a single file rather than the whole package?

derekcbr opened this issue · 10 comments

I tried to compile a single file my_wiggle_falloff.pyx based on wiggle_falloff.pyx, and it pops up an error relative cimport beyong main package is not allowed. Below is the setup.py. Is it possible to compile a single file rather than the whole package?
extensions = [
Extension(
"my_wiggle_falloff",["my_wiggle_falloff.pyx"],
),

]

setup(name='my_wiggle_falloff',
ext_modules=cythonize(extensions),
include_dirs=["."],
cmdclass={'build_ext': build_ext},
)

You probably need to set the include dir to the Animation Nodes header and import using a path relative to the Animation Nodes module.

See the Cython section of the developer guide for extensions:
https://docs.animation-nodes.com/developer_guide/extensions/introduction/#cython

You probably need to set the include dir to the Animation Nodes header and import using a path relative to the Animation Nodes module.

See the Cython section of the developer guide for extensions: https://docs.animation-nodes.com/developer_guide/extensions/introduction/#cython

Thanks Omar!Will try!

Hi Omar,
I was not able to complie correctly, please take a look and many thanks.
from setuptools import setup, Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import sys
user_name = 'UPC'
mypath01=r'C:\Users\UPC\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons'
if not(mypath01 in sys.path):
sys.path.append(mypath01)
import animation_nodes

extensions = [
Extension(
"my_wiggle_falloff",["my_wiggle_falloff.pyx"],
"include_dirs", ["C:/Users/UPC/Documents/Downloads/animation_nodes_headers"],
),

]

setup(name='my_wiggle_falloff',
ext_modules=cythonize(extensions),
)

You probably need to set the include dir to the Animation Nodes header and import using a path relative to the Animation Nodes module.
See the Cython section of the developer guide for extensions: https://docs.animation-nodes.com/developer_guide/extensions/introduction/#cython

Thanks Omar!Will try!

Hi Omar,
I was not able to complie correctly, please take a look and many thanks.
from setuptools import setup, Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import sys
user_name = 'UPC'
mypath01=r'C:\Users\UPC\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons'
if not(mypath01 in sys.path):
sys.path.append(mypath01)
import animation_nodes

extensions = [
Extension(
"my_wiggle_falloff",["my_wiggle_falloff.pyx"],
"include_dirs", ["C:/Users/UPC/Documents/Downloads/animation_nodes_headers"],
),

]

setup(name='my_wiggle_falloff',
ext_modules=cythonize(extensions),
)

Can you provide a more complete version of what you are trying to do so that I can test it locally?
It is unclear to me why you import animation_nodes in the setup file here.

Can you provide a more complete version of what you are trying to do so that I can test it locally? It is unclear to me why you import animation_nodes in the setup file here.

image

setup.py is as below:

from setuptools import setup, Extension 
from Cython.Build import cythonize
from Cython.Distutils import build_ext

extensions = [
    Extension(
        "my_wiggle_falloff",["my_wiggle_falloff.pyx"],
        "include_dirs", ["C:/Users/UPC/Documents/Downloads/animation_nodes_headers"],
    ),
    
]

setup(name='my_wiggle_falloff',
      ext_modules=cythonize(extensions),
      )

my_wiggle_off.pyx is below:

import bpy
from bpy.props import *
from ... base_types import AnimationNode
from ... data_structures cimport BaseFalloff
from ... algorithms.perlin_noise cimport perlinNoise1D

class WiggleFalloffNode():

    def execute(self, seed, evolution, speed, offset, amplitude, octaves, persistance):
        evolution *= max(speed, 0) / 10
        return WiggleFalloff(seed, evolution, offset, amplitude, octaves, persistance)

cdef class WiggleFalloff(BaseFalloff):
    cdef:
        double evolution
        double offset, amplitude
        double persistance
        int octaves

    def __cinit__(self, float seed, float evolution,
                        float offset, float amplitude,
                        int octaves, float persistance):
        self.evolution = seed * 341312 + evolution
        self.amplitude = amplitude
        self.persistance = persistance
        self.offset = offset
        self.octaves = min(max(octaves, 0), 100)
        self.clamped = False
        self.dataType = "NONE"

    cdef float evaluate(self, void *object, Py_ssize_t index):
        cdef double x = self.evolution + index * 1127
        cdef double noise = perlinNoise1D(x, self.persistance, self.octaves)
        return <float>(self.amplitude * noise + self.offset)

You should probably set the include path in the cythonize function as follows:

from Cython.Build import cythonize
from Cython.Distutils import build_ext
from setuptools import setup, Extension 

extensions = [
    Extension(
        "my_wiggle_falloff", ["my_wiggle_falloff.pyx"]
    ),
]

setup(
    name = "my_wiggle_falloff",
    ext_modules = cythonize(extensions,
                            include_path = ["/path/to/animation_nodes_headers", "."],
                            compiler_directives = {"language_level" : "3"}),
)

And use absolute imports relative to the animation_nodes module as follows:

from animation_nodes.data_structures cimport BaseFalloff
from animation_nodes.algorithms.perlin_noise cimport perlinNoise1D
animation_nodes.

It worked well now. Thanks a lot Omar! Your supports are always great!

Hi Omar, although the compilation is ok, when call my_wiggle_falloff, it will generate below errors:animation_nodes.data_structures.meshes,mesh_data.Mesh size changed ,may indicate binary incompatibility, expect 88 from c header, got 80 from pyobject. not sure why?

This likely means that your headers are older/newer than your compiled files. Make sure both the headers and the compiled objects are of the same version.

This likely means that your headers are older/newer than your compiled files. Make sure both the headers and the compiled objects are of the same version.

Thanks Omar again.