generated from Justintime50/python-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4ec458d
Showing
19 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[report] | ||
exclude_lines = | ||
if __name__ == '__main__': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
max-line-length = 100 | ||
extend-ignore = E203 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: build | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
- name: Install Dependencies | ||
run: make install | ||
- name: Check format | ||
run: make format-check | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
pythonversion: ["3.7", "3.8", "3.9", "3.10"] | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.pythonversion }} | ||
- name: Install Dependencies | ||
run: make install | ||
- name: Run tests | ||
run: make coverage | ||
- name: Coveralls | ||
if: github.ref == 'refs/heads/main' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: venv/bin/coveralls --service=github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
- name: Install pypa/build | ||
run: >- | ||
python -m | ||
pip install | ||
build | ||
--user | ||
- name: Build a binary wheel and a source tarball | ||
run: >- | ||
python -m | ||
build | ||
--sdist | ||
--wheel | ||
--outdir dist/ | ||
. | ||
# Uncomment for your project | ||
# - name: Publish to PyPI | ||
# uses: pypa/gh-action-pypi-publish@master | ||
# with: | ||
# password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.env | ||
.DS_Store | ||
__pycache__ | ||
build | ||
dist | ||
*.egg-info | ||
venv | ||
htmlcov | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# CHANGELOG | ||
|
||
## v1.7.0 (2021-11-29) | ||
|
||
* Adds `mypy` and type hinting via `py.typed` | ||
* Simplifies template module (removes unused class) | ||
* Adds missing `__all__` variable to `__init__.py` | ||
* Simplifies the lint step of the build by only running checks once (previously some checks were getting run twice) | ||
* Tests against Python `3.10` | ||
|
||
## v1.6.0 (2021-10-08) | ||
|
||
* Adds `Black` and `iSort` as dev dependencies | ||
* Adds a `pyproject.toml` file to configure Python tools | ||
* Completely refactors the `Makefile` to include new tools and better ways of invoking previous ones | ||
* Removes `.github/FUNDING.yml` file in favor of `.github` global files | ||
|
||
## v1.5.0 (2021-09-10) | ||
|
||
* Drops support for Python 3.6 | ||
* Removes the `mock` library in favor of the builtin `unittest.mock` library | ||
* Fix some typos | ||
|
||
## v1.4.0 (2021-07-12) | ||
|
||
* Clarified various pieces of info | ||
* Unified more text replacements for easier usage of the template when getting started | ||
|
||
## v1.3.0 (2021-05-31) | ||
|
||
* Pins dependencies and moves them to a constant | ||
* Adds missing lines to code coverage report | ||
|
||
## v1.2.0 (2021-01-30) | ||
|
||
* Fixed the Coveralls command in GitHub Actions, builds now pass with their new platform requirement flag | ||
* Added a `release.yml` file to automate PyPI releasing via GitHub Actions | ||
|
||
## v1.1.1 (2021-01-09) | ||
|
||
* Removed all references to Travis-CI and replace with GitHub Actions | ||
* Bumped the year in LICENSE | ||
* Added clarifying statement in README to remove all extra assets | ||
|
||
## v1.1.0 (2021-01-05) | ||
|
||
* Added GitHub Actions | ||
* Added `conftest.py` | ||
* Updated `README` with much more verbose instructions on changing details of the project to get you started | ||
* Added test coverage | ||
* Correcting lint Makefile target to point to the unit folder | ||
|
||
## v1.0.0 (2020-11-19) | ||
|
||
* Initial release | ||
* Makefile, README, setup.py, .travis.yml, LICENSE, test suite, module, assets, and more included to save time and energy on your next Python project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Justin Hammond | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
PYTHON_BINARY := python3 | ||
VIRTUAL_BIN := venv/bin | ||
PROJECT_NAME := project_name | ||
TEST_DIR := test | ||
|
||
## help - Display help about make targets for this Makefile | ||
help: | ||
@cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t | ||
|
||
## build - Builds the project in preparation for release | ||
build: | ||
$(PYTHON_BINARY) setup.py sdist bdist_wheel | ||
|
||
## coverage - Test the project and generate an HTML coverage report | ||
coverage: | ||
$(VIRTUAL_BIN)/pytest --cov=$(PROJECT_NAME) --cov-branch --cov-report=html --cov-report=term-missing | ||
|
||
## clean - Remove the virtual environment and clear out .pyc files | ||
clean: | ||
rm -rf ~/.venv/$(PROJECT_NAME)/ venv | ||
find . -name '*.pyc' -delete | ||
rm -rf dist | ||
rm -rf build | ||
rm -rf *.egg-info | ||
|
||
## black - Runs the Black Python formatter against the project | ||
black: | ||
$(VIRTUAL_BIN)/black $(PROJECT_NAME)/ $(TEST_DIR)/ | ||
|
||
## black-check - Checks if the project is formatted correctly against the Black rules | ||
black-check: | ||
$(VIRTUAL_BIN)/black $(PROJECT_NAME)/ $(TEST_DIR)/ --check | ||
|
||
## format - Runs all formatting tools against the project | ||
format: black isort lint mypy | ||
|
||
## format-check - Checks if the project is formatted correctly against all formatting rules | ||
format-check: black-check isort-check lint mypy | ||
|
||
## install - Install the project locally | ||
install: | ||
$(PYTHON_BINARY) -m venv ~/.venv/$(PROJECT_NAME)/ | ||
ln -snf ~/.venv/$(PROJECT_NAME)/ venv | ||
$(VIRTUAL_BIN)/pip install -e ."[dev]" | ||
|
||
## isort - Sorts imports throughout the project | ||
isort: | ||
$(VIRTUAL_BIN)/isort $(PROJECT_NAME)/ $(TEST_DIR)/ | ||
|
||
## isort-check - Checks that imports throughout the project are sorted correctly | ||
isort-check: | ||
$(VIRTUAL_BIN)/isort $(PROJECT_NAME)/ $(TEST_DIR)/ --check-only | ||
|
||
## lint - Lint the project | ||
lint: | ||
$(VIRTUAL_BIN)/flake8 $(PROJECT_NAME)/ $(TEST_DIR)/ | ||
|
||
## mypy - Run mypy type checking on the project | ||
mypy: | ||
$(VIRTUAL_BIN)/mypy $(PROJECT_NAME)/ $(TEST_DIR)/ | ||
|
||
## test - Test the project | ||
test: | ||
$(VIRTUAL_BIN)/pytest | ||
|
||
.PHONY: help build coverage clean black black-check format format-check install isort isort-check lint mypy test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<div align="center"> | ||
|
||
# Python Template | ||
|
||
A Python project template to save you time and energy. | ||
|
||
[![Build Status](https://github.com/Justintime50/python-template/workflows/build/badge.svg)](https://github.com/Justintime50/python-template/actions) | ||
[![Coverage Status](https://coveralls.io/repos/github/Justintime50/python-template/badge.svg?branch=main)](https://coveralls.io/github/Justintime50/python-template?branch=main) | ||
[![Licence](https://img.shields.io/github/license/justintime50/python-template)](LICENSE) | ||
|
||
<img src="https://raw.githubusercontent.com/justintime50/assets/main/src/python-template/showcase.png" alt="Showcase"> | ||
|
||
</div> | ||
|
||
Python projects take a long time to setup with all the various files, the virtual environment, and keeping things uniform across projects. With this Python template, you can quickly setup boilerplate code and miscellaneous items for your Python project saving you time and energy so you can get back to coding. | ||
|
||
## Install | ||
|
||
Click the `Use this template` button at the top of this project's GitHub page, it looks like this: | ||
|
||
<img src="https://raw.githubusercontent.com/justintime50/assets/main/src/templates/use_template_button.png" alt="Use Template Button"> | ||
|
||
## Usage | ||
|
||
**Easy text replacements** | ||
|
||
1. Replace all instances of `project_name` with the name of your project | ||
* These are the Python snake_case references (eg: `project_name`) | ||
1. Replace all instances of `PROJECT_NAME_URL` with the name of your project | ||
* These are the references to your project that will appear in URLs and are typically hyphenated (eg: `project-name`) | ||
1. Replace all instances of `USERNAME` with the name of the author or owner of the project | ||
* These are references typically found in the URL of your project as it appears on GitHub | ||
|
||
**File configuration** | ||
|
||
1. Configure the `setup.py` file | ||
1. Configure the `Makefile` targets | ||
1. Update the name in the `LICENSE` or swap it out entirely | ||
1. Configure the `.github/workflows/build.yml` file | ||
1. Update the `CHANGELOG.md` with your own info | ||
1. Rename other files/folders as needed and configure their content | ||
1. Delete this `README` and rename `README_project.md` to `README.md` | ||
|
||
**GitHub configuration** | ||
|
||
1. Add a `PYPI_API_TOKEN` GitHub secret to your project so that automated releasing can occur from GitHub Actions to PyPI and uncomment the final step on the `release` job in `.github/workflows/release.yml` | ||
|
||
## Attribution | ||
|
||
* Watch [the video](https://youtu.be/ZMfcl3CnRhA) where I built this template. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<div align="center"> | ||
|
||
# PROJECT_NAME_URL | ||
|
||
A one-liner description of your project goes here. | ||
|
||
[![Build Status](https://github.com/USERNAME/PROJECT_NAME_URL/workflows/build/badge.svg)](https://github.com/USERNAME/PROJECT_NAME_URL/actions) | ||
[![Coverage Status](https://coveralls.io/repos/github/USERNAME/PROJECT_NAME_URL/badge.svg?branch=main)](https://coveralls.io/github/USERNAME/PROJECT_NAME_URL?branch=main) | ||
[![PyPi](https://img.shields.io/pypi/v/PROJECT_NAME_URL)](https://pypi.org/project/PROJECT_NAME_URL) | ||
[![Licence](https://img.shields.io/github/license/USERNAME/PROJECT_NAME_URL)](LICENSE) | ||
|
||
<img src="https://raw.githubusercontent.com/justintime50/assets/main/src/python-template/showcase.png" alt="Showcase"> | ||
|
||
</div> | ||
|
||
A longer paragraph description of your project goes here. | ||
|
||
## Install | ||
|
||
```bash | ||
# Install tool | ||
pip3 install project_name | ||
|
||
# Install locally | ||
make install | ||
``` | ||
|
||
## Usage | ||
|
||
Usage instructions go here. | ||
|
||
```bash | ||
venv/bin/python my_script.py | ||
``` | ||
|
||
## Development | ||
|
||
```bash | ||
# Get a comprehensive list of development tools | ||
make help | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from project_name.my_module import main | ||
|
||
__all__ = [ | ||
'main', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
def main(): | ||
"""The main entrypoint for this script used in the setup.py file.""" | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[tool.black] | ||
experimental-string-processing = true | ||
line-length = 120 | ||
skip-string-normalization = true | ||
|
||
[tool.isort] | ||
profile = "black" |
Oops, something went wrong.