Skip to content

Commit ac4e5b8

Browse files
authored
Merge pull request #2314 from RustPython/coolreader18/no-cache-mac
Try skipping caching on macos
2 parents 991be82 + e4f446e commit ac4e5b8

9 files changed

Lines changed: 116 additions & 25 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ jobs:
7878
if: runner.os == 'macOS'
7979
- name: Cache cargo dependencies
8080
uses: actions/cache@v2
81+
# cache gets corrupted for some reason on mac
82+
if: runner.os != 'macOS'
8183
with:
8284
path: |
8385
~/.cargo/registry
@@ -108,12 +110,20 @@ jobs:
108110
RUSTPYTHONPATH: ${{ github.workspace }}/Lib
109111
if: runner.os == 'Linux'
110112
- name: run cpython tests (macOS lightweight)
111-
run: target/release/rustpython -m test -x test_argparse -x test_json -x test_bytes -x test_long -v
113+
run:
114+
target/release/rustpython -m test -v -x
115+
test_argparse test_json test_bytes test_bytearray test_long test_unicode test_array
116+
test_asyncgen test_list test_complex test_json test_set test_dis test_calendar
112117
env:
113118
RUSTPYTHONPATH: ${{ github.workspace }}/Lib
114119
if: runner.os == 'macOS'
115120
- name: run cpython tests (windows partial - fixme)
116-
run: target/release/rustpython -m test -x test_argparse -x test_json -x test_bytes -x test_long -x test_pwd -x test_bool -x test_cgi -x test_complex -x test_exception_hierarchy -x test_glob -x test_importlib -x test_iter -x test_list -x test_os -x test_pathlib -x test_py_compile -x test_set -x test_shutil -x test_sys -x test_unicode -x test_unittest -x test_venv -x test_zipimport -v
121+
run:
122+
target/release/rustpython -m test -v -x
123+
test_argparse test_json test_bytes test_long test_pwd test_bool test_cgi test_complex
124+
test_exception_hierarchy test_glob test_iter test_list test_os test_pathlib
125+
test_py_compile test_set test_shutil test_sys test_unicode test_unittest test_venv
126+
test_zipimport test_importlib
117127
env:
118128
RUSTPYTHONPATH: ${{ github.workspace }}/Lib
119129
if: runner.os == 'Windows'

Lib/pathlib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
supports_symlinks = True
1717
if os.name == 'nt':
1818
import nt
19-
if sys.getwindowsversion()[:2] >= (6, 0):
19+
# XXX RUSTPYTHON TODO: nt._getfinalpathname
20+
if False and sys.getwindowsversion()[:2] >= (6, 0):
2021
from nt import _getfinalpathname
2122
else:
2223
supports_symlinks = False
@@ -42,7 +43,10 @@
4243
)
4344

4445
def _ignore_error(exception):
45-
return (getattr(exception, 'errno', None) in _IGNORED_ERROS or
46+
# XXX RUSTPYTHON: added check for FileNotFoundError, file.exists() on windows throws it
47+
# but with a errno==ESRCH for some reason
48+
return (isinstance(exception, FileNotFoundError) or
49+
getattr(exception, 'errno', None) in _IGNORED_ERROS or
4650
getattr(exception, 'winerror', None) in _IGNORED_WINERRORS)
4751

4852

Lib/test/support/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,12 +1066,15 @@ def temp_dir(path=None, quiet=False):
10661066
try:
10671067
rmtree(path)
10681068
except OSError as exc:
1069-
# XXX RUSTPYTHON: added quiet check here, not sure why rmtree fails on windows
1070-
if not quiet:
1071-
raise
1072-
warnings.warn(f'unable to remove temporary'
1073-
f'directory {path!r}: {exc}',
1074-
RuntimeWarning, stacklevel=3)
1069+
# XXX RUSTPYTHON: something something async file removal?
1070+
# also part of the thing with rmtree()
1071+
# throwing PermissionError, I think
1072+
if os.path.exists(path):
1073+
if not quiet:
1074+
raise
1075+
warnings.warn(f'unable to remove temporary'
1076+
f'directory {path!r}: {exc}',
1077+
RuntimeWarning, stacklevel=3)
10751078

10761079
@contextlib.contextmanager
10771080
def change_cwd(path, quiet=False):

Lib/test/test_importlib/test_locks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import threading
77
import weakref
8+
import unittest
89

910
from test import support
1011
from test import lock_tests
@@ -37,6 +38,7 @@ class ModuleLockAsRLockTests:
3738
LockType=LOCK_TYPES)
3839

3940

41+
@unittest.skipIf(sys.platform == "darwin", "TODO: RUSTPYTHON")
4042
class DeadlockAvoidanceTests:
4143

4244
def setUp(self):

Lib/test/test_importlib/test_windows.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def test_module_not_found(self):
8888

8989
@unittest.skipUnless(sys.platform.startswith('win'), 'requires Windows')
9090
class WindowsExtensionSuffixTests:
91+
# TODO: RUSTPYTHON
92+
@unittest.expectedFailure
9193
def test_tagged_suffix(self):
9294
suffixes = self.machinery.EXTENSION_SUFFIXES
9395
expected_tag = ".cp{0.major}{0.minor}-{1}.pyd".format(sys.version_info,

extra_tests/snippets/stdlib_os.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
assert_raises(FileNotFoundError,
1818
lambda: os.rename('DOES_NOT_EXIST', 'DOES_NOT_EXIST 2'))
1919

20-
if hasattr(os, "sendfile"):
20+
# sendfile only supports in_fd as non-socket on linux and solaris
21+
if hasattr(os, "sendfile") and sys.platform.startswith("linux"):
2122
src_fd = os.open('README.md', os.O_RDONLY)
2223
dest_fd = os.open('destination.md', os.O_RDWR | os.O_CREAT)
2324
src_len = os.stat('README.md').st_size

vm/src/stdlib/os.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,17 @@ mod _os {
437437
#[pyfunction]
438438
fn remove(path: PyPathLike, dir_fd: DirFd, vm: &VirtualMachine) -> PyResult<()> {
439439
let path = make_path(vm, &path, &dir_fd)?;
440-
fs::remove_file(path).map_err(|err| err.into_pyexception(vm))
440+
let is_junction = cfg!(windows)
441+
&& fs::symlink_metadata(path).map_or(false, |meta| {
442+
let ty = meta.file_type();
443+
ty.is_dir() && ty.is_symlink()
444+
});
445+
let res = if is_junction {
446+
fs::remove_dir(path)
447+
} else {
448+
fs::remove_file(path)
449+
};
450+
res.map_err(|err| err.into_pyexception(vm))
441451
}
442452

443453
#[pyfunction]
@@ -963,7 +973,12 @@ impl<'a> SupportFunc {
963973
where
964974
F: IntoPyNativeFunc<FKind>,
965975
{
966-
let func_obj = vm.ctx.new_function(func);
976+
let ctx = &vm.ctx;
977+
let func_obj = ctx
978+
.new_function_named(func, name.to_owned())
979+
.into_function()
980+
.with_module(ctx.new_str(MODULE_NAME))
981+
.build(ctx);
967982
Self {
968983
name,
969984
func_obj,

vm/src/stdlib/winreg.rs

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use crate::builtins::pystr::PyStrRef;
33
use crate::builtins::pytype::PyTypeRef;
44
use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard};
55
use crate::exceptions::IntoPyException;
6-
use crate::function::OptionalArg;
76
use crate::pyobject::{
87
BorrowValue, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject,
98
};
109
use crate::VirtualMachine;
1110

1211
use std::convert::TryInto;
12+
use std::ffi::OsStr;
1313
use std::io;
1414
use winapi::shared::winerror;
1515
use winreg::{enums::RegType, RegKey, RegValue};
@@ -98,25 +98,43 @@ impl Hkey {
9898
}
9999
}
100100
}
101+
fn into_key(self) -> RegKey {
102+
let k = match self {
103+
Self::PyHKEY(py) => py.key().raw_handle(),
104+
Self::Constant(k) => k,
105+
};
106+
RegKey::predef(k)
107+
}
101108
}
102109

103-
fn winreg_OpenKey(
110+
#[derive(FromArgs)]
111+
struct OpenKeyArgs {
112+
#[pyarg(any)]
104113
key: Hkey,
105-
subkey: Option<PyStrRef>,
106-
reserved: OptionalArg<i32>,
107-
access: OptionalArg<u32>,
108-
vm: &VirtualMachine,
109-
) -> PyResult<PyHKEY> {
110-
let reserved = reserved.unwrap_or(0);
111-
let access = access.unwrap_or(winreg::enums::KEY_READ);
114+
#[pyarg(any)]
115+
sub_key: Option<PyStrRef>,
116+
#[pyarg(any, default = "0")]
117+
reserved: i32,
118+
#[pyarg(any, default = "winreg::enums::KEY_READ")]
119+
access: u32,
120+
}
121+
122+
fn winreg_OpenKey(args: OpenKeyArgs, vm: &VirtualMachine) -> PyResult<PyHKEY> {
123+
let OpenKeyArgs {
124+
key,
125+
sub_key,
126+
reserved,
127+
access,
128+
} = args;
129+
112130
if reserved != 0 {
113131
// RegKey::open_subkey* doesn't have a reserved param, so this'll do
114132
return Err(vm.new_value_error("reserved param must be 0".to_owned()));
115133
}
116134

117-
let subkey = subkey.as_ref().map_or("", |s| s.borrow_value());
135+
let sub_key = sub_key.as_ref().map_or("", |s| s.borrow_value());
118136
let key = key
119-
.with_key(|k| k.open_subkey_with_flags(subkey, access))
137+
.with_key(|k| k.open_subkey_with_flags(sub_key, access))
120138
.map_err(|e| e.into_pyexception(vm))?;
121139

122140
Ok(PyHKEY::new(key))
@@ -177,6 +195,39 @@ fn winreg_CloseKey(key: Hkey) {
177195
}
178196
}
179197

198+
fn winreg_CreateKey(key: Hkey, subkey: Option<PyStrRef>, vm: &VirtualMachine) -> PyResult<PyHKEY> {
199+
let k = match subkey {
200+
Some(subkey) => {
201+
let (k, _disp) = key
202+
.with_key(|k| k.create_subkey(&*subkey.borrow_value()))
203+
.map_err(|e| e.into_pyexception(vm))?;
204+
k
205+
}
206+
None => key.into_key(),
207+
};
208+
Ok(PyHKEY::new(k))
209+
}
210+
211+
fn winreg_SetValue(
212+
key: Hkey,
213+
subkey: Option<PyStrRef>,
214+
typ: u32,
215+
value: PyStrRef,
216+
vm: &VirtualMachine,
217+
) -> PyResult<()> {
218+
if typ != winreg::enums::REG_SZ as u32 {
219+
return Err(vm.new_type_error("type must be winreg.REG_SZ".to_owned()));
220+
}
221+
let subkey = subkey.as_ref().map_or("", |s| s.borrow_value());
222+
key.with_key(|k| k.set_value(subkey, &OsStr::new(value.borrow_value())))
223+
.map_err(|e| e.into_pyexception(vm))
224+
}
225+
226+
fn winreg_DeleteKey(key: Hkey, subkey: PyStrRef, vm: &VirtualMachine) -> PyResult<()> {
227+
key.with_key(|k| k.delete_subkey(subkey.borrow_value()))
228+
.map_err(|e| e.into_pyexception(vm))
229+
}
230+
180231
fn reg_to_py(value: RegValue, vm: &VirtualMachine) -> PyResult {
181232
macro_rules! bytes_to_int {
182233
($int:ident, $f:ident, $name:ident) => {{
@@ -255,6 +306,9 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
255306
"EnumKey" => named_function!(ctx, winreg, EnumKey),
256307
"EnumValue" => named_function!(ctx, winreg, EnumValue),
257308
"CloseKey" => named_function!(ctx, winreg, CloseKey),
309+
"CreateKey" => named_function!(ctx, winreg, CreateKey),
310+
"SetValue" => named_function!(ctx, winreg, SetValue),
311+
"DeleteKey" => named_function!(ctx, winreg, DeleteKey),
258312
});
259313

260314
macro_rules! add_constants {

vm/src/sysmodule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ settrace() -- set the global debug tracing function
703703

704704
#[cfg(windows)]
705705
{
706-
let _getwindowsversion = WindowsVersion::make_class(ctx);
706+
WindowsVersion::make_class(ctx);
707707
extend_module!(vm, module, {
708708
"getwindowsversion" => named_function!(ctx, sys, getwindowsversion),
709709
})

0 commit comments

Comments
 (0)