GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Enhance compatibility of os.pathconf_names · Issue #4494 · RustPython/RustPython

Enhance compatibility of os.pathconf_names #4494

New issue
Copy link
New issue
Copy link
Open
#4508
Open
Enhance compatibility of os.pathconf_names#4494
#4508
Copy link
Labels
A-stdlibO-macos

Description

@marvinmednick
marvinmednick
opened on Feb 12, 2023
Issue body actions

Placeholder to track the implmentation of os.pathconf_names -- additional detail to follow
(related to Extend the os module #1175)

Reacted by DimitrisJim

Activity

  1. DimitrisJim
    assigned
    marvinmednick
    on Feb 13, 2023
  2. marvinmednick commented on Feb 14, 2023

    @marvinmednick
    marvinmednick
    on Feb 14, 2023
    Author
    More actions

    Here is the approach:
    The pathconf data is stored in PathconVar Enum, which is configured 'manually' by setting the value constants from libc (which is the integer value needed for pathconf) Since its a simple enum (no data associated) each enum variant can converted to an integer representation using 'as u8/u16/...'

    I'd want the code to iterate through Enum creating the data and create the string and the integer value to build the dictionary.

    I initially looked at a proc_macro to do this, but then saw that pathconf uses a create strum_macro::EnumString to the variatnt name as string and there is another option EnumVariantNames which already support iterating through the different variants as str references (&&str).

    And the code will look like this (I followed the os.envion dictionary as an example):

          #[pyattr]
          fn pathconf_names(vm: &VirtualMachine) -> PyDictRef {
              let pathconf_name_dict = vm.ctx.new_dict();
              // iterate through each item 
              for variant in PathconfVar::VARIANTS {
                  // get the name of variant as a string to use as the dictionary key
                  let key: PyObjectRef = vm.ctx.new_str(variant.to_string()).into();\
                  // get the enum value itself  and convert it to an integer for he dictionary value 
                  let value: PyObjectRef = vm
                      .ctx
                      .new_int(PathconfVar::from_str(variant).unwrap() as u8)
                      .into();
                  pathconf_name_dict.set_item(&*key, value, vm).unwrap();
              }
              pathname_name_dict
          }
    
    
  3. youknowone
    closed this as completedin #4508on Feb 21, 2023
  4. youknowone
    reopened this on Feb 21, 2023
  5. youknowone
    changed the title [-]Implement os.pathconf_names[/-] [+]Implement os.pathconf_names for non-linux unix[/+] on Feb 21, 2023
  6. youknowone commented on Feb 21, 2023

    @youknowone
    youknowone
    on Feb 21, 2023
    Member
    More actions

    #4508 implemented linux version of this function.
    Because this implementation is using libc function, I expect it can be somehow also work on macOS

  7. youknowone
    unassigned
    marvinmednick
    on Feb 21, 2023
  8. youknowone
    added
    A-stdlib
    O-macos
    on Feb 22, 2023
  9. naonus commented on Feb 23, 2023

    @naonus
    naonus
    on Feb 23, 2023
    Contributor
    More actions

    I will take this issue

    Reacted by DimitrisJim
  10. youknowone
    assigned
    naonus
    on Feb 23, 2023
  11. naonus commented on Feb 23, 2023

    @naonus
    naonus
    on Feb 23, 2023
    Contributor
    More actions

    Env: macOS11.5.2( Big Sur ), Intel CPU
    I tried test it and shared the result blow. It worked well

    {'PC_LINK_MAX': 1, 'PC_MAX_CANON': 2, 'PC_MAX_INPUT': 3, 'PC_NAME_MAX': 4, 'PC_PATH_MAX': 5, 'PC_PIPE_BUF': 6, 'PC_CHOWN_RESTRICTED': 7, 'PC_NO_TRUNC': 8, 'PC_VDISABLE': 9}

    Reacted by Jeong, YunWon
  12. youknowone
    unassigned
    naonus
    on Feb 25, 2023
  13. youknowone commented on Feb 27, 2023

    @youknowone
    youknowone
    on Feb 27, 2023
    Member
    More actions

    On macOS,

    CPython result:

    {'PC_ALLOC_SIZE_MIN': 16,
     'PC_ASYNC_IO': 17,
     'PC_CHOWN_RESTRICTED': 7,
     'PC_FILESIZEBITS': 18,
     'PC_LINK_MAX': 1,
     'PC_MAX_CANON': 2,
     'PC_MAX_INPUT': 3,
     'PC_MIN_HOLE_SIZE': 27,
     'PC_NAME_MAX': 4,
     'PC_NO_TRUNC': 8,
     'PC_PATH_MAX': 5,
     'PC_PIPE_BUF': 6,
     'PC_PRIO_IO': 19,
     'PC_REC_INCR_XFER_SIZE': 20,
     'PC_REC_MAX_XFER_SIZE': 21,
     'PC_REC_MIN_XFER_SIZE': 22,
     'PC_REC_XFER_ALIGN': 23,
     'PC_SYMLINK_MAX': 24,
     'PC_SYNC_IO': 25,
     'PC_VDISABLE': 9}
    

    RustPython result:

    {'PC_CHOWN_RESTRICTED': 7,
     'PC_LINK_MAX': 1,
     'PC_MAX_CANON': 2,
     'PC_MAX_INPUT': 3,
     'PC_NAME_MAX': 4,
     'PC_NO_TRUNC': 8,
     'PC_PATH_MAX': 5,
     'PC_PIPE_BUF': 6,
     'PC_VDISABLE': 9}
    
  14. youknowone
    changed the title [-]Implement os.pathconf_names for non-linux unix[/-] [+]Enhance compatibility of os.pathconf_names[/+] on Feb 27, 2023
  15. youknowone commented on Feb 27, 2023

    @youknowone
    youknowone
    on Feb 27, 2023
    Member
    More actions

    This comment is useful to understand missing variables. #4571 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-stdlibO-macos

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.