-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add os.supports_* placeholders #964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add os.supports_* placeholders #964
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Added a few comments
vm/src/stdlib/os.rs
Outdated
@@ -512,33 +577,128 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { | |||
"st_size" => ctx.new_property(StatResultRef::st_size), | |||
}); | |||
|
|||
py_module!(vm, "_os", { | |||
"open" => ctx.new_rustfunc(os_open), | |||
let fd_funcs: Vec<(&str, PyObjectRef, Option<bool>, Option<bool>, Option<bool>)> = vec![ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the support_*
an Option
? This can be either true
of false
. You convert the None
to false
later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a kind of documentation describing it is varies by platform(Some) or always not supported(None)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand...
Let's take os.symlink
for example. on linux system dir_fd
is supported and on windows it is not. In that case we will have Some(true)
on linux and Some(false)
on windows. While follow_symlinks
will always be None
. Is there any difference between Some(false)
and None
? Would there be a different error message somewhere I am missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no difference between None
and Some(false)
for implementations. As you pointed out, None
marks os.symlink
doesn't have any option about follow_symlinks
. I think it is a little bit confusing because it is just Some(false)
for now.
Once we get actual values for each platforms, the None
part always will be None
. Because Python spec doesn't have any value about it. Otherwise, the Some
part will be something like Some(platform_supports_os_symlink)
because Python spec describes the value must be true
or false
by platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is platform_supports_os_symlink
a function in your example or a boolean value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a value. (or result of a function) I think the values are platform-specific constants defined in compile time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinion is that this Option
is not needed. I think using platform_supports_os_symlink
or false
would be more readable.
# supports | ||
assert isinstance(os.supports_fd, set) | ||
assert isinstance(os.supports_dir_fd, set) | ||
assert isinstance(os.supports_follow_symlinks, set) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test that os.stat
(or any other compatible function) is in os.supports_*
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing is insdie of the set for now. It is just placeholders. See fd_funcs which only includes None
and Some(false)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Did not see that.
vm/src/stdlib/os.rs
Outdated
// chmod Some Some Some | ||
// chown Some Some Some | ||
// chroot Some None None | ||
( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very readable in the current way. It is hard to remember what parameter is which. How about changing this to be a vector of:
struct FdFunc {
name: String,
func_obj: PyObjectRef,
supports_fd: boolean,
supports_dir_fd: boolean,
supports_follow_symlinks: boolean,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this and other comments, thanks!
vm/src/stdlib/os.rs
Outdated
None, | ||
), | ||
// utime Some Some Some | ||
// walk Some None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of this function like walk
are implemented in pure python. Maybe consider removing the placeholders?
vm/src/stdlib/os.rs
Outdated
use std::os::unix::fs as unix_fs; | ||
let src = make_path(vm, src, &dir_fd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dir_fd
in symlink is only relevant for the dst
. The underlying implementation use symlinkat
.
Codecov Report
@@ Coverage Diff @@
## master #964 +/- ##
==========================================
- Coverage 64.84% 64.81% -0.04%
==========================================
Files 91 91
Lines 16312 16363 +51
Branches 3695 3702 +7
==========================================
+ Hits 10578 10606 +28
- Misses 3277 3293 +16
- Partials 2457 2464 +7
Continue to review full report at Codecov.
|
bfcc82d
to
958767d
Compare
958767d
to
64afd5c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.