Skip to content

Commit

Permalink
tests/cpydiff/core_import_split_ns_pkgs: Document split import.
Browse files Browse the repository at this point in the history
  • Loading branch information
smurfix committed Oct 8, 2023
1 parent c99666a commit dc88906
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/cpydiff/core_import_split_ns_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
categories: Core,import
description: MicroPython doesn't support namespace packages split across filesystem.
cause: MicroPython's import system is highly optimized for simplicity, minimal memory usage, and minimal filesystem search overhead.
workaround: Don't install modules belonging to the same namespace package in different directories. For MicroPython, it's recommended to have at most 3-component module search paths: for your current application, per-user (writable), system-wide (non-writable).
workaround: Not required.
"""
import sys

sys.path.append(sys.path[1] + "/modules")
sys.path.append(sys.path[1] + "/modules2")

import subpkg.foo
# import from the second subpackage first
import subpkg.bar
import subpkg.foo

print("Two modules of a split non-namespace package imported")

import subpkg
assert subpkg.one == 1
assert not hasattr(subpkg,"two")

print("Two modules of a split namespace package imported")
print("The first module's __init__ is used")
2 changes: 2 additions & 0 deletions tests/cpydiff/modules/subpkg/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Not a namespace package
one = 1
2 changes: 2 additions & 0 deletions tests/cpydiff/modules2/subpkg/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Not a namespace package
two = 2

0 comments on commit dc88906

Please sign in to comment.