Skip to content

Package metadata: give more-descriptive error when license file not found #827

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

Conversation

MaddyGuthridge
Copy link
Contributor

@MaddyGuthridge MaddyGuthridge commented Jan 26, 2025

Resolves: python-poetry#10105

This is a second (much simpler) attempt at solving this issue. My first can be found at #825, and is massively more complex.

This time, the change is in Factory._configure_package_metadata, and just adds a FileNotFoundError exception. Much easier to comprehend.

One thing I want to check is how this error is reported by poetry's main CLI. I want to make sure that the detail of the error is properly conveyed in the CLI. Does anyone have advice on how I can test my modifications against the Poetry CLI?

  • Added tests for changed code.
  • Updated documentation for changed code.

Summary by Sourcery

Raise a FileNotFoundError when the license file specified in pyproject.toml is not found.

Bug Fixes:

  • Fixed an issue where Poetry did not report an error when the license file was missing.

Tests:

  • Added a test case to verify that a FileNotFoundError is raised when the license file is missing.

Copy link

sourcery-ai bot commented Jan 26, 2025

Reviewer's Guide by Sourcery

This pull request improves error handling when a license file is not found. Instead of failing silently, it now raises a FileNotFoundError with a descriptive message, which includes the absolute path of the missing file. Additionally, a test case was added to verify this new behavior.

Sequence diagram for improved license file handling

sequenceDiagram
    participant Factory as Factory._configure_package_metadata
    participant FS as File System

    Factory->>FS: Check if license_path exists
    alt License file not found
        FS-->>Factory: File does not exist
        Factory->>Factory: Raise FileNotFoundError with detailed message
    else License file exists
        FS-->>Factory: File exists
        Factory->>FS: Read license file content
        FS-->>Factory: Return license text
        Factory->>Factory: Process license text
    end
Loading

Flow diagram for license file processing

flowchart TD
    A[Start license processing] --> B{Has license file path?}
    B -->|No| C[Use raw license text]
    B -->|Yes| D{Check if file exists}
    D -->|No| E[Raise FileNotFoundError]
    D -->|Yes| F[Read license file]
    F --> G[Process license content]
    C --> G
    G --> H[End]
Loading

File-Level Changes

Change Details Files
Raise FileNotFoundError when license file is missing
  • Added a check to verify if the license file exists before attempting to read it.
  • Raise a FileNotFoundError if the license file does not exist.
  • Include the absolute path of the missing file in the error message.
src/poetry/core/factory.py
Added test case for missing license file
  • Added a test case that creates a project with a missing license file.
  • Assert that a FileNotFoundError is raised when creating a poetry instance with a missing license file.
  • Assert that the error message contains the absolute path of the missing file.
tests/test_factory.py
tests/fixtures/missing_license_file/pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @MaddyGuthridge - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@MaddyGuthridge MaddyGuthridge force-pushed the maddy-fix-license-missing-exception branch 2 times, most recently from 3d56aba to f774027 Compare January 26, 2025 05:14
Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com>
@radoering radoering merged commit 6f8d54c into python-poetry:main Jan 26, 2025
18 checks passed
@finswimmer finswimmer mentioned this pull request Feb 6, 2025
3 tasks
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.

Misleading errors are reported if some pyproject.toml fields are invalid
2 participants