Skip to content

How to create a Python extension with multiple files? #647

@sk-uma

Description

@sk-uma

Hi! Thanks for the great project.

I'm trying to create a Python package using Codon. I've written a small example that uses multiple files, but I'm confused about how to build it correctly.

Here's my file structure:

mymodule/
├── __init__.py
└── main.py
setup.py

__init__.py

from .main import MyClass, ack
print("Hello, Codon! in __init__.py")

main.py

print("Hello, Codon! in main.py")

@dataclass(python=True)
class MyClass:
    def __init__(self):
        print("MyClass initialized")

    def say_hello(self):
        print("Hello, Codon!")

def ack(m: int, n: int) -> int:
    if m == 0:
        return n + 1
    elif n == 0:
        return ack(m - 1, 1)
    else:
        return ack(m - 1, ack(m, n - 1))

I followed the documentation and created a setup.py that builds the extension using Codon.
However, when I try to import MyClass or ack, I get an ImportError. It seems that only the file specified in the extension (__init__.py) is being compiled.

What's the proper way to build a Codon-based Python extension that includes multiple files?

The full example is here:
👉 https://github.com/sk-uma/codon-pyext-example

Thanks in advance for any help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions