Skip to content

Conversation

@finswimmer
Copy link
Member

@finswimmer finswimmer commented Oct 21, 2025

Resolves: python-poetry/poetry#10557

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

Summary by Sourcery

Fix Factory._configure_package_dependencies to differentiate between an undefined and an explicitly empty dependencies list, ensuring that an empty list still produces a main dependency group with no entries.

Bug Fixes:

  • Distinguish between missing and empty project dependencies in Factory._configure_package_dependencies so that an explicitly empty list yields an empty main dependency group rather than being ignored

Tests:

  • Add sample_project_new_no_deps fixture and test_create_poetry_with_empty_dependencies to verify handling of empty dependencies

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 21, 2025

Reviewer's Guide

This PR updates the package dependency setup in Factory._configure_package_dependencies to distinguish explicitly empty dependency lists from entirely missing dependencies, and adds new tests and fixtures to verify behavior when no dependencies are defined.

Sequence diagram for dependency configuration logic in Factory._configure_package_dependencies

sequenceDiagram
    participant Factory
    participant Project
    participant DependencyGroup
    Factory->>Project: get("dependencies")
    Factory->>Project: get("optional-dependencies")
    Factory->>Project: get("dynamic")
    alt dependencies is not None or optional_dependencies exists
        Factory->>DependencyGroup: create with MAIN_GROUP and mixed_dynamic
    end
Loading

Class diagram for updated dependency handling in Factory._configure_package_dependencies

classDiagram
    class Factory {
        _configure_package_dependencies(project)
    }
    class DependencyGroup {
        MAIN_GROUP
        mixed_dynamic
    }
    Factory --> DependencyGroup : creates
    class Project {
        dependencies
        optional-dependencies
        dynamic
    }
    Factory ..> Project : reads
    class Dependency {}
    class NormalizedName {}
    DependencyGroup "1" -- "*" Dependency : contains
    DependencyGroup "1" -- "*" NormalizedName : uses
Loading

File-Level Changes

Change Details Files
Differentiate between missing and empty dependency list in package configuration
  • Use project.get("dependencies") without a default fallback
  • Change the if condition to check dependencies is not None or optional_dependencies
  • Fallback to an empty dict only when dependencies is falsy
src/poetry/core/factory.py
Add tests and fixtures for empty dependencies scenario
  • Add test_create_poetry_with_empty_dependencies with detailed assertions
  • Include a pyproject.toml fixture defining no dependencies
  • Add corresponding README.rst fixture under sample_project_new_no_deps
tests/test_factory.py
tests/fixtures/sample_project_new_no_deps/pyproject.toml
tests/fixtures/sample_project_new_no_deps/README.rst

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!

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 there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `tests/test_factory.py:316-325` </location>
<code_context>
+def test_create_poetry_with_empty_dependencies() -> None:
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding a test for the case where dependencies are not defined at all.

Please add a test for when the dependencies key is missing from pyproject.toml to ensure both scenarios are covered.

Suggested implementation:

```python
def test_create_poetry_with_empty_dependencies() -> None:
    project = "sample_project_new_no_deps"
    poetry = Factory().create_poetry(fixtures_dir / project)

    assert poetry.is_package_mode

    package = poetry.package

    assert "main" in package._dependency_groups
    assert package._dependency_groups["main"].dependencies == []

def test_create_poetry_with_no_dependencies_key() -> None:
    project = "sample_project_new_no_dependencies_key"
    poetry = Factory().create_poetry(fixtures_dir / project)

    assert poetry.is_package_mode

    package = poetry.package

    assert "main" in package._dependency_groups
    assert package._dependency_groups["main"].dependencies == []

```

You will need to add a fixture directory (e.g., `fixtures_dir / "sample_project_new_no_dependencies_key"`) containing a `pyproject.toml` file that does NOT have a `[tool.poetry.dependencies]` section. This ensures the test is valid and passes.
</issue_to_address>

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.

@finswimmer finswimmer force-pushed the i10557-empty-dependency-list branch from c31dcfc to d1a9f33 Compare October 26, 2025 19:22
@finswimmer finswimmer requested a review from radoering October 28, 2025 20:33
@radoering radoering merged commit d46a257 into python-poetry:main Oct 29, 2025
22 checks passed
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.

Implicit main dependency group does not exist when specifying project.dependencies = []

2 participants