msg136055 - (view) |
Author: Josh Triplett (joshtriplett) |
Date: 2011-05-15 23:45 |
Even if pyconfig.h defines DONT_HAVE_STAT and DONT_HAVE_FSTAT (which prevents the definitions of HAVE_STAT and HAVE_FSTAT), Python still references fstat in Python/import.c, along with struct stat and constants like S_IXUSR. I ran into this when attempting to compile Python for an embedded platform, which has some basic file operations but does not have stat. (I will likely end up faking fstat for now, but I'd rather not have to do so.) |
|
|
msg136065 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2011-05-16 03:28 |
Oh, so it's possible to not have the fstat() syscall. I asked me the question when I modified import.c (and other files related to importing a module). |
|
|
msg136937 - (view) |
Author: Petri Lehtinen (petri.lehtinen) *  |
Date: 2011-05-26 10:54 |
Should the .pyc/.pyo file writing be disabled altogether if stat() and/or fstat() is not available. In this case, there's no way to check mtimes, right? |
|
|
msg136943 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2011-05-26 11:29 |
Does your filesystem store the modification time? Why don't you have/want fstat()? Do you have stat() or a similar function? |
|
|
msg137059 - (view) |
Author: Josh Triplett (joshtriplett) |
Date: 2011-05-27 15:21 |
GRUB's filesystem drivers don't support reading mtime. And no, no form of stat() function exists, f or otherwise. On a related note, without HAVE_STAT, import.c can't import package modules at all, since it uses stat to check in advance for a directory. In the spirit of Python's usual "try it and see if it works" approach, why not just try opening foo/__init__.py, and if that doesn't work try opening foo.py? |
|
|
msg137296 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2011-05-30 15:38 |
> Should the .pyc/.pyo file writing be disabled altogether > if stat() and/or fstat() is not available. If we cannot get the file modification time, .pyc/.pyo writing must be disabled. If your OS/libc/filesystem doesn't have fstat(), you don't have file modification, so no .pyc/.pyo write. |
|
|
msg137319 - (view) |
Author: Petri Lehtinen (petri.lehtinen) *  |
Date: 2011-05-30 18:50 |
STINNER Victor wrote: > If we cannot get the file modification time, .pyc/.pyo writing must be disabled. If your OS/libc/filesystem doesn't have fstat(), you don't have file modification, so no .pyc/.pyo write. Should I go on and write a patch? Any hints on how this code path (of not writing .pyc/.pyo because of missing stat() and fstat()) could be tested? |
|
|
msg137323 - (view) |
Author: Josh Triplett (joshtriplett) |
Date: 2011-05-30 20:09 |
Given that GRUB doesn't support writing to filesystems at all, I already have to set Py_DontWriteBytecodeFlag, so disabling .pyc/.pyo entirely would work fine for my use case. |
|
|
msg137324 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2011-05-30 20:12 |
> Should I go on and write a patch? Yes please, write a patch, I will review it. To emulate a system without stat or fstat, you may use: #define fstat dont_have_fstat #define stat dont_have_stat The link will fail if the code still refer to fstat() or stat(). |
|
|
msg137358 - (view) |
Author: Petri Lehtinen (petri.lehtinen) *  |
Date: 2011-05-31 11:52 |
I tried to compile Python 3.3 (from default branch) with DONT_HAVE_FSTAT and DONT_HAVE_STAT. It seems to depend even more heavily on stat() being available, in other files than Python/import.c. With 2.7, it was quite easy to disable the .pyc/.pyo writing in the absence of fstat(), but the NullImporter needs to be able to check for a directory. In addition, the build process fails when trying to run "setup.py build", because distutils cannot be imported. And it cannot be imported because it's a package, and packages (directories) cannot be detected without having stat(). So... Unless we have another way to check for a directory, I'm not sure whether it will be possible to compile Python at all without stat(). |
|
|
msg137364 - (view) |
Author: Josh Triplett (joshtriplett) |
Date: 2011-05-31 15:23 |
Rather than checking for a directory, how about just opening foo/__init__.py, and if that fails opening foo.py? |
|
|
msg137365 - (view) |
Author: Petri Lehtinen (petri.lehtinen) *  |
Date: 2011-05-31 15:30 |
The NullImporter is documented to raise ImportError on directories, not directories containing __init__.py: http://docs.python.org/library/imp.html#imp.NullImporter Checking for __init__.py{,c,o} seems doable to me without having stat(). |
|
|
msg175269 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2012-11-10 09:43 |
My vote is for won't fix. Systems without stat() or fstat() are clearly broken from Python's point of view; at the very least, they aren't POSIX-compliant. |
|
|
msg175418 - (view) |
Author: Petri Lehtinen (petri.lehtinen) *  |
Date: 2012-11-12 06:42 |
Should the defines be removed then, because they're kind of false promises for the user. |
|
|
msg175464 - (view) |
Author: Chromatix (chromatix) |
Date: 2012-11-12 18:47 |
Actually many people try to compile python on an environment with freestanding C library, so this can be a specific case of that. Is there any issue or thread where compiling python with freestanding headers is discussed? As this relates to that. Shall you remove the defines, please put instructions in the source code to let user know how they can provide their self-invented fstat function to the code. |
|
|
msg189582 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2013-05-19 12:21 |
For those of you who are concerned with this issue, could you explain your use case on the following discussion thread: http://mail.python.org/pipermail/python-dev/2013-May/126285.html ? I would personally like to remove HAVE_FSTAT and make Python unconditionally use fstat(). It will make the code quite simpler in some places. |
|
|