How To Use Setuptools Packages And Ext_modules With The Same Name?
Solution 1:
You cannot. The first one imported wins. You cannot have scripts/modules/packages/extensions with the same name — one overrides all others.
But you can to have one inside another. Make your extension named fastfilepackage.fastfilepackage
and you can import fastfilepackage
to import the Python package and import fastfilepackage.fastfilepackage
to import the extension; or from fastfilepackage import fastfilepackage
.
Solution 2:
As a final solution, I completely removed all Python *.py
code because they caused the C Extensions code to become 30% slower. Now my setup.py
become like this:
from setuptools import setup, Extension
setup(
name = 'fastfilepackage',
version = '0.1.1',
ext_modules = [
Extension(
name = 'fastfilepackage',
sources = [
'source/fastfile.cpp',
],
include_dirs = ['source'],
)
],
)
File structure:
.
├── setup.py
├── MANIFEST.in
├── README.md
├── LICENSE.txt
└── source
├── fastfile.cpp
└── version.h
MANIFEST.in
include README.md
include LICENSE.txt
recursive-include source *.h
This is the installed file structure: (No *.py
files anywhere = 100% performance)
.
└── dist-packages
├── fastfilepackage-0.1.1.dist-info
│ ├── INSTALLER
│ ├── LICENSE.txt
│ ├── METADATA
│ ├── RECORD
│ ├── top_level.txt
│ └── WHEEL
└── fastfilepackage.cpython-36m-x86_64-linux-gnu.so
I just replaced the version.py
directly by a C Extensions module attribute:
// https://docs.python.org/3/c-api/arg.html#c.Py_BuildValueconstchar* __version__ = "0.1.1";
PyObject_SetAttrString( thismodule, "__version__", Py_BuildValue( "s", __version__ ) );
References:
Post a Comment for "How To Use Setuptools Packages And Ext_modules With The Same Name?"