Crackerjack (ˈkra-kər-ˌjak
): a person or thing of marked excellence.
Crackerjack is an opinionated Python project management tool designed to help you create, maintain, and publish high-quality Python projects with ease. It combines best-in-class tools and a streamlined workflow to ensure code quality, consistency, and reliability.
If you're new to Crackerjack, follow these steps:
-
Install Python 3.13: Ensure you have Python 3.13 installed.
-
Install PDM:
pipx install pdm
-
Install Crackerjack:
pip install crackerjack
-
Initialize a New Project: Navigate to your project's root directory and run:
python -m crackerjack
Crackerjack is built on the following core principles:
- Code Clarity: Code should be easy to read, understand, and maintain.
- Automation: Tedious tasks should be automated, allowing developers to focus on solving problems.
- Consistency: Code style, formatting, and project structure should be consistent across projects.
- Reliability: Tests are essential, and code should be checked rigorously.
- Tool Integration: Leverage powerful existing tools instead of reinventing the wheel.
- Static Typing: Static typing is essential for all development.
Crackerjack provides:
- Effortless Project Setup: Initializes new Python projects with a standard directory structure,
pyproject.toml
, and essential configuration files. - PDM Integration: Manages dependencies and virtual environments using PDM (with uv enabled for speed).
- Automated Code Cleaning: Removes unnecessary docstrings, line comments, and trailing whitespace.
- Consistent Code Formatting: Enforces a consistent style using Ruff, the lightning-fast Python linter and formatter.
- Comprehensive Pre-commit Hooks: Installs and manages a robust suite of pre-commit hooks to ensure code quality (see the "Pre-commit Hooks" section below).
- Interactive Checks: Supports interactive pre-commit hooks (like
refurb
,bandit
, andpyright
) to allow you to fix issues in real-time. - Built-in Testing: Automatically runs tests using
pytest
. - Easy Version Bumping: Provides commands to bump the project version (micro, minor, or major).
- Simplified Publishing: Automates publishing to PyPI via PDM.
- Commit and Push: Commits and pushes your changes.
Crackerjack automatically installs and manages these pre-commit hooks:
- pdm-lock-check: Ensures the
pdm.lock
file is up to date. - Core pre-commit-hooks: Essential hooks from pre-commit-hooks (e.g.,
trailing-whitespace
,end-of-file-fixer
). - Ruff: Ruff for linting, code formatting, and general code style enforcement.
- Vulture: Vulture to identify dead code.
- Creosote: Creosote to detect unused dependencies.
- Flynt: Flynt for converting string formatting to f-strings.
- Codespell: Codespell for correcting typos in the code.
- Autotyping: Autotyping for adding type hints.
- Refurb: Refurb to suggest code improvements.
- Bandit: Bandit to identify potential security vulnerabilities.
- Pyright: Pyright for static type checking.
- Ruff (again): A final Ruff pass to ensure all changes comply with the enforced style.
Crackerjack projects adhere to these guidelines:
- Static Typing: Use type hints consistently throughout your code.
- Explicit Naming: Choose clear, descriptive names for classes, functions, variables, and other identifiers.
- Markdown for Documentation: Use Markdown (
.md
) for all documentation, READMEs, etc. - Pathlib: Use
pathlib.Path
for handling file and directory paths instead ofos.path
. - Consistent Imports: Use
import typing as t
for type hinting. - Constants and Config: Do not use all-caps for constants or configuration settings.
- Path Parameters: Functions that handle file operations should accept
pathlib.Path
objects as parameters. - Dependency Management: Use PDM for dependency management, package building, and publishing.
- Testing: Use pytest as your testing framework.
- Python Version: Crackerjack projects support the latest Python versions.
- Clear Code: Avoid overly complex code.
- Modular: Functions should do one thing well.
-
Python: Ensure you have Python 3.13 installed.
-
PDM: Install PDM using
pipx
:pipx install pdm
-
Crackerjack: Install Crackerjack and initialize in your project root using:
pip install crackerjack cd your_project_root python -m crackerjack
Run Crackerjack from the root of your Python project using:
python -m crackerjack
-c
,--commit
: Commit changes to Git.-i
,--interactive
: Run pre-commit hooks interactively when possible.-n
,--no-config-updates
: Skip updating configuration files (e.g.,pyproject.toml
).-u
,--update-precommit
: Update pre-commit hooks to the latest versions.-d
,--doc
: Generate documentation. (not yet implemented)-v
,--verbose
: Enable verbose output.-p
,--publish <micro|minor|major>
: Bump the project version and publish to PyPI using PDM.-b
,--bump <micro|minor|major>
: Bump the project version without publishing.-x
,--clean
: Clean code by removing docstrings, line comments, and extra whitespace.-t
,--test
: Run tests usingpytest
.-a
,--all
: Run with-x -t -p <micro|minor|major> -c
development options.--help
: Display help.
-
Run checks, bump version, publish, then commit:
python -m crackerjack -p minor -c
-
Clean code, run checks, run tests, then commit:
python -m crackerjack -c -x -t
-
Run checks skipping config updates:
python -m crackerjack -n
-
Bump the version and publish to PyPI:
python -m crackerjack -p micro
-
Bump the version without publishing:
python -m crackerjack -b major
-
Update pre-commit hooks:
python -m crackerjack -u
-
Get help:
python -m crackerjack --help
-
Clean code, run checks, run tests, bump version, publish, then commit:
python -m crackerjack -x -t -p minor -c # or even easier python -m crackerjack -a minor
Crackerjack is an evolving project. Contributions are welcome! Please open a pull request or issue.
To contribute:
- Add Crackerjack as a development dependency to your project:
pdm add -G dev crackerjack
- Run checks and tests before submitting:
python -m crackerjack -x -t
This ensures your code meets all quality standards before submission.
This project is licensed under the terms of the BSD 3-Clause license.
- PDM: For excellent dependency and virtual environment management.
- Ruff: For lightning-fast linting and code formatting.
- pre-commit: For the robust hook management system.
- pytest: For the flexible and powerful testing framework.
- uv: For greatly improving PDM speeds.
- bandit: For finding security vulnerabilities.
- vulture: for dead code detection.
- creosote: For unused dependency detection.
- flynt: For f-string conversion.
- codespell: For spelling correction.
- autotyping: For automatically adding type hints.
- refurb: For code improvement suggestions.
- pyright: For static type checking.
- Typer: For the creation of the CLI.