|
1 | | -# Modern Python Project |
| 1 | +# Modern Python Project Template |
2 | 2 |
|
3 | 3 | [](https://pypi.org/project/modern-python-project/) |
4 | 4 |
|
5 | | -Pydantic data model for [Notion](https://www.notion.so/). |
| 5 | +A comprehensive, production-ready Python project template |
| 6 | +that incorporates modern development practices, tools, and workflows. |
| 7 | +This template provides everything you need to start developing, |
| 8 | +testing, and deploying Python packages with confidence. |
6 | 9 |
|
7 | | -Install via: |
| 10 | +## 🚀 Key Features & Advantages |
| 11 | + |
| 12 | +### Development Environment |
| 13 | + |
| 14 | +- **[devenv.sh](https://devenv.sh/)** - Reproducible development environments using Nix |
| 15 | +- **Cross-platform support** - Works on macOS and Linux with conditional package loading |
| 16 | +- **[direnv](https://direnv.net/docs/installation.html)** integration for automatic environment activation |
| 17 | +- **Python 3.12** with modern tooling |
| 18 | + |
| 19 | +### Package Management & Building |
| 20 | + |
| 21 | +- **[uv](https://github.com/astral-sh/uv)** - Ultra-fast Python package installer and resolver |
| 22 | +- **[hatchling](https://hatch.pypa.io/)** - Modern build backend |
| 23 | +- **Dynamic versioning** from Git tags using `uv-dynamic-versioning` |
| 24 | +- **Dependency groups** for clean separation of dev/prod dependencies |
| 25 | + |
| 26 | +### Code Quality & Testing |
| 27 | + |
| 28 | +- **[pytest](https://pytest.org/)** with async support and comprehensive plugins: |
| 29 | + - Coverage reporting with HTML output |
| 30 | + - Snapshot testing with [syrupy](https://github.com/tophat/syrupy) |
| 31 | + - Watch mode with [pytest-watcher](https://github.com/olzhasar/pytest-watcher) |
| 32 | +- **[ruff](https://github.com/astral-sh/ruff)** - Lightning-fast linting and formatting |
| 33 | +- **Pre-commit hooks** with comprehensive checks: |
| 34 | + - Code formatting (ruff-format) |
| 35 | + - Import sorting |
| 36 | + - TOML validation |
| 37 | + - Markdown formatting |
| 38 | + - Security scanning (trufflehog) |
| 39 | + - Shell script checking |
| 40 | + - Typo detection |
| 41 | + |
| 42 | +### CI/CD & Publishing |
| 43 | + |
| 44 | +- **GitHub Actions** workflow with: |
| 45 | + - Multi-OS testing (Ubuntu + macOS) |
| 46 | + - Automatic PyPI publishing on tags |
| 47 | + - Trusted publishing (no API keys needed) |
| 48 | + - Artifact storage |
| 49 | +- **Renovate** for automated dependency updates |
| 50 | +- **Semantic versioning** with automatic tag-based releases |
| 51 | + |
| 52 | +### Documentation & Maintenance |
| 53 | + |
| 54 | +- **Markdown linting** with customizable rules |
| 55 | +- **License** (MIT) included |
| 56 | +- **Comprehensive .gitignore** for Python projects |
| 57 | +- **VS Code configuration** for optimal development experience |
| 58 | + |
| 59 | +## 🛠 Setup Instructions |
| 60 | + |
| 61 | +### Prerequisites |
| 62 | + |
| 63 | +- [Nix](https://nixos.org/download.html) package manager |
| 64 | +- [direnv](https://direnv.net/docs/installation.html) (recommended) |
| 65 | + |
| 66 | +### Quick Start |
| 67 | + |
| 68 | +1. **Clone and setup:** |
| 69 | + |
| 70 | + ```bash |
| 71 | + git clone <your-repo-url> |
| 72 | + cd modern-python-project |
| 73 | + direnv allow # If using direnv |
| 74 | + # OR |
| 75 | + nix develop # If not using direnv |
| 76 | + ``` |
| 77 | + |
| 78 | +1. **Install dependencies:** |
| 79 | + |
| 80 | + ```bash |
| 81 | + # Dependencies are automatically installed via devenv |
| 82 | + # But you can manually sync if needed: |
| 83 | + uv sync --all-extras |
| 84 | + ``` |
| 85 | + |
| 86 | +1. **Run tests:** |
| 87 | + |
| 88 | + ```bash |
| 89 | + test-all |
| 90 | + ``` |
| 91 | + |
| 92 | +1. **Start developing:** |
| 93 | + |
| 94 | + ```bash |
| 95 | + # Watch mode for tests |
| 96 | + test-watch |
| 97 | + |
| 98 | + # Format code |
| 99 | + format |
| 100 | + |
| 101 | + # Build package |
| 102 | + build |
| 103 | + ``` |
| 104 | + |
| 105 | +### Environment Setup Details |
| 106 | + |
| 107 | +The development environment provides these commands: |
| 108 | + |
| 109 | +- `build` - Build the Python package |
| 110 | +- `format` - Run all formatters and linters |
| 111 | +- `test-all` - Run the complete test suite |
| 112 | +- `test-snapshot-update` - Update test snapshots |
| 113 | +- `test-watch` - Run tests in watch mode |
| 114 | +- `deps-upgrade` - Upgrade all dependencies |
| 115 | + |
| 116 | +## 📁 Project Structure |
8 | 117 |
|
9 | 118 | ```sh |
10 | | -pip install modern-python-project |
| 119 | +modern-python-project/ |
| 120 | +├── modern_python_project/ # Main package code |
| 121 | +│ ├── __init__.py |
| 122 | +│ ├── main.py # CLI entry point |
| 123 | +│ └── my_function.py # Example module |
| 124 | +├── modern_python_project_tests/ # Test package |
| 125 | +│ ├── __snapshots__/ # Snapshot test files |
| 126 | +│ ├── test_cli.py # CLI tests |
| 127 | +│ └── test_my_function.py # Module tests |
| 128 | +├── devenv.nix # Development environment config |
| 129 | +├── devenv.yaml # devenv input configuration |
| 130 | +├── pyproject.toml # Project metadata and tool config |
| 131 | +├── uv.lock # Locked dependencies |
| 132 | +└── README.md # This file |
11 | 133 | ``` |
12 | 134 |
|
13 | | -## Development |
| 135 | +## 🔧 Configuration |
| 136 | + |
| 137 | +### Python Dependencies |
| 138 | + |
| 139 | +Dependencies are managed in `pyproject.toml`: |
| 140 | + |
| 141 | +- **Main dependencies:** Listed under `dependencies` |
| 142 | +- **Development dependencies:** Listed under `dependency-groups.dev` |
| 143 | + |
| 144 | +### Testing Configuration |
| 145 | + |
| 146 | +- **Coverage:** Configured to maintain 80% minimum coverage |
| 147 | +- **Pytest:** Async support enabled, comprehensive reporting |
| 148 | +- **Snapshots:** Automatic snapshot testing for CLI and functions |
| 149 | + |
| 150 | +### Code Quality |
| 151 | + |
| 152 | +- **Ruff:** Fast linting and formatting with import sorting |
| 153 | +- **Pre-commit:** Comprehensive hooks for code quality |
| 154 | +- **Coverage:** HTML reports generated in `coverage_html/` |
| 155 | + |
| 156 | +## 🚀 Development Workflow |
| 157 | + |
| 158 | +1. **Make changes** to your code |
| 159 | +1. **Run tests** with `test-watch` for immediate feedback |
| 160 | +1. **Format code** with `format` before committing |
| 161 | +1. **Commit changes** - pre-commit hooks will run automatically |
| 162 | +1. **Push to GitHub** - CI will run tests on multiple platforms |
| 163 | +1. **Create release** by pushing a tag (format: `vX.X.X`) |
| 164 | + |
| 165 | +## 📦 Publishing |
| 166 | + |
| 167 | +Publishing to PyPI is fully automated: |
| 168 | + |
| 169 | +1. Create a new tag: `git tag v1.0.0` |
| 170 | +1. Push the tag: `git push origin v1.0.0` |
| 171 | +1. GitHub Actions will automatically build and publish to PyPI |
| 172 | + |
| 173 | +The project uses trusted publishing, so no API keys are required. |
| 174 | + |
| 175 | +## 🌟 Why This Template? |
| 176 | + |
| 177 | +This template embodies modern Python development best practices: |
| 178 | + |
| 179 | +- **Fast feedback loops** with watch mode testing |
| 180 | +- **Consistent code quality** with automated formatting and linting |
| 181 | +- **Reliable builds** with locked dependencies and reproducible environments |
| 182 | +- **Secure publishing** with trusted publishing and no stored secrets |
| 183 | +- **Cross-platform support** with conditional package loading |
| 184 | +- **Comprehensive testing** with coverage tracking and snapshot testing |
| 185 | +- **Automated maintenance** with dependency updates and security scanning |
| 186 | + |
| 187 | +Perfect for both solo projects and team development, this template scales |
| 188 | +from simple scripts to complex packages while maintaining development velocity and code quality. |
| 189 | + |
| 190 | +## 📄 License |
| 191 | + |
| 192 | +MIT License - see [LICENSE](LICENSE) file for details. |
14 | 193 |
|
15 | | -This repository uses [devenv](https://devenv.sh/). |
16 | | -Devenv and enabled direnv will give you the best developer experience. |
| 194 | +## 🤝 Contributing |
17 | 195 |
|
18 | | -## Releasing |
| 196 | +1. Fork the repository |
| 197 | +1. Create a feature branch |
| 198 | +1. Make your changes |
| 199 | +1. Run the test suite |
| 200 | +1. Submit a pull request |
19 | 201 |
|
20 | | -Create a new release [here](/joscha/modern-python-project/releases/new). |
21 | | -Choose a semver-style tag (i.e. `vX.X.X`). Make sure it has the `v` prefix. |
| 202 | +The pre-commit hooks and CI will ensure code quality and test coverage. |
0 commit comments