GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [WASI] test cases with sys.path.insert(0, os.curdir) fail on WASI · Issue #93461 · python/cpython

[WASI] test cases with sys.path.insert(0, os.curdir) fail on WASI #93461

New issue
Copy link
New issue
Copy link
Closed
Closed
[WASI] test cases with sys.path.insert(0, os.curdir) fail on WASI#93461
Copy link
Assignees
brettcannon
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixestopic-importlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@tiran
tiran
opened on Jun 3, 2022
Issue body actions

Bug report

Test cases that insert os.curdir ('.') into sys.path fail on WASI platforms. I think it is related how wasmtime maps directories into the runtime environment and how it sets up the current working directory. The test passes if I replace '.' with an empty string '' or remove the cached FileFinder instance for '.' with sys.path_importer_cache.pop('.').

 ./test-wasi.sh test_support -m test_forget
0:00:00 Run tests sequentially
0:00:00 [1/1] test_support
test test_support failed -- Traceback (most recent call last):
  File "/Lib/test/test_support.py", line 116, in test_forget
    mod = __import__(TESTFN)
          ^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '@test_66600_tmpæ'

test_support failed (1 error)

== Tests result: FAILURE ==

The culprit seems to be an outdated FileFinder instance: {'.': FileFinder('/.')}. The CWD is '/python-wasm/cpython/builddir/wasi/build/test_python_66600æ' when the test case is executed.

0:00:00 [1/1] test_support
> /Lib/test/test_support.py(114)test_forget()
-> sys.path.insert(0, os.curdir)
(Pdb) p sys.path
['.', '/usr/local/lib/python312.zip', '/Lib', '/build/lib.wasi-wasm32-3.12']
(Pdb) pp sys.path_importer_cache
{'.': FileFinder('/.'),
 '/Lib': FileFinder('/Lib'),
 '/Lib/collections': FileFinder('/Lib/collections'),
 '/Lib/encodings': FileFinder('/Lib/encodings'),
 '/Lib/importlib': FileFinder('/Lib/importlib'),
 '/Lib/re': FileFinder('/Lib/re'),
 '/Lib/test': FileFinder('/Lib/test'),
 '/Lib/test/libregrtest': FileFinder('/Lib/test/libregrtest'),
 '/Lib/test/support': FileFinder('/Lib/test/support'),
 '/Lib/unittest': FileFinder('/Lib/unittest'),
 '/Lib/urllib': FileFinder('/Lib/urllib'),
 '/build/lib.wasi-wasm32-3.12': FileFinder('/build/lib.wasi-wasm32-3.12'),
 '/usr/local/lib/python312.zip': None}
(Pdb) p os.getcwd()
'/python-wasm/cpython/builddir/wasi/build/test_python_66600æ'
(Pdb) n
> /Lib/test/test_support.py(115)test_forget()
-> importlib.invalidate_caches()
(Pdb) n
> /Lib/test/test_support.py(116)test_forget()
-> try:
(Pdb) p sys.path
['.', '.', '/usr/local/lib/python312.zip', '/Lib', '/build/lib.wasi-wasm32-3.12']
(Pdb) pp sys.path_importer_cache
{'.': FileFinder('/.'),
 '/Lib': FileFinder('/Lib'),
 '/Lib/collections': FileFinder('/Lib/collections'),
 '/Lib/encodings': FileFinder('/Lib/encodings'),
 '/Lib/importlib': FileFinder('/Lib/importlib'),
 '/Lib/re': FileFinder('/Lib/re'),
 '/Lib/test': FileFinder('/Lib/test'),
 '/Lib/test/libregrtest': FileFinder('/Lib/test/libregrtest'),
 '/Lib/test/support': FileFinder('/Lib/test/support'),
 '/Lib/unittest': FileFinder('/Lib/unittest'),
 '/Lib/urllib': FileFinder('/Lib/urllib'),
 '/build/lib.wasi-wasm32-3.12': FileFinder('/build/lib.wasi-wasm32-3.12'),
 '/usr/local/lib/python312.zip': None}

A build on Linux has an absolute path to build directory as first sys.path entry.

reproducer

$ podman run --rm -ti -v $(pwd):/python-wasm/cpython:Z quay.io/tiran/cpythonbuild:emsdk3
# ./build-python-build.sh
# ./build-python-wasi.sh
# ./test-wasi.sh test_support -m test_forget

Activity

  1. tiran
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    3.11only security fixesonly security fixes
    3.12only security fixesonly security fixes
    on Jun 3, 2022
  2. tiran
    assigned
    brettcannon
    on Jun 3, 2022
  3. brettcannon
    added
    topic-importlib
    on Jun 3, 2022
  4. tiran
    added a commit that references this issue on Jun 9, 2022

    pythongh-93461: Invalidate sys.path_importer_cache entries with relat…

    983288b
  5. tiran commented on Jun 9, 2022

    @tiran
    tiran
    on Jun 9, 2022
    MemberAuthor
    More actions

    GH-93461 is the simplest solution I could come up with. importlib.invalidate_caches now drops all FileFinder instances if the cache key is not an absolute path.

    Reacted by Brett Cannon
  6. brettcannon commented on Jun 9, 2022

    @brettcannon
    brettcannon
    on Jun 9, 2022
    Member
    More actions

    Seems like a reasonable solution to the problem.

    Reacted by Christian Heimes
  7. ambv
    added a commit that references this issue on Jun 10, 2022

    gh-93461: Invalidate sys.path_importer_cache entries with relative pa…

    09243b8
  8. miss-islington
    added 2 commits that reference this issue on Jun 10, 2022

    pythongh-93461: Invalidate sys.path_importer_cache entries with relat…

    163891f

    gh-93461: Invalidate sys.path_importer_cache entries with relative pa…

    3d1c080
  9. brettcannon commented on Jun 17, 2022

    @brettcannon
    brettcannon
    on Jun 17, 2022
    Member
    More actions

    @tiran can this be closed?

  10. tiran commented on Jun 17, 2022

    @tiran
    tiran
    on Jun 17, 2022
    MemberAuthor
    More actions

    Yes, it is fixed now.

  11. tiran
    closed this as completedon Jun 17, 2022
  12. tiran
    closed this as completedon Jun 19, 2022
  13. serhiy-storchaka
    added a commit that references this issue on Jun 26, 2022

    Revert 30935 defer bpo45162 to 312 (#94285)

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

Metadata

Metadata

Assignees

  • @brettcannon
    brettcannon

Labels

3.11only security fixesonly security fixes3.12only security fixesonly security fixestopic-importlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.