Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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? #1895

Closed
derekcbr opened this issue Dec 20, 2022 · 10 comments

Comments

@derekcbr
Copy link

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},
)

@OmarEmaraDev
Copy link
Collaborator

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

@derekcbr
Copy link
Author

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!

@derekcbr
Copy link
Author

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),
)

@OmarEmaraDev
Copy link
Collaborator

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.

@derekcbr
Copy link
Author

derekcbr commented Dec 21, 2022

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)

@OmarEmaraDev
Copy link
Collaborator

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

@derekcbr
Copy link
Author

animation_nodes.

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

@derekcbr derekcbr reopened this Dec 23, 2022
@derekcbr
Copy link
Author

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?

@OmarEmaraDev
Copy link
Collaborator

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.

@derekcbr
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants