You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Install Python 3.13
pyenv install 3.13.0a4 # or latest alpha/beta version# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
# Set Python version for the project
pyenv local 3.13.0a4
Project Initialization
# Create new project
poetry new --src your-project-name
cd your-project-name
# Initialize git
git init
# Install dependencies
poetry install
# Setup pre-commit
poetry run pre-commit install
# Add new project dependency
poetry add package-name
# Add development dependency
poetry add --group dev package-name
# Update all dependencies
poetry update
# Update specific package
poetry update package-name
# Show outdated packages
poetry show --outdated
# Export requirements.txt (if needed)
poetry export -f requirements.txt --output requirements.txt
poetry export -f requirements.txt --output requirements-dev.txt --with dev
Environment Management
# Activate virtual environment
poetry shell
# Run command in virtual environment without activation
poetry run python script.py
# Show environment information
poetry env info
# List all environments
poetry env list
# Remove environment
poetry env remove python
Dependency Groups Management
# Install all dependencies (including dev)
poetry install
# Install only production dependencies
poetry install --without dev
# Update lock file
poetry lock --no-update
# Show dependency tree
poetry show --tree
Pre-commit Configuration
Installation and Setup
# Install pre-commit in project
poetry add --group dev pre-commit
# Install pre-commit hooks
poetry run pre-commit install
# Install pre-commit hooks for commit messages (optional)
poetry run pre-commit install --hook-type commit-msg
# Update pre-commit hooks
poetry run pre-commit autoupdate
Manual Runs
# Run all pre-commit hooks
poetry run pre-commit run --all-files
# Run specific hook
poetry run pre-commit run autopep8 --all-files
poetry run pre-commit run ruff --all-files
poetry run pre-commit run mypy --all-files
# Run hooks on specific files
poetry run pre-commit run --files src/your_package/specific_file.py
Manual Code Quality Checks
Code Formatting (autopep8)
# Format single file
poetry run autopep8 --in-place --aggressive --aggressive --aggressive src/your_package/file.py
# Format entire project
poetry run autopep8 --in-place --aggressive --aggressive --aggressive --recursive src/
# Format with specific rules
poetry run autopep8 --in-place --select E,W,F --max-line-length=88 src/
Linting (Ruff)
# Run linter
poetry run ruff check src/
# Run with automatic fixes
poetry run ruff check --fix src/
# Check specific file
poetry run ruff check src/your_package/file.py
# Show error explanations
poetry run ruff check --show-source src/
Type Checking (MyPy)
# Run type checker
poetry run mypy src/
# Run with specific flags
poetry run mypy --strict src/
# Check single file
poetry run mypy src/your_package/file.py
Security Checks (Bandit)
# Run security checks
poetry run bandit -r src/
# Run with specific severity
poetry run bandit -r -ll src/ # Only high severity issues
Common Tasks
Testing
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov=src
# Run specific test file
poetry run pytest tests/test_specific.py
# Run tests matching pattern
poetry run pytest -k "test_pattern"
Code Coverage
# Generate coverage report
poetry run pytest --cov=src --cov-report=html
# Show coverage in terminal
poetry run pytest --cov=src --cov-report=term-missing