Skip to content

The __main__.py module breaks under Windows #177

Closed

Description

@slott56

On Windows there's a platform-specific failure exposed by tests/test_main.py::test_stat_good because os.getegid() is not available on Windows.

Alter the __main__.py to have a Windows-compatible variant of the stat() function without the group_access and user_access attributes of the data object it builds.

Activity

  1. Quantum0uasar commented on May 21, 2026

    @Quantum0uasar
    Collaborator

    Hi! I'd be happy to work on this fix.

    The issue is that os.getegid() (and os.getuid() / os.getgid() if used similarly) is a Unix-only call and raises AttributeError on Windows.

    My plan:

    1. Wrap the group_access and user_access calls in a platform check: if hasattr(os, 'getegid') (or if sys.platform != 'win32')
    2. On Windows, gracefully skip or return a sensible default for those attributes
    3. Update the test in tests/test_main.py to handle both platforms

    This should be a minimal, targeted fix. I'll open a draft PR shortly — let me know if you have a preference on how the Windows fallback should behave!

  2. added a commit that references this issue on May 21, 2026
    26bec6d
  3. slott56 commented on May 21, 2026

    @slott56
    CollaboratorAuthor

    Sorry for not seeing this before the PR was submitted.

    An if using sys.platform is not the best approach. The use of hasattr() or a try/except block is going to work out more consistently across more OS's. See the https://docs.python.org/3/library/intro.html#notes-on-availability which is rather vague.

  4. Quantum0uasar commented on May 21, 2026

    @Quantum0uasar
    Collaborator

    Thanks for the feedback @slott56! You're right — using sys.platform (or platform.system()) is fragile.

    @Rohan5commit please update PR #178 to use a try/except AttributeError block instead, which is more robust and idiomatic:

    try:
        data["group_access"] = celtypes.BoolType(status.st_gid == os.getegid())  # type: ignore[attr-defined]
        data["user_access"] = celtypes.BoolType(status.st_uid == os.geteuid())  # type: ignore[attr-defined]
    except AttributeError:
        pass  # os.getegid() and os.geteuid() are not available on all platforms (e.g. Windows)

    Also remove import platform and the _IS_WINDOWS flag entirely — they are no longer needed. This approach handles any platform where those attributes are missing, not just Windows.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions