Multiple directories with modules of a single package

42 Views Asked by At

I develop a Python package. Part of its modules are built via Cython. The project tree is following

.
├── cysrc
│   ├── aaa.py
│   └── bbb.py
├── pkg
│   ├── __init__.py
│   ├── ccc.py
│   └── ddd.py
└── setup.py

Modules in the cysrc folder goes through cythonization and compilation and ends up as *.so files in the wheel and in the installation. Modules in the pkg folder are installed as-is (as usual Python modules).

The key lines of the setup.py file:

cy_modules = [m[:-3] for m in glob('*.py', root_dir='cysrc')] # remove extension
extensions = [Extension('mypackage.{m}', [f'cysrc/{m}.py']) for m in cy_modules]
ext_modules = cythonize(extensions, build_dir='build', compiler_directives=compiler_directives,  annotate=True)


setup(name='MyPackage',
    packages=['mypackage'],
    package_dir={'mypackage':'pkg'},
    ext_modules = ext_modules,
    )

Sometimes I need to install this package without cythonization/compilation of sources in cysrc. For example for usage with converage.py or for an editable installation.

Currently I just move files form cysrc to pkg and back when I need it. Is there more convenient way to do it?

0

There are 0 best solutions below