Skip to content

all: Move frozen modules to virtual directory. #8000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

andrewleech
Copy link
Contributor

Thie PR is for a fix created by @wnienhaus - I hope you don't mind me patching it and submitting it here (I needed to use it myself).
I've ammended it slightly to change the vpath from .frozen to |frozen to make it much harder to have a conflict with a real file/folder. I've also added it to the default path for the windows build. Other than that it's as per the original commits at wnienhaus@450d6d3 and 5559cbd which I've maintained the authorship of.

I've skipped 2918097 as it looks like it's doing more / enabling frozen where it wasn't previously?

I'm also interested in discussion / feedback about having the default position of the frozen import at the end of the search path. In general I think this is a sensible default, however it's different to the current behaviour where it's typically first.


This change "moves" frozen modules into a virtual directory
called "|frozen". This allows controlling the search order for
frozen modules, relative to other directories.

Before this change, frozen modules were found via the current
directory (i.e. the "" entry in sys.path). However, when a file
is executed from the command line the first entry in sys.path
(which is normally the empty string ""), is replaced by the base
path of the executing file (correct behavior as per CPython).
This made loading frozen modules fail.

With this change, frozen modules have their own entry in
sys.path, which also allows the user to control the order of
search when looking for frozen modules.

By default, the virtual "|frozen" directory is the last entry
in sys.path (i.e. it gets searched last).

Fixes issue #2322.

This change "moves" frozen modules into a virtual directory
called "|frozen". This allows controlling the search order for
frozen modules, relative to other directories.

Before this change, frozen modules were found via the current
directory (i.e. the "" entry in sys.path). However, when a file
is executed from the command line the first entry in sys.path
(which is normally the empty string ""), is replaced by the base
path of the executing file (correct behavior as per CPython).
This made loading frozen modules fail.

With this change, frozen modules have their own entry in
sys.path, which also allows the user to control the order of
search when looking for frozen modules.

By default, the virtual "|frozen" directory is the last entry
in sys.path (i.e. it gets searched last).

Fixes issue micropython#2322.
@andrewleech
Copy link
Contributor Author

Ah, for some reason I failed to see this was in fact submitted here already in #5057 so ignore me :-)

@wnienhaus
Copy link
Contributor

Very nice. Shows there is demand for this to be fixed 😄 .

The pipe is good as an "unlikely to ever be in a directory name" character, however on unix shells (also PowerShell) it represents the pipe, which is perhaps a bit unfortunate? (In my original PR I proposed {frozen}, because I also wanted something highly unlikely, but ended up changing it to .frozen because CircuitPython had already made that choice some time back).

@dpgeorge
Copy link
Member

Superseded by #8079.

@dpgeorge dpgeorge closed this Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants