Giter VIP home page Giter VIP logo

setuptools-cythonize's People

Contributors

anxuae avatar stefand986 avatar synapticarbors avatar tschoonj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

setuptools-cythonize's Issues

Issue with relative import of parent module

Hi,

I'm currently trying to use your module to cythonize one of my modules, but I get strange ImportErrors.
In order to demonstrate the problem, I have created a minimal example for Python 3.7 here: foobar.zip.

This is the basic folder structure:

.
├── setup.py
└── src
    └── foobar
        ├── __init__.py
        └── foo
            ├── __init__.py
            └── bar.py

The content of src/setup.py is:

from setuptools import setup, find_packages
from setuptools_cythonize import get_cmdclass

setup(
    cmdclass=get_cmdclass(),
    name="foobar",
    version="0.0.1",
    description="Test package",
    packages=find_packages(where="src"),
    package_dir={"foobar": "src/foobar"},
    python_requires="~=3.7"
)

The content of src/foobar/__init__.py is:

from .foo import foo1, foo2, foo3
from .foo.bar import bar1, bar2, bar3

The content of src/foobar/foo/__init__.py is:

from .. import foo
from .bar import bar1, bar2, bar3

foo1 = 1
foo2 = 2
foo3 = 3

The content of src/foobar/foo/bar.py is:

from .. import foo

bar1 = 10
bar2 = 20
bar3 = 30

A compiled package created with

python setup.py bdist --cythonize

gives the following error during import (some sensitive paths have been replaced with ...):

In [1]: import foobar
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-cc8dfa1d0002> in <module>
----> 1 import foobar

...\venv\lib\site-packages\foobar\__init__.py in <module>
      1
----> 2 from .foo import foo1, foo2, foo3
      3 from .foo.bar import bar1, bar2, bar3

...\venv\lib\site-packages\foobar\foo\__init__.py in <module>
      1
      2 from .. import foo
----> 3 from .bar import bar1, bar2, bar3
      4
      5 foo1 = 1

...\venv\lib\site-packages\foobar\foo\bar.cp37-win_amd64.pyd in init foobar.foo.bar()

ImportError: cannot import name foo

This is the output from the package creation (some sensitive paths have been replaced with ...):

running bdist_wheel
running build
running build_py
creating build
creating build\lib
creating build\lib\foobar
copying src\foobar\__init__.py -> build\lib\foobar
creating build\lib\foobar\foo
copying src\foobar\foo\__init__.py -> build\lib\foobar\foo
running build_ext
cythoning src\foobar\foo\bar.py to build\temp.win-amd64-3.7\Release\pyrex\foobar\foo\bar.c
creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release
creating build\temp.win-amd64-3.7\Release\pyrex
creating build\temp.win-amd64-3.7\Release\pyrex\foobar
creating build\temp.win-amd64-3.7\Release\pyrex\foobar\foo
building 'foobar.foo.bar' extension
creating build\temp.win-amd64-3.7\Release\build
creating build\temp.win-amd64-3.7\Release\build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release\build\temp.win-amd64-3.7\Release
creating build\temp.win-amd64-3.7\Release\build\temp.win-amd64-3.7\Release\pyrex
creating build\temp.win-amd64-3.7\Release\build\temp.win-amd64-3.7\Release\pyrex\foobar
creating build\temp.win-amd64-3.7\Release\build\temp.win-amd64-3.7\Release\pyrex\foobar\foo
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I...\venv\include -I...\Python\Python3x\include -I...\Python\Python3x\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /Tcbuild\temp.win-amd64-3.7\Release\pyrex\foobar\foo\bar.c /Fobuild\temp.win-amd64-3.7\Release\build\temp.win-amd64-3.7\Release\pyrex\foobar\foo\bar.obj
bar.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:...\venv\libs /LIBPATH:...\Python\Python3x\libs /LIBPATH:...\Python\Python3x /LIBPATH:...\venv\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64" /EXPORT:PyInit_bar build\temp.win-amd64-3.7\Release\build\temp.win-amd64-3.7\Release\pyrex\foobar\foo\bar.obj /OUT:build\lib\foobar\foo\bar.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.7\Release\build\temp.win-amd64-3.7\Release\pyrex\foobar\foo\bar.cp37-win_amd64.lib
   Creating library build\temp.win-amd64-3.7\Release\build\temp.win-amd64-3.7\Release\pyrex\foobar\foo\bar.cp37-win_amd64.lib and object build\temp.win-amd64-3.7\Release\build\temp.win-amd64-3.7\Release\pyrex\foobar\foo\bar.cp37-win_amd64.exp
Generating code
Finished generating code
installing to build\bdist.win-amd64\wheel
running install
running install_lib
creating build\bdist.win-amd64
creating build\bdist.win-amd64\wheel
creating build\bdist.win-amd64\wheel\foobar
creating build\bdist.win-amd64\wheel\foobar\foo
copying build\lib\foobar\foo\bar.cp37-win_amd64.pyd -> build\bdist.win-amd64\wheel\.\foobar\foo
copying build\lib\foobar\foo\__init__.py -> build\bdist.win-amd64\wheel\.\foobar\foo
copying build\lib\foobar\__init__.py -> build\bdist.win-amd64\wheel\.\foobar
running install_egg_info
running egg_info
creating foobar.egg-info
writing foobar.egg-info\PKG-INFO
writing dependency_links to foobar.egg-info\dependency_links.txt
writing top-level names to foobar.egg-info\top_level.txt
writing manifest file 'foobar.egg-info\SOURCES.txt'
reading manifest file 'foobar.egg-info\SOURCES.txt'
writing manifest file 'foobar.egg-info\SOURCES.txt'
Copying foobar.egg-info to build\bdist.win-amd64\wheel\.\foobar-0.0.1-py3.7.egg-info
running install_scripts
...\venv\lib\site-packages\wheel\bdist_wheel.py:82: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
  warn=(impl == 'cp')):
...t\venv\lib\site-packages\wheel\bdist_wheel.py:87: RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
  sys.version_info < (3, 8))) \
creating build\bdist.win-amd64\wheel\foobar-0.0.1.dist-info\WHEEL
creating 'dist\foobar-0.0.1-cp37-cp37m-win_amd64.whl' and adding 'build\bdist.win-amd64\wheel' to it
adding 'foobar/__init__.py'
adding 'foobar/foo/__init__.py'
adding 'foobar/foo/bar.cp37-win_amd64.pyd'
adding 'foobar-0.0.1.dist-info/METADATA'
adding 'foobar-0.0.1.dist-info/WHEEL'
adding 'foobar-0.0.1.dist-info/top_level.txt'
adding 'foobar-0.0.1.dist-info/RECORD'
removing build\bdist.win-amd64\wheel

This is the output from pip freeze:

backcall==0.2.0
colorama==0.4.5
Cython==0.29.32
decorator==5.1.1
foobar @ file:///.../dist/foobar-0.0.1-cp37-cp37m-win_amd64.whl
ipython==7.34.0
jedi==0.18.1
matplotlib-inline==0.1.6
parso==0.8.3
pickleshare==0.7.5
prompt-toolkit==3.0.31
Pygments==2.13.0
setuptools-cythonize==1.0.7
traitlets==5.5.0
wcwidth==0.2.5

On the other hand, the source package created with

python setup.py bdist

works just fine!?

Do you have any idea why the line from .. import foo in src/foobar/foo/bar.py is causing this error?

customizable cython options

Loving this package so far. However, finding the lack of customization a bit limiting.

Some cython_options appear to be hardcoded like

            # Embed source line position
            cython_options.embed_pos_in_docstring = True
            # Generate annotated HTML page for source files
            cython_options.annotate = False
            cython_options.fast_fail = True
            cython_options.error_on_unknown_names = True
            self.compile = self.optimize = False  # noqa

I can't see a proper way to customizing any options, either the ones hard coded or the ones left to cython default directive.

(Also as a side note module_name.startswith('__') does not only catch __init__.py but also e.g. __main__.py)

Cythonize install command

I have tried this package with success to make wheels. But I couldn't make it run for a local install, I mean python3 setup.py install --cythonize doesn't install it as a compiled library.

I can be interesting for performing local installations with Cython.

Cannot upload to pypi

I use python setup.py bdist --cythonize to generate a wheel file and the result is *-0.0.1-cp38-cp38-linux_x86_64.whl.

But unfortunately, this file cannot be uploaded to pypi directly:

INFO     Response from https://upload.pypi.org/legacy/:                                                                                                                             
         400 Binary wheel 'mypackage-0.0.1-cp38-cp38-linux_x86_64.whl' has an unsupported platform tag 'linux_x86_64'.                                                        
INFO     <html>                                                                                                                                                                     
          <head>                                                                                                                                                                    
           <title>400 Binary wheel 'mypackage-0.0.1-cp38-cp38-linux_x86_64.whl' has an unsupported platform tag 'linux_x86_64'.</title>                                       
          </head>                                                                                                                                                                   
          <body>                                                                                                                                                                    
           <h1>400 Binary wheel 'mypackage-0.0.1-cp38-cp38-linux_x86_64.whl' has an unsupported platform tag 'linux_x86_64'.</h1>                                             
           The server could not comply with the request since it is either malformed or otherwise incorrect.<br/><br/>                                                              
         Binary wheel &#x27;mypackage-0.0.1-cp38-cp38-linux_x86_64.whl&#x27; has an unsupported platform tag &#x27;linux_x86_64&#x27;.                                        
          </body>                                                                                                                                                                   
         </html>       

How can I convert this whl file to get it working?

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.