[Python-Dev] how to find the file path to an extension module at init time?
"Martin v. Löwis"
martin at v.loewis.de
Tue Nov 15 01:33:50 CET 2011
>> Currently, for Cython? I don't think that can work.
> Hmm, it might work to put an empty module next to the 'real' extension
> and to import it to figure out the common directory of both. As long as
> it's still there after installation and the right one gets imported,
> that is. A relative import should help on versions that support it.
> Although that won't help in the __init__ case because a relative import
> will likely depend on __path__ being available first. Chicken and egg...
If there was an actual __init__.py that just had
then __cinit__ could copy __path__ from the already-loaded __init__, no?
>> Certainly. An approach similar to _Py_PackageContext should be possible.
> Yes, and a "_Py_ModuleImportContext" would be rather trivial to do.
> Could that go into 3.3?
If somebody contributes a patch: sure.
> What about 2.7?
Certainly not. It would be a new feature, and there can't be new
features in 2.7.
> Could an exception be made there regarding new "features"?
> It's not likely to break anything, but it would help Cython.
"Not likely to break anything" really means it practice
"it probably will break somebody's code". Policies are
there to be followed, and this one I personally feel strongly
about. If it means that users can get certain Cython features
only with Python 3.x, the better.
More information about the Python-Dev