Skip to content

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

Merged
merged 1 commit into from
May 12, 2019

Conversation

youknowone
Copy link
Member

No description provided.

Copy link
Contributor

@palaviv palaviv left a 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

@@ -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![
Copy link
Contributor

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

Copy link
Member Author

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)

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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)
Copy link
Contributor

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_*?

Copy link
Member Author

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)

Copy link
Contributor

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.

// chmod Some Some Some
// chown Some Some Some
// chroot Some None None
(
Copy link
Contributor

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,
}

Copy link
Member Author

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!

None,
),
// utime Some Some Some
// walk Some None
Copy link
Contributor

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?

use std::os::unix::fs as unix_fs;
let src = make_path(vm, src, &dir_fd);
Copy link
Contributor

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-io
Copy link

codecov-io commented May 11, 2019

Codecov Report

Merging #964 into master will decrease coverage by 0.03%.
The diff coverage is 62.85%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
vm/src/obj/objset.rs 73.45% <100%> (ø) ⬆️
vm/src/stdlib/os.rs 68.4% <62.31%> (-2.21%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95a894a...64afd5c. Read the comment docs.

@youknowone youknowone force-pushed the os-supports-placeholders branch from bfcc82d to 958767d Compare May 12, 2019 10:10
@youknowone youknowone force-pushed the os-supports-placeholders branch from 958767d to 64afd5c Compare May 12, 2019 16:15
Copy link
Contributor

@palaviv palaviv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@coolreader18 coolreader18 merged commit b01d756 into RustPython:master May 12, 2019
@youknowone youknowone deleted the os-supports-placeholders branch May 13, 2019 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants