FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Pathconf names by marvinmednick · Pull Request #4508 · RustPython/RustPython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rs  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 7 additions & 0 deletions extra_tests/snippets/stdlib_os.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):

for arg in [None, 1, 1.0, TabError]:
assert_raises(TypeError, os.system, arg)

# Testing for os.pathconf_names
if sys.platform.startswith('linux'):
assert len(os.pathconf_names) > 0
assert 'PC_NAME_MAX' in os.pathconf_names
for option,index in os.pathconf_names.items():
assert os.pathconf('/', index) == os.pathconf('/', option)
24 changes: 22 additions & 2 deletions vm/src/stdlib/posix.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub mod module {
fs, io,
os::unix::{ffi as ffi_ext, io::RawFd},
};
use strum_macros::EnumString;
use strum_macros::{EnumString, EnumVariantNames};

#[pyattr]
use libc::{PRIO_PGRP, PRIO_PROCESS, PRIO_USER};
Expand Down Expand Up @@ -1681,7 +1681,7 @@ pub mod module {

// Copy from [nix::unistd::PathconfVar](https://docs.rs/nix/0.21.0/nix/unistd/enum.PathconfVar.html)
// Change enum name to fit python doc
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, EnumString)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, EnumString, EnumVariantNames)]
#[repr(i32)]
#[allow(non_camel_case_types)]
pub enum PathconfVar {
Expand Down Expand Up @@ -1881,6 +1881,26 @@ pub mod module {
pathconf(PathOrFd::Fd(fd), name, vm)
}

// TODO: this is expected to be run on macOS as a unix, but somehow not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I put linux cfg until it is fixed for macos

#[cfg(target_os = "linux")]
#[pyattr]
fn pathconf_names(vm: &VirtualMachine) -> PyDictRef {
use std::str::FromStr;
use strum::VariantNames;
let pathname = vm.ctx.new_dict();
for variant in PathconfVar::VARIANTS {
// get the name of variant as a string to use as the dictionary key
let key = vm.ctx.new_str(variant.to_string());
// get the enum from the string and convert it to an integer for the dictionary value
let value: PyObjectRef = vm
.ctx
.new_int(PathconfVar::from_str(variant).unwrap() as u8)
.into();
pathname.set_item(&*key, value, vm).unwrap();
}
pathname
}

#[cfg(any(target_os = "linux", target_os = "macos"))]
#[derive(FromArgs)]
struct SendFileArgs {
Expand Down

Back | FazBrowse Home | New Git URL