Skip to content

Add PythonDependencyFile trait for polymorphic dependency management#7274

Open
Jenson3210 wants to merge 10 commits intomainfrom
python-dependencies-trait
Open

Add PythonDependencyFile trait for polymorphic dependency management#7274
Jenson3210 wants to merge 10 commits intomainfrom
python-dependencies-trait

Conversation

@Jenson3210
Copy link
Copy Markdown
Contributor

@Jenson3210 Jenson3210 commented Apr 3, 2026

Summary

  • Introduces the PythonDependencyFile trait with implementations for PyProjectFile (pyproject.toml), RequirementsFile (requirements.txt), and PipfileFile (Pipfile), providing a polymorphic API for dependency operations: add, upgrade, remove, change, pin transitives, and search markers
  • Refactors AddDependency, UpgradeDependencyVersion, RemoveDependency, ChangeDependency, and UpgradeTransitiveDependencyVersion to use the trait instead of duplicating TOML manipulation logic — removing ~800 lines of duplicated code
  • All recipes now work on pyproject.toml, requirements.txt, and Pipfile files
  • RequirementsFile supports scope-based filename filtering: scope=null matches all files, scope="" matches requirements.txt, scope="dev" matches requirements-dev.txt
  • PipfileFile supports [packages] and [dev-packages] sections via scope parameter, including inline table dependencies (django = {version = ">=3.2", extras = ["postgres"]})
  • Adds PipfileParser for parsing Pipfile and attaching PythonResolutionResult markers with PackageManager.Pipenv
  • Package name normalization (PEP 503) is handled internally by the trait — callers don't need to pre-normalize

Test plan

  • 41 trait unit tests (PythonDependencyFileTest) covering all trait methods, matcher, scope filtering, and static utilities
  • 15 Pipfile trait unit tests (PipfileFileTest) covering matcher, upgrade, add, remove, change, and search markers
  • All existing recipe tests pass (AddDependency, UpgradeDependencyVersion, UpgradeTransitiveDependencyVersion, RemoveDependency, ChangeDependency)
  • New requirements.txt recipe integration tests for all 4 direct-dependency recipes
  • New Pipfile recipe integration tests for all 5 recipes
  • 126 total tests passing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant