Page 1 of 1

[Solved] import stat failure

Posted: Thu Mar 25, 2021 11:53 pm
by zitt
As a fairly experienced python scripter; I've hit a roadblock which I can't get past / figure out.

I'm using an out-of-date version of micropython compiled for UEFI (https://github.com/tianocore/tianocore. ... k-for-UEFI) v.1.9.4 (2018-07-30). I attempted to compile for V1.10 - but it fails.

So; I compiled the micropython framework using the instructions at that page and did a quick helloworld... but now that I'm actually trying to use it; a very simple example fails.

I downloaded upip's stat.py from:
https://github.com/micropython/micropyt ... aster/stat

and put it on my filesystem at libs\.

using micropython.efi -i I manually typed the following commands in micropython prompt:

Code: Select all

import sys
sys.path.append('libs')
import stat
dir(stat)
The last line returns:

Code: Select all

['__class__', '__name__', '__path__']
which is incomplete. None of the functions have been imported... which explains why I can't call S_ISDIR() from my normal script.

If I do the same thing on the linux port:

Code: Select all

['__class__', '__name__', '__file__', 'ST_MODE', 'ST_INO', 'ST_DEV', 'ST_NLINK', 'ST_UID', 'ST_GID', 'ST_SIZE', 'ST_ATIME', 'ST_MTIME', 'ST_CTIME', 'S_IMODE', 'S_IFMT', 'S_IFDIR', 'S_IFCHR', 'S_IFBLK', 'S_IFREG', 'S_IFIFO', 'S_IFLNK', 'S_IFSOCK', 'S_ISDIR', 'S_ISCHR', 'S_ISBLK', 'S_ISREG', 'S_ISFIFO', 'S_ISLNK', 'S_ISSOCK', 'S_ISUID', 'S_ISGID', 'S_ENFMT', 'S_ISVTX', 'S_IREAD', 'S_IWRITE', 'S_IEXEC', 'S_IRWXU', 'S_IRUSR', 'S_IWUSR', 'S_IXUSR', 'S_IRWXG', 'S_IRGRP', 'S_IWGRP', 'S_IXGRP', 'S_IRWXO', 'S_IROTH', 'S_IWOTH', 'S_IXOTH', 'UF_NODUMP', 'UF_IMMUTABLE', 'UF_APPEND', 'UF_OPAQUE', 'UF_NOUNLINK', 'UF_COMPRESSED', 'UF_HIDDEN', 'SF_ARCHIVED', 'SF_IMMUTABLE', 'SF_APPEND', 'SF_NOUNLINK', 'SF_SNAPSHOT', '_filemode_table', 'filemode']
which is expected behavior.

What am I doing wrong?

Re: import stat failure

Posted: Fri Mar 26, 2021 7:09 am
by Roberthh
Cannot replicate. I tried to load & import stat.py here, and it work as expected. Are you sure that stat does not exist before you import it?

Re: import stat failure

Posted: Sat Mar 27, 2021 2:10 am
by zitt
Roberthh wrote:
Fri Mar 26, 2021 7:09 am
Are you sure that stat does not exist before you import it?
Can you be specific?
globals() does not return stat as an option.

Re: import stat failure

Posted: Sat Mar 27, 2021 6:34 am
by Roberthh
Just look at the result of the command dir() in REPL.

Re: import stat failure

Posted: Wed Apr 07, 2021 5:06 am
by zitt
Thanks for your attention on this matter.
You couldn't reproduce because I had a screwed up environment... well specifically; a weird environment which micropython should have given me a error or something.

I had two copies of stat in my 'lib' folder - probably due to specific some upip weirdness.
Basically I had 'stat.py' in the stat directory of libs and 'stat.py' in the root of libs.

Once I removed the stat directory; it started working properly.
For some reason the same thing happen with glob... it's unclear why.
dupLibs.png
dupLibs.png (12.36 KiB) Viewed 2435 times

Re: [Solved] import stat failure

Posted: Wed Apr 07, 2021 6:06 am
by stijn
Seems to follow standard Python import rules, so I don't think MicroPython should warn about it; it's just going to import the first one it sees and not even look further. It can be annoying though, and many many hours have been wasted on this (not just Python: it started with include files in C already which follow the same principle)..

Re: [Solved] import stat failure

Posted: Thu Apr 08, 2021 6:28 am
by zitt
stijn wrote:
Wed Apr 07, 2021 6:06 am
it's just going to import the first one it sees and not even look further.
Can't be 100% sure that is what happened since a dir(stat) only seemed to report "built-in" information.
It wouldn't provide any of the methods of the file.

If I run into this again; I'll try to make better observations.