Skip to content

Conversation

lcarva
Copy link

@lcarva lcarva commented Jun 16, 2025

Some python packages, e.g. pytz, are purely written in python and do not have any other dependencies. In those cases, a resolver is not set on the compiler, causing AttributeError exceptions in various places.

This commit performs a None check on the resolver attribute before proceeding to access nested attributes.

Fixes: #304

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of missing dependency resolvers to prevent potential errors during dependency compilation.
  • Tests

    • Added a test to verify successful compilation of a requirements file containing a package with no dependencies.

@bruno-fs
Copy link
Collaborator

We might need to add few tests to keep the coverage high, but looks good to me

@lcarva lcarva force-pushed the handle-no-resolver branch from 3e67ac5 to 0f9e1af Compare June 17, 2025 17:04
@lcarva lcarva marked this pull request as ready for review June 17, 2025 17:06
@lcarva
Copy link
Author

lcarva commented Jun 17, 2025

We might need to add few tests to keep the coverage high, but looks good to me

Done! Let me know if that needs any tweaks.

@lcarva lcarva force-pushed the handle-no-resolver branch from 0f9e1af to 502e501 Compare June 23, 2025 14:17
@lcarva
Copy link
Author

lcarva commented Jun 23, 2025

Addressed the line-too-long lint error

Some python packages, e.g. pytz, are purely written in python and do not
have any other dependencies. In those cases, a `resolver` is not set on
the compiler, causing `AttributeError` exceptions in various places.

This commit performs a `None` check on the `resolver` attribute before
proceeding to access nested attributes.

Fixes: hermetoproject#304

Signed-off-by: Luiz Carvalho <[email protected]>
@lcarva lcarva force-pushed the handle-no-resolver branch from 502e501 to c2d6ebe Compare July 14, 2025 12:41
Copy link

coderabbitai bot commented Jul 14, 2025

Walkthrough

The changes update the dependency compilation script to add explicit checks for the presence of a resolver object before accessing its attributes or methods, preventing possible AttributeErrors. Additionally, a new test is introduced to verify that compiling a package with no dependencies runs successfully without errors.

Changes

File(s) Change Summary
src/pybuild_deps/scripts/compile.py Added explicit checks for compiler.resolver before accessing its attributes or methods.
tests/test_main.py Added a test (test_compile_package_without_dependencies) to verify compilation with no dependencies.

Sequence Diagram(s)

sequenceDiagram
    participant Tester as test_compile_package_without_dependencies
    participant CLI as pybuild-deps CLI
    participant Compiler as compile.py
    participant Resolver as compiler.resolver

    Tester->>CLI: Invoke compile command
    CLI->>Compiler: Run compile logic
    Compiler->>Compiler: Check if compiler.resolver is not None
    alt resolver exists
        Compiler->>Resolver: Access resolver attributes/methods
    else resolver is None
        Compiler->>Compiler: Skip resolver-dependent logic
    end
    Compiler->>CLI: Write output, exit
    CLI->>Tester: Return exit code 0
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent AttributeError when compiler.resolver is None (#304)
Ensure compile command works for requirements with no dependencies (#304)

Poem

In the warren where the code bunnies dwell,
We fixed a bug that once gave us hell.
No more NoneType surprises in the night—
Now compiling runs smooth, no error in sight!
With a hop and a test, we’re ready to go,
🐇✨ Onward, dependencies, compile and flow!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aecf883 and c2d6ebe.

📒 Files selected for processing (2)
  • src/pybuild_deps/scripts/compile.py (2 hunks)
  • tests/test_main.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/pybuild_deps/scripts/compile.py (1)
tests/test_compile_build_dependencies.py (1)
  • compiler (15-18)
🔇 Additional comments (4)
src/pybuild_deps/scripts/compile.py (3)

115-117: LGTM! Proper null safety for hash resolution.

The null check prevents AttributeError when compiler.resolver is None, which occurs for packages with no dependencies. The initialization of hashes to None and conditional assignment is the correct approach.


147-151: LGTM! Consistent null safety pattern applied.

The implementation properly handles the case where compiler.resolver is None by initializing both unsafe_packages and unsafe_requirements to None and conditionally setting them only when the resolver exists. This follows the same pattern as the hash resolution above.


154-155: Confirm None handling for unsafe_packages and unsafe_requirements in OutputWriter.write

Please manually verify that the underlying pip-tools OutputWriter.write method accepts None for these parameters (treating them as empty lists) without error. If it does not, update the call site to pass empty lists instead of None:

• File: src/pybuild_deps/scripts/compile.py
Lines: 154–155

     unsafe_packages=unsafe_packages,
     unsafe_requirements=unsafe_requirements,

• If OutputWriter.write does not handle None, change to:

     unsafe_packages=unsafe_packages or [],
     unsafe_requirements=unsafe_requirements or [],
tests/test_main.py (1)

260-267: LGTM! Excellent test coverage for the edge case.

The test effectively verifies that the compile command works correctly for packages with no dependencies (like pytz==2024.1). This directly validates the null safety fixes added to the compile script and ensures the issue described in #304 is resolved.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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.

AttributeError: 'NoneType' object has no attribute 'resolve_hashes'
2 participants