Skip to content

Commit

Permalink
Standardise common project components (#174)
Browse files Browse the repository at this point in the history
* Standardise common project components

* This commit brings files that are common to other UKHO python package repos
  into line with those other projects.
* Includes retirement of the tox tool for running tests.
* The common files were generated with the projen (github.com/projen/projen) tool,
  but for simplicity the projen components used to do this are excluded from the
  public repository.

* Fix typo in workflow

* Fix typo in Makefile

* Update dev dependencies
  • Loading branch information
lmarsden committed Nov 19, 2021
1 parent 057d41d commit 7f4ee2b
Show file tree
Hide file tree
Showing 23 changed files with 573 additions and 574 deletions.
30 changes: 30 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# .coveragerc to control coverage.py
[run]
omit =
.venv/*
tests/*

branch = True

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

# Don't complain about abstract methods, they aren't run:
@(abc.)?abstractmethod

ignore_errors = True
6 changes: 4 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
version: 2
updates:
- package-ecosystem: "pip"
- package-ecosystem: pip
directory: "/"
registries: "*"
versioning-strategy: lockfile-only
schedule:
interval: "daily"
interval: daily
66 changes: 57 additions & 9 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Dependabot auto-merge
name: Dependabot build and auto-review

on:
workflow_run:
workflows:
- 'Python Package'
branches:
- 'dependabot/**'
- 'Dependabot Build Transfer'
branches-ignore:
- 'dependabot/submodules/**'
types:
- completed

Expand All @@ -14,18 +14,66 @@ permissions:
contents: write

jobs:
dependabot:
dependabot-build:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' && github.event.workflow_run.conclusion == 'success' }}
if: ${{ github.actor == 'dependabot[bot]' }}
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
fail-fast: true

steps:
- name: Checkout gsfpy repo
uses: actions/checkout@v2
with:
ref: ${{ github.event.workflow_run.head_branch }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
- name: Free disk space on build worker
run: |
df -h
sudo apt-get clean
sudo apt-get autoclean && sudo apt-get autoremove -y
df -h
- name: Run tests
env:
run: |
poetry install
make test-all
- name: Auto-reject Failed Dependabot PR
if: ${{ failure() }}
run: gh pr review --request-changes -b "Breaking change in dependent package version detected by Dependabot. Manual resolution required." ${{ github.event.workflow_run.head_branch }}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

dependabot-merge:

runs-on: ubuntu-latest
needs: [dependabot-build]

steps:
- uses: actions/checkout@v2
- name: Checkout gsfpy repo
uses: actions/checkout@v2
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Auto-approve Dependabot PR

- name: Auto-approve Successful Dependabot PR
run: gh pr review --approve ${{ github.event.workflow_run.head_branch }}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Auto-merge Dependabot PR

- name: Auto-merge Successful Dependabot PR
if: ${{ success() }}
run: gh pr merge --auto --squash ${{ github.event.workflow_run.head_branch }}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
14 changes: 14 additions & 0 deletions .github/workflows/dependabot-build-transfer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Dependabot Build Transfer

on:
push:
branches:
- 'dependabot/**'

jobs:
build-pass:
runs-on: ubuntu-latest
steps:
# Secrets are not available to dependabot from pull_request events, but are needed for build
- name: "Skip pull_request event"
run: echo "Pass Dependabot build to workflow_run event"
28 changes: 0 additions & 28 deletions .github/workflows/python-package.yml

This file was deleted.

4 changes: 1 addition & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ jobs:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - --version 1.0.0
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
python -m pip install --upgrade pip poetry
- name: Build
run: |
make dist
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Python package

on:
push:
branches-ignore:
- 'dependabot/**'

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
fail-fast: false

steps:
- name: Checkout gsfpy repo
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
- name: Free disk space on build worker
run: |
df -h
sudo apt-get clean
sudo apt-get autoclean && sudo apt-get autoremove -y
df -h
- name: Run tests
run: |
poetry install
make test-all
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ MANIFEST.in
/releases/*
pip-wheel-metadata
/poetry.toml
requirements.txt

notebooks/

Expand Down
32 changes: 19 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ BROWSER := python -c "$$BROWSER_PYSCRIPT"
help:
@poetry run python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
clean: clean-build clean-pyc clean-test clean-venv ## remove all build, test, coverage and Python artifacts

clean-build: ## remove build artifacts
rm -fr build/
Expand All @@ -41,19 +41,25 @@ clean-pyc: ## remove Python file artifacts
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +

clean-test: ## remove test and coverage artifacts
clean-test: ## remove test and coverage artifacts (including legacy .tox directory from older versions)
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache

lint: checktypes checkstyle sast checklicenses ## run all checks
clean-venv: ## remove .venv artifacts
rm -fr .venv/

## run all static checks
lint: checktypes checkstyle sast checklicenses

checktypes: .venv ## check types with mypy
poetry run mypy --ignore-missing-imports gsfpy tests

checkstyle: .venv ## check style with flake8 and black
poetry run flake8 --ignore F401,F403,F405 gsfpy tests
## Ignore flake8 F401, F403 and F405 errors as we want to be able to use star (*) imports
## Ignore flake8 F811, 821 and W503 errors as enforcement changed between python 3.7 and 3.8
poetry run flake8 --ignore F401,F403,F405,F811,F821,W503 gsfpy tests
poetry run isort --check-only --profile black gsfpy tests
poetry run black --check --diff gsfpy tests

Expand All @@ -67,23 +73,21 @@ sast: .venv ## run static application security testing
checklicenses: .venv requirements.txt ## check dependencies meet licence rules
poetry run liccheck -s liccheck.ini

## run tests quickly with the default Python
## Multiple pytest runs are necessary as once the gsfpy package has been loaded for a
## specific version of GSF, or with a custom shared object library, it cannot be unloaded.
## run unit and component tests quickly with the default Python
test: .venv
poetry run pytest --ignore-glob=tests/gsfpy3_08/* --ignore-glob=tests/gsfpy3_09/* --ignore-glob=tests/gsfpy/test_gsffile_with_*.py --verbose --capture=no
poetry run pytest --ignore-glob=tests/gsfpy3_08/* --ignore-glob=tests/gsfpy3_09/* --ignore-glob=tests/gsfpy/test_gsffile.py --verbose --capture=no
poetry run pytest tests/gsfpy3_08/test_libgsf_load_valid.py --verbose --capture=no
poetry run pytest tests/gsfpy3_08/test_libgsf_load_invalid.py --verbose --capture=no
poetry run pytest tests/gsfpy3_08/test_libgsf_load_default.py --verbose --capture=no
poetry run pytest --ignore-glob=tests/gsfpy3_08/test_libgsf_load_*.py --ignore-glob=tests/gsfpy3_09/* --verbose --capture=no --cov=gsfpy3_08 --cov-fail-under=95 --cov-config=tox.ini
poetry run pytest --ignore-glob=tests/gsfpy3_08/test_libgsf_load_*.py --ignore-glob=tests/gsfpy3_09/* --verbose --capture=no --cov=gsfpy3_08
poetry run pytest tests/gsfpy3_09/test_libgsf_load_valid.py --verbose --capture=no
poetry run pytest tests/gsfpy3_09/test_libgsf_load_invalid.py --verbose --capture=no
poetry run pytest tests/gsfpy3_09/test_libgsf_load_default.py --verbose --capture=no
poetry run pytest --ignore-glob=tests/gsfpy3_09/test_libgsf_load_*.py --ignore-glob=tests/gsfpy3_08/* --verbose --capture=no --cov=gsfpy3_09 --cov-fail-under=95 --cov-config=tox.ini
poetry run pytest --ignore-glob=tests/gsfpy3_09/test_libgsf_load_*.py --ignore-glob=tests/gsfpy3_08/* --verbose --capture=no --cov=gsfpy3_09

test-all: .venv ## run tests on every Python version with tox
poetry run tox
## run all static checks and tests
test-all: .venv lint test

coverage: ## check code coverage quickly with the default Python
poetry run coverage run --source gsfpy -m pytest
Expand All @@ -106,6 +110,8 @@ requirements.txt: poetry.lock
poetry install
@touch -c .venv

poetry.lock: pyproject.toml
poetry update
poetry.lock:
poetry lock -vvv
@touch -c poetry.lock

## end Makefile
4 changes: 0 additions & 4 deletions gsfpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
__author__ = """UK Hydrographic Office"""
__email__ = "[email protected]"
__version__ = "2.0.0"

import os


Expand Down
4 changes: 0 additions & 4 deletions gsfpy3_08/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
__author__ = """UK Hydrographic Office"""
__email__ = "[email protected]"
__version__ = "2.0.0"

from ctypes import byref, c_int
from os import fsencode
from pathlib import Path
Expand Down
4 changes: 0 additions & 4 deletions gsfpy3_09/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
__author__ = """UK Hydrographic Office"""
__email__ = "[email protected]"
__version__ = "2.0.0"

from ctypes import byref, c_int
from os import fsencode
from pathlib import Path
Expand Down
29 changes: 18 additions & 11 deletions liccheck.ini
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
# Authorized and unauthorized licenses in LOWER CASE
[Licenses]
authorized_licenses:
bsd
new bsd
bsd license
new bsd license
simplified bsd
3-clause bsd
apache
apache 2.0
apache license 2.0
apache software
apache software license
apache-software
Apache 2
asl
asl 2
apache-software
apache software
bsd
bsd license
bsd-3-clause
cc-by
gnu lgpl
lgpl
lgpl with exceptions or zpl
GNU Library or Lesser General Public License (LGPL)
historical permission notice and disclaimer (hpnd)
hpnd
isc license
isc license (iscl)
lgpl
lgpl with exceptions or zpl
lgplv3
mit
mit license
mozilla public license 2.0 (mpl 2.0)
mpl-2.0
python software foundation license
python software foundation
new bsd
new bsd license
psf
public domain <http://unlicense.org>
python software foundation
python software foundation license
simplified bsd
zpl 2.1

unauthorized_licenses:
Expand Down
Loading

0 comments on commit 7f4ee2b

Please sign in to comment.