Title: [WASI] test cases with sys.path.insert(0, os.curdir) fail on WASI · Issue #93461 · python/cpython · GitHub
Open Graph Title: [WASI] test cases with sys.path.insert(0, os.curdir) fail on WASI · Issue #93461 · python/cpython
X Title: [WASI] test cases with sys.path.insert(0, os.curdir) fail on WASI · Issue #93461 · python/cpython
Description: 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...
Open Graph Description: 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 curre...
X Description: 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 t...
Opengraph URL: https://github.com/python/cpython/issues/93461
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[WASI] test cases with sys.path.insert(0, os.curdir) fail on WASI","articleBody":"**Bug report**\r\n\r\nTest 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('.')``.\r\n\r\n```\r\n ./test-wasi.sh test_support -m test_forget\r\n0:00:00 Run tests sequentially\r\n0:00:00 [1/1] test_support\r\ntest test_support failed -- Traceback (most recent call last):\r\n File \"/Lib/test/test_support.py\", line 116, in test_forget\r\n mod = __import__(TESTFN)\r\n ^^^^^^^^^^^^^^^^^^\r\nModuleNotFoundError: No module named '@test_66600_tmpæ'\r\n\r\ntest_support failed (1 error)\r\n\r\n== Tests result: FAILURE ==\r\n```\r\n\r\nThe 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.\r\n\r\n```\r\n0:00:00 [1/1] test_support\r\n\u003e /Lib/test/test_support.py(114)test_forget()\r\n-\u003e sys.path.insert(0, os.curdir)\r\n(Pdb) p sys.path\r\n['.', '/usr/local/lib/python312.zip', '/Lib', '/build/lib.wasi-wasm32-3.12']\r\n(Pdb) pp sys.path_importer_cache\r\n{'.': FileFinder('/.'),\r\n '/Lib': FileFinder('/Lib'),\r\n '/Lib/collections': FileFinder('/Lib/collections'),\r\n '/Lib/encodings': FileFinder('/Lib/encodings'),\r\n '/Lib/importlib': FileFinder('/Lib/importlib'),\r\n '/Lib/re': FileFinder('/Lib/re'),\r\n '/Lib/test': FileFinder('/Lib/test'),\r\n '/Lib/test/libregrtest': FileFinder('/Lib/test/libregrtest'),\r\n '/Lib/test/support': FileFinder('/Lib/test/support'),\r\n '/Lib/unittest': FileFinder('/Lib/unittest'),\r\n '/Lib/urllib': FileFinder('/Lib/urllib'),\r\n '/build/lib.wasi-wasm32-3.12': FileFinder('/build/lib.wasi-wasm32-3.12'),\r\n '/usr/local/lib/python312.zip': None}\r\n(Pdb) p os.getcwd()\r\n'/python-wasm/cpython/builddir/wasi/build/test_python_66600æ'\r\n(Pdb) n\r\n\u003e /Lib/test/test_support.py(115)test_forget()\r\n-\u003e importlib.invalidate_caches()\r\n(Pdb) n\r\n\u003e /Lib/test/test_support.py(116)test_forget()\r\n-\u003e try:\r\n(Pdb) p sys.path\r\n['.', '.', '/usr/local/lib/python312.zip', '/Lib', '/build/lib.wasi-wasm32-3.12']\r\n(Pdb) pp sys.path_importer_cache\r\n{'.': FileFinder('/.'),\r\n '/Lib': FileFinder('/Lib'),\r\n '/Lib/collections': FileFinder('/Lib/collections'),\r\n '/Lib/encodings': FileFinder('/Lib/encodings'),\r\n '/Lib/importlib': FileFinder('/Lib/importlib'),\r\n '/Lib/re': FileFinder('/Lib/re'),\r\n '/Lib/test': FileFinder('/Lib/test'),\r\n '/Lib/test/libregrtest': FileFinder('/Lib/test/libregrtest'),\r\n '/Lib/test/support': FileFinder('/Lib/test/support'),\r\n '/Lib/unittest': FileFinder('/Lib/unittest'),\r\n '/Lib/urllib': FileFinder('/Lib/urllib'),\r\n '/build/lib.wasi-wasm32-3.12': FileFinder('/build/lib.wasi-wasm32-3.12'),\r\n '/usr/local/lib/python312.zip': None}\r\n```\r\n\r\nA build on Linux has an absolute path to build directory as first ``sys.path`` entry.\r\n\r\n**reproducer**\r\n\r\n```\r\n$ podman run --rm -ti -v $(pwd):/python-wasm/cpython:Z quay.io/tiran/cpythonbuild:emsdk3\r\n# ./build-python-build.sh\r\n# ./build-python-wasi.sh\r\n# ./test-wasi.sh test_support -m test_forget\r\n```","author":{"url":"https://github.com/tiran","@type":"Person","name":"tiran"},"datePublished":"2022-06-03T10:33:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/93461/cpython/issues/93461"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5525612a-c949-2177-c856-e29bf7a9f052 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A66:17FD9C:38669E:4B92BA:6969ACD7 |
| html-safe-nonce | 05d3748d3fc524782f3684c82aa93967e53b634237df9ff3e32444a640448e1d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTY2OjE3RkQ5QzozODY2OUU6NEI5MkJBOjY5NjlBQ0Q3IiwidmlzaXRvcl9pZCI6IjE5NjkyMjM0OTYxOTYyMTA3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e29ddf6c2bf0a220e2392743e938f5400f0db08a0ce9c32e473497e0401c88cb |
| hovercard-subject-tag | issue:1259742187 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/93461/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bc95241bae8e24882c1c621bd65ad2e8c42a487e6faa686bbfe7e0ad2b9b80e9/python/cpython/issues/93461 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bc95241bae8e24882c1c621bd65ad2e8c42a487e6faa686bbfe7e0ad2b9b80e9/python/cpython/issues/93461 |
| og:image:alt | 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 curre... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tiran |
| hostname | github.com |
| expected-hostname | github.com |
| None | 24c4c97a2d520cb286b35e1a4c22d7a4df3c26a2fa28dd7cdf0e65db327b4de7 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 124667f43168afb6c9c03b7c02eb5b1d2e1be3d9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width