Do we need port some extension modules to the modules directory?
Hi, I notice some modules not in modules directory(for example: _warnings、marshal in python directory). Do we need port those modules to modules directory? Sorry for my noisy info. Bests Wishs, Hai Shi
I notice some modules not in modules directory(for example: _warnings、marshal in python directory). Do we need port those modules to modules directory?
I strongly suspect the answer is "no." Modules which aren't in the Modules directory are built directly into the Python executable. Using your example of the _warnings module, note that in Makefile.pre.in Python/_warnings.o is listed in the PYTHON_OBJS list (as are Python/sysmodule.o and Python/marshal.o). This is evidence they are built directly into the interpreter itself. Another is that at runtime those modules have no __file__ attribute:
import marshal marshal.__file__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'marshal' has no attribute '__file__' import sys sys.__file__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'sys' has no attribute '__file__' import _warnings _warnings.__file__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module '_warnings' has no attribute '__file__'
Skip
Skip Montanaro wrote:
I notice some modules not in modules directory(for example: _warnings、marshal in python directory). Do we need port those modules to modules directory?
I strongly suspect the answer is "no." Modules which aren't in the Modules directory are built directly into the Python executable. Using your example of the _warnings module, note that in Makefile.pre.in Python/_warnings.o is listed in the PYTHON_OBJS list (as are Python/sysmodule.o and Python/marshal.o). This is evidence they are built directly into the interpreter itself. Another is that at runtime those modules have no __file__ attribute: import marshal marshal.__file__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'marshal' has no attribute '__file__' import sys sys.__file__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'sys' has no attribute '__file__' import _warnings _warnings.__file__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module '_warnings' has no attribute '__file__' Skip
Hi, skip, Thank you for your replay. IMHO, it's because those module is builtinmodules, so they have no __file__ attribute and listed in PYTHON_OBJS(I am not sure I understand clearly). But I have no clear criteria what module should be putted in python directory or modules directory. I found some core developer have mentioned this detail 13 years ago(https://bugs.python.org/issue1631171). Best Wishs, Hai Shi
On Sun, Apr 12, 2020 at 8:36 AM Hai Shi <shihai1992@gmail.com> wrote:
I notice some modules not in modules directory(for example: _warnings、marshal in python directory). Do we need port those modules to modules directory?
FWIW, this is something I've been meaning to look at for a while and is relatively high on my "back burner" [1] TODO list. :) Not only do we have some "extension" modules defined in Python/, but we also have some core runtime functionality defined in the Modules/ directory (e.g. in gcmodule.c). In practice neither has been a problem over the years. However, it does make discovery a bit more complicated, both for new contributors and for tools. So I consider it at the least worth looking into the value (and downsides, if any) of moving the seemingly out-of-place pieces to the appropriate locations. Anyway, I haven't looked at this super closely (and likely won't for a while), so at this point the above is mostly just my gut reaction. Take it for what it's worth. :) -eric [1] as in "on the back burner of the stove"
Eric Snow wrote:
In practice neither has been a problem over the years. However, it does make discovery a bit more complicated, both for new contributors and for tools. So I consider it at the least worth looking into the value (and downsides, if any) of moving the seemingly out-of-place pieces to the appropriate locations.
Hi, Eric, Thank you for your speedy reply. You put my thoughts into words ;)
participants (3)
-
Eric Snow
-
Hai Shi
-
Skip Montanaro