pythonsetup.pypython-wheelcythonize

Cythonize installs .so files to wrong location


I'd like to ask a question about how to configure setup.py with Cython, setuptools extensions etc. I'm trying cythonize a submodule with Cython.Distutils's build_ext. But the issue isn't Cython.Distutils's Extentsion module, (if it exists) because it isn't loaded. Only build_ext. So I create a setuptools.extension Extension in a list, and then cythonize the list of Extension objects. There's only one Extension in the list, an its as follows.

Extension("distance", ["kmerdb/distance.pyx"], include_dirs=[np.get_include()])

I've tried different methods of installation, from python setup.py install to pip install -e . to generating the wheel file and installing the wheel. I couldn't find anything that worked...

Okay, so I know very little about the process and that's probably why I am getting hung up but I've searched the whole site, no luck. So here goes.

I'm running the following shell script to install my package locally, and it works fine. The problem is the installation doesn't move the .so and the .py file into the kmerdb module I'm trying to export. Any suggestions? Thanks

>python setup.py sdist bdist_wheel
>/bin/auditwheel repair --plat manylinux2014_x86_64 dist/kmerdb-*linux_x86_64.whl
>mv wheelhouse/* dist
>rm dist/*linux_x86_64.whl
>pip install dist/kmerdb-*-manylinux2014_x86_64.whl
>ls ~/.pyenv/versions/kdb/lib/python3.10/site-packages/kmerdb-0.6.5-py3.10-linux-x86_64.egg/
distance.cpython-310-x86_64-linux-gnu.so    distance.py    kmerdb    ...

Again, the files distance.cpython-310-x86_64-linux-gno.so is not moved into the kmerdb module, my Python packages, which I'm trying to install locally and configure for .whl upload to PyPI.

Python 3.10.1 (main, Jan  1 2022, 21:28:19) [GCC 11.1.0] on linux
Cython==0.29.26

setup.py


    Extension("distance", ["kmerdb/distance.pyx"], include_dirs=[np.get_include()], define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],),
    setup(
        name=NAME,
        version=VERSION,
        description=DESCRIPTION,
        long_description=long_description,
        long_description_content_type='text/markdown',
        author=AUTHOR,
        author_email=EMAIL,
        python_requires=REQUIRES_PYTHON,
        url=URL,
        download_url=CURRENT_RELEASE,
        keywords = ["k-mer", "kmer", "k-merdb", "kmerdb", "kdb"],
        classifiers=[
            "Development Status :: 1 - Planning",
            "Intended Audience :: Developers",
            "Intended Audience :: Science/Research",
            "Operating System :: OS Independent",
            "Programming Language :: Python",
            "Programming Language :: Python :: 3",
            "Programming Language :: Python :: 3.6",
            "Programming Language :: Python :: 3.7",
            "Programming Language :: Python :: 3.8",
            "Programming Language :: Python :: 3.9",
            "Programming Language :: Python :: 3.10",
            "Topic :: Scientific/Engineering",
            "Topic :: Scientific/Engineering :: Bio-Informatics",
            "Topic :: Software Development :: Libraries :: Python Modules",
        ],
        packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
        package_dir={'kmerdb': 'kmerdb'},
        package_data={'kmerdb': ['CITATION']},
        # If your package is a single module, use this instead of 'packages':
        #py_modules=['kmerdb'],
        #scripts=['bin/kmerdb', 'bin/kmerdb_report.R'],
        entry_points={
            'console_scripts': ['kmerdb=kmerdb:cli'],
        },
        install_requires=REQUIRED,#['Cython==0.29.21', 'numpy==1.18.1'],
        extras_require=EXTRAS,
        include_package_data=True,
        license='GPLv3+',
        test_suite='test',
        #    tests_require=['mamba', 'expect'],
        ext_modules=cythonize(extensions),
        library_dirs=["."],
        zip_safe=False,
    )

Solution

  • I'm going to self answer here. The issue stemmed from an improperly specified Extension.

        Extension("kmerdb.distance", ["kmerdb/distance.pyx"], include_dirs=[np.get_include()])
    

    All I had to do was include the module name for the fully specified submodule hierarchy. Fixed it!