Skip to content

Question about overriding frozen source modules #1804

Closed

Description

@dhylands

When you build a firmware image that has some frozen module (say foo), and you provide a foo.py on the local filesystem, import foo still imports the internal one.

Normally you can control whether your module or a system module gets imported by manipulating sys.path, but for frozen modules there doesn't seem to be any choice.

The best I've come up with so far is to have the file be called foo2 and do import foo2 as foo. Then since foo is already loaded further imports of foo will just return that.

So I was just looking to find out if having the frozen foo.py take precedence was the intention or not.

Activity

  1. pfalcon commented on Jan 28, 2016

    @pfalcon
    Contributor

    So I was just looking to find out if having the frozen foo.py take precedence was the intention or not.

    Not really. It was done "for efficiency" (not hit disk I/O if it can be found internally). I agree that overriding usecase makes sense. Well, I guess ideal solution is to make order configurable.

  2. sarusso commented on Nov 28, 2016

    @sarusso

    Any news on this? In my case using a different name for the module I want to "override" is really not an option.. @pfalcon could you point me to the source code file/lines where the "not hit disk I/O if it can be found internally" decision is made?

  3. dpgeorge commented on Nov 29, 2016

    @dpgeorge
    Member

    Any news on this?

    There has been no progress on this. If you want to have a go, you'll need to swap the order of lookup in py/builtinimport.c:mp_import_stat_any, and then the order of import in the do_load function in the same file.

  4. added a commit that references this issue on Apr 16, 2019
  5. dpgeorge commented on Dec 17, 2021

    @dpgeorge
    Member

    The order is now configurable by using .frozen, see 86ce442

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions