[Solved] import stat failure

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
zitt
Posts: 6
Joined: Thu Mar 25, 2021 11:40 pm

[Solved] import stat failure

Post by zitt » Thu Mar 25, 2021 11:53 pm

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?
Last edited by zitt on Wed Apr 07, 2021 5:09 am, edited 1 time in total.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: import stat failure

Post by Roberthh » Fri Mar 26, 2021 7:09 am

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?

zitt
Posts: 6
Joined: Thu Mar 25, 2021 11:40 pm

Re: import stat failure

Post by zitt » Sat Mar 27, 2021 2:10 am

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.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: import stat failure

Post by Roberthh » Sat Mar 27, 2021 6:34 am

Just look at the result of the command dir() in REPL.

zitt
Posts: 6
Joined: Thu Mar 25, 2021 11:40 pm

Re: import stat failure

Post by zitt » Wed Apr 07, 2021 5:06 am

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 2294 times

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: [Solved] import stat failure

Post by stijn » Wed Apr 07, 2021 6:06 am

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)..

zitt
Posts: 6
Joined: Thu Mar 25, 2021 11:40 pm

Re: [Solved] import stat failure

Post by zitt » Thu Apr 08, 2021 6:28 am

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.

Post Reply