Skip to content

Update netrc.py from 3.13.6 and make pwd accesible on Android #6083

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ShaharNaveh
Copy link
Contributor

@ShaharNaveh ShaharNaveh commented Aug 8, 2025

Summary by CodeRabbit

  • Refactor
    • Updated platform support for the password module, adjusting which operating systems include this feature.
    • Improved conditional compilation to better align with supported platforms.

Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

Walkthrough

This update modifies conditional compilation attributes for the pwd module in the standard library, changing the set of platforms where it is included or excluded. Additionally, the getpwall function within the pwd module is now excluded from Android builds, and an unused warning is suppressed for the module.

Changes

Cohort / File(s) Change Summary
Stdlib module conditional compilation
vm/src/stdlib/mod.rs
Updated conditional compilation for the pwd module and its registration, now excluding iOS, WASI, and Redox instead of Android and Redox.
Pwd module adjustments
vm/src/stdlib/pwd.rs
Added #[allow(unused)] to the module, inserted a blank line after Passwd struct, and excluded getpwall from Android builds.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

A bunny hops through code with glee,
Tweaking modules for all to see.
"No pwd for iOS or WASI!" it cries,
While Android’s getpwall now quietly lies.
With careful paws, the changes land—
Platform rules now better planned!
🐇✨

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ShaharNaveh ShaharNaveh marked this pull request as ready for review August 8, 2025 13:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
vm/src/stdlib/mod.rs (2)

50-54: LGTM: enable pwd on Android; exclude on iOS/WASI/Redox.

The cfg aligns with platform availability and mirrors CPython’s behavior more closely.

Consider a brief comment explaining why iOS/WASI/Redox are excluded to help future maintainers.


128-132: LGTM: consistent cfg for module registration.

The init map condition matches the module declaration cfg, avoiding mismatches at link time.

Update the preceding “Unix-only” comment to reflect exceptions (iOS/WASI/Redox) for clarity.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e922722 and bf4f6b9.

⛔ Files ignored due to path filters (2)
  • Lib/netrc.py is excluded by !Lib/**
  • Lib/test/test_netrc.py is excluded by !Lib/**
📒 Files selected for processing (2)
  • vm/src/stdlib/mod.rs (2 hunks)
  • vm/src/stdlib/pwd.rs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

Files:

  • vm/src/stdlib/pwd.rs
  • vm/src/stdlib/mod.rs
🧠 Learnings (5)
📓 Common learnings
Learnt from: moreal
PR: RustPython/RustPython#5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration using #ifdef checks rather than providing fallback values for other platforms.
Learnt from: moreal
PR: RustPython/RustPython#5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration rather than providing fallback values for other platforms.
📚 Learning: 2025-06-28T16:31:03.991Z
Learnt from: arihant2math
PR: RustPython/RustPython#5790
File: build.rs:2-2
Timestamp: 2025-06-28T16:31:03.991Z
Learning: In Cargo build scripts (build.rs), the environment variable CARGO_CFG_TARGET_OS is guaranteed to exist and is automatically set by Cargo during the build process, making unwrap() safe to use when accessing this variable.

Applied to files:

  • vm/src/stdlib/pwd.rs
  • vm/src/stdlib/mod.rs
📚 Learning: 2025-07-19T03:16:56.511Z
Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-19T03:16:56.511Z
Learning: Applies to **/*.rs : Use the macro system (`pyclass`, `pymodule`, `pyfunction`, etc.) when implementing Python functionality in Rust

Applied to files:

  • vm/src/stdlib/pwd.rs
  • vm/src/stdlib/mod.rs
📚 Learning: 2025-06-27T14:47:28.810Z
Learnt from: moreal
PR: RustPython/RustPython#5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration using #ifdef checks rather than providing fallback values for other platforms.

Applied to files:

  • vm/src/stdlib/mod.rs
📚 Learning: 2025-06-27T14:47:28.810Z
Learnt from: moreal
PR: RustPython/RustPython#5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration rather than providing fallback values for other platforms.

Applied to files:

  • vm/src/stdlib/mod.rs
🔇 Additional comments (2)
vm/src/stdlib/pwd.rs (2)

30-30: No-op change.

Blank line only; nothing to review.


96-113: LGTM: gate getpwall on Android.

Excluding getpwall on Android matches bionic’s lack of getpwent and avoids link errors while keeping pwd available on Android.

If CI doesn’t already, please add an Android target check to ensure nix::unistd::User::{from_name,from_uid} build and run as expected on Android.

Comment on lines +5 to 7
#[allow(unused)]
#[pymodule]
mod pwd {
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Narrow the lint scope; avoid blanket allow(unused).

Use a targeted allow only on Android or guard the specific import instead of silencing all unused warnings for the whole module.

Suggested change:

-#[allow(unused)]
+#[cfg_attr(target_os = "android", allow(unused_imports))]

Additionally, consider guarding or moving the NonNull import so you can drop the allow entirely on Android:

Option A (guard the import):

#[cfg(not(target_os = "android"))]
use std::ptr::NonNull;

Option B (move into the function and fully-qualify):

// remove the module-level `use std::ptr::NonNull;`
// inside getpwall:
while let Some(ptr) = std::ptr::NonNull::new(unsafe { libc::getpwent() }) {
    // ...
}

This keeps clippy happy and avoids hiding unrelated issues.

🤖 Prompt for AI Agents
In vm/src/stdlib/pwd.rs around lines 5 to 7, the use of a blanket
#[allow(unused)] attribute on the entire module is too broad and hides unrelated
warnings. To fix this, remove the module-level #[allow(unused)] and instead
apply a more targeted approach by either guarding the import of
std::ptr::NonNull with #[cfg(not(target_os = "android"))] or by removing the
import entirely and fully qualifying std::ptr::NonNull inside the function where
it is used. This will narrow the lint scope and keep clippy warnings relevant.

@@ -2,6 +2,7 @@

pub(crate) use pwd::make_module;

#[allow(unused)]
Copy link
Member

Choose a reason for hiding this comment

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

Because the conditions in stdlib/mod.rs must be aligned, this allow will not be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's only being used on android.
I can do what coderabbitai is suggesting if that's ok

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.

2 participants