Skip to content

Commit

Permalink
feat: justfile, bandit, cleanup, version const, drop py37
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Aug 25, 2023
1 parent 1c769cc commit b688c14
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 108 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[report]
exclude_lines =
if __name__ == '__main__':
[run]
omit = project_name/_version.py
58 changes: 35 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
name: build

on: [push, pull_request]
on:
push:
paths:
- '.github/workflows/build.yml'
- '**/*.py'
branches:
- '**'
tags:
- '!**'
pull_request:
paths:
- '.github/workflows/build.yml'
- '**/*.py'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
- uses: actions/checkout@v3
- uses: extractions/setup-just@v1
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Dependencies
run: make install
- name: Check format
run: make format-check
python-version: '3.11'
- run: just install lint
test:
runs-on: ubuntu-latest
strategy:
matrix:
pythonversion: ["3.7", "3.8", "3.9", "3.10", "3.11"]
pythonversion: ['3.8', '3.9', '3.10', '3.11']
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
- uses: actions/checkout@v3
- uses: extractions/setup-just@v1
- uses: actions/setup-python@v4
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'
uses: coverallsapp/github-action@master
- run: just install coverage
coverage:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: extractions/setup-just@v1
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- run: just install coverage
- uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: "./coverage.lcov"
path-to-lcov: './coverage.lcov'
25 changes: 11 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@ name: release
on:
push:
tags:
- "*"
- '*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
- uses: actions/checkout@v3
- uses: extractions/setup-just@v1
- uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: '3.11'
- name: Build package
run: |
make install
make build
# Uncomment for your project
# - name: Publish to PyPI
# uses: pypa/gh-action-pypi-publish@master
# with:
# password: ${{ secrets.PYPI_API_TOKEN }}
run: just install build
# Uncomment for your project
# - name: Publish to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# password: ${{ secrets.PYPI_API_TOKEN }}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## v1.10.0 (2023-08-24)

- Drops Python 3.7 support
- Swaps the Makefile for a Justfile
- Overhauls version constant and usage (uniform between `setup.py` and package code)
- Cleans up GitHub Action workflows
- Adds `bandit` dev dependency

## v1.9.1 (2023-05-08)

- Fixes a replacement typo in setup.py for `package_data`
Expand Down
63 changes: 0 additions & 63 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Click the [Use this template](https://github.com/Justintime50/python-template/ge
### File configuration

1. Configure the `setup.py` file
1. Configure the `Makefile` targets
1. Configure the `justfile` 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
Expand Down
4 changes: 2 additions & 2 deletions README_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A longer paragraph description of your project goes here.
pip3 install project_name

# Install locally
make install
just install
```

## Usage
Expand All @@ -37,5 +37,5 @@ venv/bin/python my_script.py

```bash
# Get a comprehensive list of development tools
make help
just --list
```
61 changes: 61 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
PYTHON_BINARY := "python3"
VIRTUAL_ENV := "venv"
VIRTUAL_BIN := VIRTUAL_ENV / "bin"
PROJECT_NAME := "project_name"
TEST_DIR := "test"

# Scans the project for security vulnerabilities
bandit:
{{VIRTUAL_BIN}}/bandit -r {{PROJECT_NAME}}/

# Builds the project in preparation for release
build:
{{VIRTUAL_BIN}}/python -m build

# Runs the Black Python formatter against the project
black:
{{VIRTUAL_BIN}}/black {{PROJECT_NAME}}/ {{TEST_DIR}}/

# Checks if the project is formatted correctly against the Black rules
black-check:
{{VIRTUAL_BIN}}/black {{PROJECT_NAME}}/ {{TEST_DIR}}/ --check

# Test the project and generate an HTML coverage report
coverage:
{{VIRTUAL_BIN}}/pytest --cov={{PROJECT_NAME}} --cov-branch --cov-report=html --cov-report=lcov --cov-report=term-missing --cov-fail-under=90

# Cleans the project
clean:
rm -rf {{VIRTUAL_ENV}} dist *.egg-info .coverage htmlcov .*cache
find . -name '*.pyc' -delete

# Run flake8 checks against the project
flake8:
{{VIRTUAL_BIN}}/flake8 {{PROJECT_NAME}}/ {{TEST_DIR}}/

# Lints the project
lint: black-check isort-check flake8 mypy bandit

# Runs all formatting tools against the project
lint-fix: black isort

# Install the project locally
install:
{{PYTHON_BINARY}} -m venv {{VIRTUAL_ENV}}
{{VIRTUAL_BIN}}/pip install -e ."[dev]"

# Sorts imports throughout the project
isort:
{{VIRTUAL_BIN}}/isort {{PROJECT_NAME}}/ {{TEST_DIR}}/

# Checks that imports throughout the project are sorted correctly
isort-check:
{{VIRTUAL_BIN}}/isort {{PROJECT_NAME}}/ {{TEST_DIR}}/ --check-only

# Run mypy type checking on the project
mypy:
{{VIRTUAL_BIN}}/mypy {{PROJECT_NAME}}/ {{TEST_DIR}}/

# Test the project
test:
{{VIRTUAL_BIN}}/pytest
1 change: 1 addition & 0 deletions project_name/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.1.0'
21 changes: 16 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import re

import setuptools

with open('README.md', 'r') as fh:
long_description = fh.read()
with open('README.md', 'r') as readme_file:
long_description = readme_file.read()

# Inspiration: https://stackoverflow.com/a/7071358/6064135
with open('project_name/_version.py', 'r') as version_file:
version_groups = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file.read(), re.M)
if version_groups:
version = version_groups.group(1)
else:
raise RuntimeError('Unable to find version string!')

REQUIREMENTS = [
# Add your list of production dependencies here, eg:
# 'requests == 2.*',
]

DEV_REQUIREMENTS = [
'bandit == 1.7.*',
'black == 23.*',
'build == 0.10.*',
'flake8 == 6.*',
'isort == 5.*',
'mypy == 1.2',
'mypy == 1.5.*',
'pytest == 7.*',
'pytest-cov == 4.*',
'twine == 4.*',
]

setuptools.setup(
name='PROJECT_NAME_URL',
version='0.1.0',
version=version,
description='Your project description here',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down Expand Up @@ -53,5 +64,5 @@
'PROJECT_NAME_URL=project_name.my_module:main',
]
},
python_requires='>=3.7, <4',
python_requires='>=3.8, <4',
)

0 comments on commit b688c14

Please sign in to comment.