|
1 | 1 | # Python Starter |
2 | 2 |
|
3 | | -The Python Starter is a [GitHub repository template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template) that provides a minimalistic boilerplate to kickstart your [Python](https://www.python.org/) project. This template offers a streamlined foundation, complete with predefined file structures, essential tools, and recommended settings, ensuring a swift and efficient start to your Python development journey. |
| 3 | +A minimalist template for starting a new [Python](https://www.python.org/) project. |
| 4 | + |
| 5 | +This template provides a basic Python project containing an example package with built-in support for formatting, linting, testing, and continuous integration. |
4 | 6 |
|
5 | 7 | ## Key Features |
6 | 8 |
|
7 | | -- Organized file structure for Python projects, featuring a sample `pyproject.toml`, a sample module, and associated testing files. |
8 | | -- Project and dependency management with [uv](https://docs.astral.sh/uv/). |
9 | | -- Code formatting and linting with [Ruff](https://github.com/astral-sh/ruff), leveraging all recommended rules for enhanced code quality. |
10 | | -- Testing framework powered by [Pytest](https://docs.pytest.org/en/7.4.x/), complete with support for test coverage checks. |
11 | | -- [GitHub Actions](https://github.com/features/actions) support with multiple workflows for continuous integration (CI) and continuous delivery (CD). |
12 | | -- Automated dependency update checks with [Dependabot](https://docs.github.com/en/code-security/dependabot). |
| 9 | +* Uses [uv](https://docs.astral.sh/uv/) as the package manager. |
| 10 | +* Supports formatting and linting with [Ruff](https://github.com/astral-sh/ruff), and testing with [Pytest](https://docs.pytest.org/en/stable/). |
| 11 | +* Fixes formatting and linting during pre-commit hooks using [Lefthook](https://lefthook.dev/). |
| 12 | +* Preconfigured workflows for [Dependabot](https://docs.github.com/en/code-security/dependabot) and [GitHub Actions](https://github.com/features/actions). |
13 | 13 |
|
14 | 14 | ## Usage |
15 | 15 |
|
16 | | -Refer to [this wiki](https://github.com/threeal/python-starter/wiki) for information on how to use this template. |
| 16 | +This guide explains how to use this template to start a new Python project, from creation to release. |
| 17 | + |
| 18 | +### Create a New Project |
| 19 | + |
| 20 | +Follow [this link](https://github.com/new?template_name=python-starter&template_owner=threeal) to create a new project based on this template. For more information about creating a repository from a template on GitHub, refer to [this documentation](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template). |
| 21 | + |
| 22 | +Alternatively, you can clone this repository locally to begin using this template. |
| 23 | + |
| 24 | +### Set Up Tools |
| 25 | + |
| 26 | +#### Set Up Package Manager |
| 27 | + |
| 28 | +This template uses [uv](https://docs.astral.sh/uv/) as the package manager. If uv is not installed, follow [this guide](https://docs.astral.sh/uv/getting-started/installation/) to install it. Then, synchronize the project dependencies with: |
| 29 | + |
| 30 | +```sh |
| 31 | +uv sync |
| 32 | +``` |
| 33 | + |
| 34 | +For more information on uv, including adding dependencies or running tools, refer to [this documentation](https://docs.astral.sh/uv/guides/). |
| 35 | + |
| 36 | +#### Set Up Git Hooks |
| 37 | + |
| 38 | +This template uses [Lefthook](https://lefthook.dev/) to manage Git hooks, especially for the pre-commit hook. Lefthook will be installed as a development dependency by the package manager, and the pre-commit hook can be installed with: |
| 39 | + |
| 40 | +```sh |
| 41 | +uv run lefthook install |
| 42 | +``` |
| 43 | + |
| 44 | +After that, each commit to the project will trigger a hook that checks for formatting and linting. This ensures that committed files follow the specified rules. |
| 45 | + |
| 46 | +For more information on Lefthook and how it manages hooks, refer to [this documentation](https://lefthook.dev/usage/index.html). |
| 47 | + |
| 48 | +### Developing the Project |
| 49 | + |
| 50 | +#### Choose a License |
| 51 | + |
| 52 | +By default, this template is [unlicensed](https://unlicense.org/). Before modifying this template, it is recommended to replace the [`LICENSE`](./LICENSE) file with the license that will be used by the new project. For more information about licensing a repository, refer to [this documentation](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository). |
| 53 | + |
| 54 | +Alternatively, you can remove the `LICENSE` file or leave it as is to keep the new project unlicensed. |
| 55 | + |
| 56 | +#### Writing the Package |
| 57 | + |
| 58 | +Modify the source files under the [`src`](./src) directory to start writing the package. If you're new to Python, refer to [this documentation](https://wiki.python.org/moin/BeginnersGuide) for guidance. |
| 59 | + |
| 60 | +You can replace the [`src/bonacci`](./src/bonacci) directory with your package name. You can also add as many packages as you want to the `src` directory. Just make sure to update the contents of the [`pyproject.toml`](./pyproject.toml) file according to your package information. |
| 61 | + |
| 62 | +#### Testing the Package |
| 63 | + |
| 64 | +Test files in this template are named `test_*.py` and located in the [`tests`](./tests) directory. Write the necessary tests for your package and run them with: |
| 65 | + |
| 66 | +```sh |
| 67 | +uv run pytest -v --cov |
| 68 | +``` |
| 69 | + |
| 70 | +This template uses [Pytest](https://docs.pytest.org/en/stable/) as the testing framework. For more information on testing with Pytest, refer to [this documentation](https://docs.pytest.org/en/stable/getting-started.html). |
| 71 | + |
| 72 | +#### Push the Changes |
| 73 | + |
| 74 | +After writing and testing the package, commit the changes and push them to GitHub. Each push to the `main` branch will trigger a GitHub Actions workflow for continuous integration. For more details on GitHub Actions workflows, refer to [this documentation](https://docs.github.com/en/actions/about-github-actions/understanding-github-actions). |
| 75 | + |
| 76 | +Instead of pushing directly to the `main` branch, it is recommended to push to a separate branch and then create a pull request to merge into `main`. This allows changes to be reviewed and checked by GitHub Actions before merging. For more details on pull requests, refer to [this documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests). |
| 77 | + |
| 78 | +### Releasing the Project |
| 79 | + |
| 80 | +#### Specify Version Number |
| 81 | + |
| 82 | +Update the version number of the package in the [`pyproject.toml`](./pyproject.toml) file to match the version you plan to release. The version number usually follows the semantic versioning system. Refer to [this documentation](https://packaging.python.org/en/latest/discussions/versioning/) for more information on versioning in Python projects. |
| 83 | + |
| 84 | +#### Build the Package |
| 85 | + |
| 86 | +Before releasing, check if the package can be built with: |
| 87 | + |
| 88 | +```sh |
| 89 | +uv build |
| 90 | +``` |
| 91 | + |
| 92 | +This will create a source tarball and wheel distribution of the package under the `dist` directory. You can verify the contents of the package or install it locally to ensure that it is built correctly. For more information on building the package, refer to [this documentation](https://docs.astral.sh/uv/guides/package/#building-your-package). |
| 93 | + |
| 94 | +#### Release on GitHub |
| 95 | + |
| 96 | +Create a new tag in the `main` branch corresponding to the version number of the release, and then draft a new release using that tag. You can also include the source tarball and wheel distribution as assets in the release. Refer to [this documentation](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) for more information on managing releases on GitHub. |
| 97 | + |
| 98 | +#### Publish on PyPI |
| 99 | + |
| 100 | +Run the following command to publish the package to [PyPI](https://pypi.org/): |
| 101 | + |
| 102 | +```sh |
| 103 | +uv publish |
| 104 | +``` |
| 105 | + |
| 106 | +The command will prompt you to enter your username or token for publishing on PyPI. After publishing, wait a few minutes for the package to become available on PyPI. For more information on publishing to PyPI, refer to [this documentation](https://docs.astral.sh/uv/guides/package/#publishing-your-package). |
0 commit comments