[Python-Dev] how to find the file path to an extension module at init time? (original) (raw)
Stefan Behnel stefan_ml at behnel.de
Mon Nov 14 09🔞33 CET 2011
- Previous message: [Python-Dev] how to find the file path to an extension module at init time?
- Next message: [Python-Dev] how to find the file path to an extension module at init time?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Martin v. Löwis", 13.11.2011 21:46:
I'm asking specifically because I'd like to properly implement file in Cython modules at module init time. Why do you need to implement file? Python will set it eventually to its correct value, no?
Well, yes, eventually. However, almost all real world usages are at module init time, not afterwards. So having CPython set it after running through the module global code doesn't help much.
Another problem is that package local imports from init.py no longer work when it's compiled Does it actually work to have init be an extension module?
I'm just starting to try it, and the problems I found so far were file (in general), path and relative imports (specifically).
Any ideas how this could currently be achieved? 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...
Support in CPython would definitely help.
Or could this become a new feature in the future? Certainly. An approach similar to PyPackageContext should be possible.
Yes, and a "_Py_ModuleImportContext" would be rather trivial to do. Could that go into 3.3? What about 2.7? Could an exception be made there regarding new "features"? It's not likely to break anything, but it would help Cython.
Stefan
- Previous message: [Python-Dev] how to find the file path to an extension module at init time?
- Next message: [Python-Dev] how to find the file path to an extension module at init time?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]