Hello all,
I have been working on an open source key value storage engine at
https://github.com/hse-project. As of right now the project only supports C. My current task is to create Python bindings for the project which will also be open sourced and published to PyPI when they are ready which should hopefully come with the 1.9/1.10 releases assuming I can fix the following issue.
This is my first time using Cython and I have been fairly impressed with it for the most part. Most of the process has been fairly straightforward. I have written most of the bindings correctly and tested them appropriately, so things are looking good. Right now the HSE public API is located here
https://github.com/hse-project/hse/tree/master/include/hse. There you will find a couple header files, most notably hse.h and hse_limits.h. I have modeled both of these into pyx and pxd files such that a mapping looks like:
hse.h -> hse/__init__.{pxd,pyx}
hse_limits.h -> hse/limits.{pxd,pyx}
In __init__.pyx, I have `cimport limits` so that I can use some of the constants in limits.pxd. Those references work great!
The goal of the bindings is essentially to have the top level hse module with limits as a submodule. When I go to install or even do an inplace build_ext, I can import the hse module successfully! Where I am running into issues however is when I try to import the hse.limits submodule. I have tried `import hse.limits` and `from hse import limits`. Both raise import errors for me. dir(hse) returns exactly what I would expect minus the submodule.
I am running out of ideas on how to fix this issue. When I install the module to --user, the tree looks like:
hse-1.9-py3.6-linux-x86_64.egg/
hse-1.9-py3.6-linux-x86_64.egg/hse.py
hse-1.9-py3.6-linux-x86_64.egg/EGG-INFO
hse-1.9-py3.6-linux-x86_64.egg/EGG-INFO/PKG-INFO
hse-1.9-py3.6-linux-x86_64.egg/EGG-INFO/SOURCES.txt
hse-1.9-py3.6-linux-x86_64.egg/EGG-INFO/dependency_links.txt
hse-1.9-py3.6-linux-x86_64.egg/EGG-INFO/native_libs.txt
hse-1.9-py3.6-linux-x86_64.egg/EGG-INFO/not-zip-safe
hse-1.9-py3.6-linux-x86_64.egg/EGG-INFO/top_level.txt
hse-1.9-py3.6-linux-x86_64.egg/__pycache__
hse-1.9-py3.6-linux-x86_64.egg/__pycache__/hse.cpython-36.pyc
hse-1.9-py3.6-linux-x86_64.egg/hse
hse-1.9-py3.6-linux-x86_64.egg/hse/limits.py
hse-1.9-py3.6-linux-x86_64.egg/hse/__pycache__
hse-1.9-py3.6-linux-x86_64.egg/hse/__pycache__/limits.cpython-36.pyc
which seems like a pretty good layout to me. Now when I start a Python 3.6 REPL, I can import hse appropriately.
>>> from hse import limits
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'limits
That is the issue I am running into. My setup.py looks like this:
import os
from setuptools import setup, Extension
# Distribute the generated C source files so that consumers don't necessarily
# need Cython on their system to build the extensions.
USE_CYTHON = os.environ.get("USE_CYTHON")
PROJECT_DIR = os.path.dirname(os.path.realpath(__file__))
extensions = [
Extension(
"hse",
[f"{PROJECT_DIR}/hse/__init__.{'pyx' if USE_CYTHON else 'c'}"],
libraries=["hse_kvdb"]
),
Extension(
"hse.limits",
[f"{PROJECT_DIR}/hse/limits.{'pyx' if USE_CYTHON else 'c'}"],
libraries=["hse_kvdb"]
)
]
cmdclass = {}
if USE_CYTHON:
from Cython.Build import cythonize
from Cython.Distutils import build_ext
extensions = cythonize(extensions, include_path=["hse"])
cmdclass["build_ext"] = build_ext
setup(
name="hse",
version="1.9",
maintainer="Micron Technology",
description="Python bindings to HSE's C API. " \
"HSE is an embeddable key-value store designed for SSDs based on NAND " \
"flash or persistent memory. HSE optimizes performance and endurance by " \
"orchestrating data placement across DRAM and multiple classes of SSDs " \
"or other solid-state storage. HSE is ideal for powering NoSQL, " \
"Software-Defined Storage (SDS), High-Performance Computing (HPC), " \
"Big Data, Internet of Things (IoT), and Artificial Intelligence (AI) " \
"solutions.",
license="Apache-2.0",
ext_modules=extensions,
packages=["hse", "hse.limits"],
cmdclass=cmdclass,
package_dir={"hse": f"{PROJECT_DIR}/hse", "hse.limits": f"{PROJECT_DIR}/hse"},
keywords="micron hse key value object store"
)
I don't really know how to fix my issue at all. If anyone here knows how to fix this issue, I would be eternally grateful.
Thanks,
Tristan Partin