384 Commits

Author SHA1 Message Date
psyche
40c84f51c8 Expose rustpython_pylib in rustpython (#7498)
Co-authored-by: EtherealPsyche <EtherealPsyche@users.noreply.github.com>
2026-03-24 17:51:01 +09:00
Jeong, YunWon
93099e35e7 Remove PyStr::as_str, use as_wtf8/PyUtf8Str instead (#7218)
- Remove as_str() from PyStr/Py<PyStr> (was panicking on surrogates)
- Add Wtf8Concat trait and concat! macro for WTF-8 formatting
- Add impl From<&str> for &Wtf8 conversion
- Add AsPyStr/DictKey impls for PyUtf8Str types
- Migrate all call sites to as_wtf8(), to_str(), or PyUtf8Str
- Fix exception message APIs to accept Wtf8Buf
- Deduplicate inner-scope imports across modules
2026-02-27 04:20:11 +09:00
Jeong, YunWon
7b866f66e9 Add missing _winapi functions (#7185)
* Add missing _winapi functions and fix WinHandle int conversion

Add 13 functions: ReadFile, SetNamedPipeHandleState, CreateFileMapping,
OpenFileMapping, MapViewOfFile, UnmapViewOfFile, VirtualQuerySize,
CopyFile2, ResetEvent, CreateMutex, OpenEventW, LoadLibrary,
_mimetypes_read_windows_registry.

Add constants: INVALID_HANDLE_VALUE, FILE_MAP_READ/WRITE/COPY/EXECUTE.

Change WinHandle integer type from usize to isize so negative values
like INVALID_HANDLE_VALUE (-1) can be passed from Python.

* Align _winapi module with CPython

- Rename winapi.rs to _winapi.rs with #[path] attribute
- Rename CreateMutex to CreateMutexW
- Add missing constants: ERROR_ACCESS_DENIED, ERROR_PRIVILEGE_NOT_HELD,
  PROCESS_ALL_ACCESS, 10 STARTF_ constants, LOCALE_NAME_SYSTEM_DEFAULT,
  LOCALE_NAME_USER_DEFAULT, COPY_FILE_DIRECTORY
- Fix OpenMutexW return type and ReleaseMutex param type to use WinHandle

* Fix ReadFile/WriteFile overlapped keyword argument

Use FromArgs structs so overlapped parameter can be passed as
a keyword argument (overlapped=True), matching the CPython API.

* Remove extra constants and LoadLibrary not in CPython _winapi

Remove 19 constants (WAIT_ABANDONED, CREATE_ALWAYS, CREATE_NEW,
OPEN_ALWAYS, TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, 8 FILE_FLAG_*,
3 FILE_SHARE_*, NMPWAIT_NOWAIT, NMPWAIT_USE_DEFAULT_WAIT) and
LoadLibrary function that are not present in CPython's _winapi module.

* Fix utf8_mode default to 0 and add PYTHONUTF8 env var support

Default utf8_mode was incorrectly set to 1, causing text-mode
subprocess to always decode as UTF-8 instead of locale encoding.
Changed default to 0 to match CPython 3.13 behavior on Windows.
Added PYTHONUTF8 environment variable handling with -X utf8 override.

* Fix CopyFile2 to raise proper OSError subclass

Use std::io::Error::from_raw_os_error instead of vm.new_os_error so
that winerror attribute is set and errno-to-exception mapping works
(e.g. ERROR_ACCESS_DENIED → PermissionError).

* Fix syntax_non_utf8 test to not depend on locale encoding

Use explicit encoding='latin-1' so the test works regardless of
the system locale (e.g. C/POSIX locale uses ASCII by default).
2026-02-22 19:54:27 +09:00
Jeong, YunWon
f777416870 initial sandbox (#7035)
* Add host_env feature for sandbox isolation

Introduce a `host_env` feature flag that gates all host environment
access (filesystem, network, signals, processes). When disabled,
the VM operates in sandbox mode:

- _io module always available; FileIO gated by host_env
- SandboxStdio provides lightweight stdin/stdout/stderr via Rust std::io
- BytesIO/StringIO/BufferedIO/TextIOWrapper work without host_env
- open() returns UnsupportedOperation in sandbox
- stdlib modules (os, socket, signal, etc.) gated by host_env
- CI checks both host_env ON and OFF builds

* Auto-format: ruff check --select I --fix

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-08 13:58:30 +00:00
Jeong, YunWon
1e1b423fc0 Merge pull request #6997 from youknowone/test_io
Better codecs and fix lots of test_io and other expectedFailures
2026-02-06 09:04:47 +09:00
Jeong, YunWon
afea16569b Fix test_io expectedFailures 2026-02-06 00:15:18 +09:00
Jeong, YunWon
2e62cac72b Implement more warnings 2026-02-05 23:50:08 +09:00
Jeong, YunWon
5e732c5e2a Fix wasip2 build (#6935) 2026-02-02 01:26:17 +09:00
Elmir
44c3179ae0 Docs: add reference to rustpython_derive close to example (#6882)
Include a link for native module macros documentation, after an
example where they are used.
2026-01-28 10:25:48 +09:00
Jeong YunWon
20376451eb Implement Py_mod_create slot support in multi-phase init 2026-01-22 11:21:42 +09:00
Jeong YunWon
bc02b2318c module_exec 2026-01-21 22:39:40 +09:00
Jeong YunWon
fee1a4b097 multiphase 2026-01-21 22:39:39 +09:00
Jeong, YunWon
b76906a8bf Add sys._stdlib_dir (#6798) 2026-01-20 03:38:40 +09:00
Jeong, YunWon
e8dd5826e6 init warnings before site (#6771) 2026-01-18 19:16:02 +09:00
Jeong, YunWon
96e08a425e Initialize warnings module during interpreter startup to process (#6766) 2026-01-18 13:15:40 +09:00
Jeong, YunWon
ca76cb7bb0 thread_inherit_context, upgrade threading & contextvar (#6727)
* thread_inherit_context

* Update contextvar, threading from CPython 3.14.2

* partially patch test_sys to 3.14.2

---------

Co-authored-by: CPython Devleopers <>
2026-01-18 08:53:41 +09:00
Lee Dogeon
0cd6eb7b13 Write profile even if failed (#6685) 2026-01-10 15:26:49 +09:00
Jeong, YunWon
e1b22f19e6 vm.run_pyc_bytes (#6645)
* rustpython_vm::import::check_pyc_magic_number_bytes

* vm.new_scope_with_main

* PyCode::from_pyc

* vm.run_pyc_bytes

* add boundary check
2026-01-04 22:58:16 +09:00
Jeong, YunWon
bdd036ea6b pythonrun (#6643) 2026-01-04 20:52:35 +09:00
Jeong, YunWon
e10dc94992 Fix stdio_encoding, stdio_errors (#6617)
* stdio_errors, stdio_encodings

* add ascii

* unmark tests
2026-01-01 14:48:27 +09:00
Jeong, YunWon
1e706d911e Interpreter (#6614)
* Refine documentation in interpreter.rs

Improve InterpreterConfig with convenience methods (with_debug, add_path, add_paths), better documentation with working examples, refactored stdlib setup into focused functions, and comprehensive unit tests while maintaining 100% backward compatibility.

* Improve error message for non-Unicode paths

* Use consistent make_module naming in all doc examples

* cut useful changes

---------

Co-authored-by: Mohamed Gharbi <galaxysea777@gmail.com>
2025-12-31 22:14:28 +09:00
Jeong, YunWon
e79a1a1a66 Fix traceback (#6569)
* Fix traceback

* Update traceback from CPython 3.13.11

* unmark test_traceback

* fix code

* fix debug range

* fix tests
2025-12-30 16:58:53 +09:00
Terry Tianlin Luan
1464d5ca43 Adding + Fixing Clippy rules to better align with #[no_std] (#6570)
* * Added alloc_instead_of_core, std_instead_of_alloc, and std_instead_of_core clippy rules
* Manually changed part of the code to use core/alloc

* use clippy --fix to fix issues in stdlib

* * Used clippy --fix to fix issues in vm
* Imported Range in vm/src/anystr.rs

* * Used clippy --fix to fix issues in common
2025-12-30 13:10:14 +09:00
Jeong, YunWon
57b4b4ae45 fix sys path (#6537) 2025-12-26 21:43:00 +09:00
Jeong, YunWon
8b3bf558fc Introduce PyConfig to implement Paths correctly (#6461)
* getpath

* introduce PyConfig

* landmark in getpath
2025-12-21 08:25:17 +09:00
Jeong, YunWon
4bec0ad1c6 Fix test_runpy (#6409) 2025-12-12 15:26:00 +09:00
Jeong, YunWon
2ff1fba6ed Faulthandler (#6406) 2025-12-12 09:23:59 +09:00
Jeong, YunWon
04d55fa5c6 Faulthandler (#6400) 2025-12-12 00:08:55 +09:00
Jeong, YunWon
1a783fc9ec Replace SSL backend to rustls (#6244) 2025-11-16 22:17:35 +09:00
Jeong YunWon
4f8ef16937 Re-organize vm.run_script inner functions 2025-11-15 23:09:31 +09:00
Shahar Naveh
fcf196935e Update ruff 0.14.1 (#6195)
* Update ruff to 0.14.1

* Fix test regression in `test_compile`

* Unmark passing test

* Update `test_syntax` from 3.13.9

---------

Co-authored-by: Noa <coolreader18@gmail.com>
2025-10-20 22:46:46 +09:00
Anton
b56e469a5f Handle OsError in REPL (#6187) 2025-10-13 10:18:51 +09:00
Noa
85ca28094e Apply clippy suggestions to switch to let chains (#6126) 2025-09-04 15:34:10 +09:00
Jack O'Connor
109e64c2ba Allow multiple indented blocks in REPL (#6097)
There aren't any tests but being able to do nested for loops seems like
a pretty big win to me so I'm going to put up for review.

The original returned boolean clearly had **false positives** for
detecting bad errors for things like nested `if` and `for` statements.
What is less clear is if there are any **true positives** which I am no
longer catching with the updated return value.

Co-authored-by: Jack O'Connor <jack@jackoconnor.dev>
2025-08-21 13:15:02 +09:00
Shahar Naveh
4bf32a04f4 Apply some clipy lints (#6045) 2025-07-30 12:16:02 +09:00
Jeong, YunWon
d40cbbb451 Fix cspell warning (#5890)
* Fix cspell warning

* cspell: -> spell-checker:
2025-07-03 12:04:43 +09:00
Jeong YunWon
3673372d3d Fix cspell warnings 2025-06-27 12:32:59 +09:00
Jeong YunWon
2c61a12bed Apply coderabbit reviews 2025-06-15 16:03:46 +09:00
Jeong YunWon
f560b4cbfb Fix nightly clippy warnings 2025-06-15 16:03:46 +09:00
Aneesh Durg
323ea3b96b Support incomplete parsing (#5764)
* continue accepting REPL input for multiline strings

* Match cpython behavior for all multi-line statements (execute when complete)

* Emit _IncompleteInputError when compiling with incomplete flag

* Refine when _IncompleteInputError is emitted

* Support multiline strings emitting _IncompleteInputError

* lint

* Undo accidental change to PyTabError

* match -> if let

* Fix test_baseexception and test_codeop

* fix spelling

* fix exception name

* Skip pickle test of _IncompleteInputError

* Use py3.15's codeop implementation

* Update Lib/test/test_baseexception.py

---------

Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-06-05 14:41:56 +09:00
Aneesh Durg
e49e743669 Support multiline function/class definitions in REPL and InteractiveConsole (#5743)
* Support multiline function/class definitions in REPL and InteractiveConsole
2025-04-30 14:53:37 +09:00
Jeong YunWon
e434ff5f6e basic wasip2 support 2025-04-20 19:47:35 +09:00
Jeong, YunWon
4ae2936a45 fix more cspell warnings (#5689) 2025-04-11 12:08:07 +09:00
Jeong YunWon
36cce6b174 run fmt 2025-04-05 00:14:03 +09:00
Ashwin Naren
5c854fc690 clear out warnings 2025-04-04 21:46:28 +09:00
Jeong YunWon
d7113e11db Fix more cspell warnings 2025-04-04 21:45:03 +09:00
Jeong YunWon
7ac61f3840 fix cspell warnings 2025-04-04 16:15:54 +09:00
Jeong, YunWon
c7ca173c90 Merge pull request #5254 from youknowone/exception-group
ExceptionGroup
2025-03-27 14:51:12 +09:00
Jeong YunWon
e7fdfca5f5 Add python-implemented ExceptionGroup 2025-03-27 01:28:36 +09:00
Jeong YunWon
bc38e9dedd Apply nightly clippy suggestions 2025-03-26 14:52:23 +09:00