8000 unix/main: Insert script base dir into sys.path rather than replace existing entry. by andrewleech · Pull Request #8006 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

unix/main: Insert script base dir into sys.path rather than replace existing entry. #8006

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

Conversation

andrewleech
Copy link
Contributor

This directly addresses issue #2322 in that it preserve the existing empty path entry at the start of sys.path which currently acts as frozen import path.

This is a more minimal fix than renaming the import path for frozen in #5057

However, I am personally still very much in support of #5057 being included as well as this change, using the empty path for frozen can be quite confusing to new users; giving it something explicit is worthwhile in my opinion.

This fix also applies to the windows port.

@wnienhaus
Copy link
Contributor

This would work to actually manage to import frozen modules, however it would change how MicroPython behaves compared to CPython. (Not sure how much this matters in practice, but I think there is a desire to keep behaviours the same where possible.)

I looked into how MicroPython and CPython compare in this regard some time ago: https://gist.github.com/wnienhaus/65727fff5f4954d0e9418ffeaf9bbb6d (as part of commenting on #3509). I believe TEST4 and TEST5 in the Gist are what is relevant to this change.

This allows any frozen code to still be found with existing empty entry.
Also applies to windows port.

Addresses issue micropython#2322
@andrewleech
Copy link
Contributor Author

Ah, this PR also triggers a version of the upip issue I was trying to fix in #7536

upip by default looks in sys.path[1] for the directory to install modules into - with this PR that will be the frozen empty string if you run upip from script, eg, micropython ./tools/upip.py install micropython-os.

If upip is frozen into micropython then it should work with this change as in the default unix build sys.path[1] will be ~/.micropython/lib

@dpgeorge
Copy link
Member

@andrewleech is this still relevant now that we have .frozen 86ce442?

@andrewleech
Copy link
Contributor Author

Sorry yes I meant to close this one with a reference to that!

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

Successfully merging this pull request may close these issues.

4 participants
0