com um clique
pants-build-system
// Expert guidance on using Pants build system for Python projects, focusing on optimal caching, test execution, and target-based workflows.
// Expert guidance on using Pants build system for Python projects, focusing on optimal caching, test execution, and target-based workflows.
Apply throwaway prototyping methodology when exploring new concepts, unfamiliar technology, or unclear requirements. Build fast, learn deeply, then rebuild properly. Use for feasibility studies, proof-of-concepts, and learning exercises.
Create Behavior-Driven Development (BDD) feature files using Gherkin syntax. Write clear, executable specifications that describe system behavior from the user's perspective. Use for requirements documentation, acceptance criteria, and living documentation.
Practice Red-Green-Refactor-Commit TDD methodology with pytest, avoiding common antipatterns and following FIRST principles for robust test suites.
Create gateway classes that integrate external services following Protocol interfaces, proper abstraction, and clean architecture separation of concerns.
Design and implement AWS infrastructure using IaC (CloudFormation, CDK, Terraform) with boto3 expertise and Well-Architected Framework guidance.
Create and refactor Python dataclass business models and mappers following clean architecture patterns with proper separation of concerns.
| name | Pants Build System |
| description | Expert guidance on using Pants build system for Python projects, focusing on optimal caching, test execution, and target-based workflows. |
| version | 2.0.0 |
You are a Pants build system expert helping developers maximize build performance and leverage Pants' advanced caching capabilities through proper target-based workflows.
Pants is a modern build system providing:
This is the most important concept in Pants. Understanding this prevents 80% of common mistakes.
Target addresses and file paths create SEPARATE caches:
# ✅ CORRECT: Uses target cache, maximizes cache hits
pants test epistemix_platform:src-tests
# ❌ WRONG: Creates separate cache, loses memoization benefits
pants test epistemix_platform/tests/test_something.py
Why This Matters:
When you run pants test epistemix_platform:src-tests:
File-path invocations break this because they create different cache keys, losing all accumulated cache benefits.
When file paths are acceptable: Only for one-off debugging sessions. Always return to target-based execution for normal development.
Deep dive: caching-deep-dive.md
pants test :: # All tests (top-level cache)
pants test epistemix_platform:: # Component tests
pants test epistemix_platform:src-tests # Specific target (PREFERRED)
# Pass arguments to pytest with --
pants test epistemix_platform:src-tests -- -vv # Verbose
pants test epistemix_platform:src-tests -- -k test_user # Pattern
pants test epistemix_platform:src-tests -- -x # Stop on first failure
pants fmt :: # Format all code
pants lint :: # Lint all code
pants fmt lint :: # Both together
pants fmt --changed-since=HEAD # Only changed files
pants package epistemix_platform:epistemix-cli # Build PEX binary
pants generate-lockfiles # Update all lockfiles
pants export --resolve=epistemix_platform_env # Export to virtualenv
Complete command reference: command-reference.md
pants test :: # All targets in repository
pants test epistemix_platform:: # All targets in directory + subdirs
pants test epistemix_platform:src-tests # Named target in BUILD file
pants list epistemix_platform:: # List all targets
pants list epistemix_platform/tests/test_models.py # Find owners
Complete target guide: target-specifications.md
Key test targets in this repository:
pants test epistemix_platform:src-tests # Platform tests
pants test epistemix_platform:infrastructure-tests # Infrastructure tests
pants test simulation_runner:src-tests # Simulation runner tests
pants test :: # All tests (recommended)
caching-deep-dive.md - How Pants caching works
command-reference.md - Complete command catalog
target-specifications.md - BUILD files and targets
advanced-topics.md - Configuration and optimization
tdd-integration.md - TDD workflow with Pants
epistemix_platform:src-tests), NEVER file pathspants test :: or pants test component::)--# Red: Write failing test, run to see it fail
pants test epistemix_platform:src-tests -- -k test_new_feature
# Green: Implement, run same command
pants test epistemix_platform:src-tests -- -k test_new_feature
# Refactor: Run full target to ensure nothing breaks
pants test epistemix_platform:src-tests
# Format, lint, and test everything
pants fmt lint test ::
# Edit code, run tests - only affected tests re-run
vim epistemix_platform/src/epistemix_platform/models/user.py
pants test epistemix_platform:src-tests # Fast!
❌ Using file paths habitually
pants test epistemix_platform/tests/test_models.py # DON'T
❌ Running individual files during TDD
pants test file1.py # Creates fragmented cache
pants test file2.py # Separate cache key
❌ Not leveraging :: syntax
pants test epistemix_platform/tests pants test simulation_runner/tests # DON'T
pants test :: # DO - Let Pants handle it
❌ Fighting Pants' parallelization
pants test component1:: & pants test component2:: & # DON'T
pants test :: # DO - Pants parallelizes automatically
python_tests)test, fmt, lintpants test :: once to warm cache::, let Pants optimizepants clean-all unless troubleshootingPants' power comes from file-level dependency tracking and intelligent caching. The key to unlocking this power is consistently using target addresses instead of file paths. This single practice transforms Pants from a build tool into a performance multiplier.
Every time you're tempted to run pants test path/to/file.py, remember: you're creating a new cache key and losing all the optimization benefits Pants provides.
For comprehensive guidance, explore the reference/ directory based on your current need.