Skip to content
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

Improve error message for packages in src folder #10236

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

martinvotruba-r7
Copy link

@martinvotruba-r7 martinvotruba-r7 commented Mar 1, 2025

Problem description

Currently when a poetry install command is run on a project, which has source stored under src/project_name, but a folder named project_name exists in the root, the command will fail with project_name is not a package. It can be rather hard to determine the root cause, as one might easily overlook the empty folder.

Steps to reproduce

  1. create a new poetry project poetry new poetry-demo
  2. Move poetry_demo/__init__.py to src/poetry_demo/__init__.py
  3. run poetry install

The command will fail with the following

poetry install
Installing dependencies from lock file

Installing the current project: poetry-demo (0.1.0)
poetry_demo is not a package.

This is caused by the presence of poetry_demo folder in the root.

tree -I ".git" --noreport --charset utf-8 .
.
├── README.md
├── poetry.lock
├── poetry_demo
├── pyproject.toml
├── src
│   └── poetry_demo
│       └── __init__.py
└── tests
    └── __init__.py

When I remove the poetry_demo folder, the poetry install command succeeds.

Resolution

To provide more information about the actual root cause of the issue, I have added another validation method to the Factory class. This will output a warning when there is both

  • an empty project_name folder in the root
  • non-empty src/project_name folder
    The provided warning message is the following
Found empty directory 'project_name' in project root while the actual package is in 'src/project_name'. This may cause issues with package installation. Consider removing the empty directory.

If there is a better place / method how to alert user to the empty project_name folder, I am happy to hear it and adjust my implementation.

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

Summary by Sourcery

Tests:

  • Adds a test case to verify the new validation check for projects with source code in the src/ directory.

Copy link

sourcery-ai bot commented Mar 1, 2025

Reviewer's Guide by Sourcery

This pull request improves the user experience by adding a warning message when a Poetry project has a potential misconfiguration: an empty directory in the project root with the same name as the project, while the actual package resides in the src directory. This situation can lead to confusing installation errors.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Added a validation to warn users about potential issues when a project has an empty directory in the root with the same name as the project, while the actual package is located in the src directory.
  • Implemented _validate_project_in_src method in CheckCommand to detect the described scenario.
  • Added a warning message to the check command output when the condition is met.
  • Added a test case to verify the warning message is displayed correctly.
src/poetry/console/commands/check.py
tests/console/commands/test_check.py
tests/fixtures/project_with_src_folder/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 @martinvotruba-r7 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a test case where the root project_name directory exists but is not empty.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 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.

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.

1 participant