Commit eb83192f authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add plugin and boilerplate project files

parents
Loading
Loading
Loading
Loading
Loading

.editorconfig

0 → 100644
+11 −0
Original line number Diff line number Diff line
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab

[*.{yml,yaml,cfg}]
indent_style = space
indent_size = 2

.flakerules.toml

0 → 100644
+131 −0
Original line number Diff line number Diff line
[tool.flakeheaven.plugins]
mccabe = [
	"+C",
]
pycodestyle = [
	# Warnings not considered, many are not relevant to Python ~=3.9 and will
	# cause syntax errors anyway, others concern whitespace which is fixed by
	# a pre-commit hook.
	"+E*",

	# DISABLE "Missing whitespace around bitwise or shift operator"
	"-E227",

	# DISABLE "Line too long"
	# Prefer B950 implementation
	"-E501",

	# DISABLE "Multiple statements on one line (def)"
	# Doesn't work well with @overload definitions
	"-E704",
]
pyflakes = [
	# Most pyflakes tests are either discovered by mypy, or fixed automatically
	# by "isort" and "unimport"; the following are the remaining useful checks
	"-*",

	# ENABLE "Undefined name %s in __all__"
	"+F822",

	# ENABLE "Local variable %s ... referenced before assignment"
	"+F823",

	# ENABLE "Local variable %s is assigned to but never used"
	"+F841",

	# ENABLE "raise NotImplemented should be raise NotImplementedError"
	# mypy has particular trouble with this one:
	# https://github.com/python/mypy/issues/5710
	"+F901",
]
flake8-docstrings = [
	## Missing Docstrings
	"+D1*",

	# DISABLE "Missing docstring in magic method"
	# Magic/dunder methods are well-known
	"-D105",

	# DISABLE "Missing docstring in __init__"
	# Document basic construction in the class docstring
	"-D107",

	# Whitespace Issues
	"+D2*",

	# DISABLE "One-line docstring should fit on one line with quotes"
	# Prefer top-and-bottom style always
	"-D200",

	# DISABLE "1 blank line required before class docstring"
	"-D203",

	# DISABLE "Docstring should be indented with spaces, not tabs"
	# Tabs, absolutely always
	"-D206",

	# DISABLE "Multi-line docstring summary should start at the first line"
	"-D212",

	# ENABLE "Use “””triple double quotes”””"
	"+D300",

	# First line should be descriptive, imperative and capitalised
	"+D401", "+D402", "+D403", "+D404",

	# ENABLE "Function/Method decorated with @overload shouldn’t contain a docstring"
	"+D418",
]
flake8-sfs = [
	# ENABLE "String literal formatting using percent operator."
	# ENABLE "Bytes literal formatting using percent operator."
	"+SFS1*",
]
flake8-bugbear = [
	# The bulk of bugbear's checks are useful
	"+B0*",

	# DISABLE "Do not use mutable data structures for argument defaults [...]"
	# Would be nice if could take into account use as a non-mutable type
	"-B006",

	# Use named-tuples (preferably class based) for data-only classes
	"+B903",

	# Replacement for E501
	"+B950",
]
flake8-print = [
	"+T*",
]
flake8-return = [
	"+R*",
]

[tool.flakeheaven.exceptions."**/__init__.py"]
docstrings = [
	# DISABLE "Missing docstring in public package"
	# Sometimes we want package docstrings, other times not.
	# TODO(dom.sekotill): Verify this
	"-D104",
]

[tool.flakeheaven.exceptions."**/__main__.py"]
docstrings = [
	# DISABLE "Missing docstring in public module"
	# I don't consider __main__ to be a public module, it serves the same
	# function in packages as `if __name__ == "__main__":` in modules.
	"-D100",
]
pycodestyle = [
	# DISABLE "Multiple statements on one line (semicolon)"
	# __main__ modules SHOULD simply import an entrypoint and call it.
	# One-lining it can look a little more elegant than three (including
	# a blank line between imports and code!)
	"-E702",
]

[tool.flakeheaven.exceptions."**/_*.py"]
flake8-docstrings = [
	"-D1*",
]

.gitignore

0 → 100644
+5 −0
Original line number Diff line number Diff line
# Python object cache
*.py[co]

# Test results
/results/
+58 −0
Original line number Diff line number Diff line
# Find a suitable commit for determining changed files
#
#
# Copyright 2022 Dom Sekotill <dom.sekotill@kodo.org.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


pre_commit_run() (
	set -eu
	declare -a PRE_COMMIT_ARGS

	find_lca() {
		local repo=$CI_REPOSITORY_URL current_branch=$CI_COMMIT_BRANCH
		local other_branch=$1

		# See https://stackoverflow.com/questions/63878612/git-fatal-error-in-object-unshallow-sha-1
		# and https://stackoverflow.com/questions/4698759/converting-git-repository-to-shallow/53245223#53245223
		# for background on what `git repack -d` is doing here.
		git repack -qd

		git fetch -q $repo --shallow-exclude=$other_branch $current_branch
		git fetch -q $repo --deepen=1 $current_branch

		FROM_REF=$(git rev-parse -q --revs-only --verify shallow) || unset FROM_REF
	}

	fetch_ref() {
		git fetch -q $CI_REPOSITORY_URL --depth=1 $1
		FROM_REF=$1
	}

	if [[ -v CI_COMMIT_BEFORE_SHA ]] && [[ ! $CI_COMMIT_BEFORE_SHA =~ ^0{40}$ ]]; then
		fetch_ref $CI_COMMIT_BEFORE_SHA
	elif [[ -v CI_MERGE_REQUEST_TARGET_BRANCH_NAME ]]; then
		find_lca $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
	elif [[ $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH ]]; then
		find_lca $CI_DEFAULT_BRANCH
	fi

	if [[ -v FROM_REF ]]; then
		PRE_COMMIT_ARGS=( --from-ref=$FROM_REF --to-ref=$CI_COMMIT_SHA )
	else
		PRE_COMMIT_ARGS=( --all-files )
	fi

	pre-commit run "$@" "${PRE_COMMIT_ARGS[@]}"
)

.gitlab-ci.yml

0 → 100644
+56 −0
Original line number Diff line number Diff line
# Optional project CI variables to set:
#
# SAFETY_API_KEY:
#   Set to your API key for accessing up-to-date package security information

stages:
- prepare
- test

.python:
  image: python:3.9
  variables:
    PIP_CACHE_DIR: $CI_PROJECT_DIR/cache/pkg
    PIP_NO_COMPILE: "true"
    PIP_NO_CLEAN: "true"
  cache:
    key: $CI_JOB_IMAGE
    paths: [cache]
  before_script:
  - pip install "pip>=21.3"


Pin:
  # Pin dependencies in requirements.txt for reproducing pipeline results
  stage: prepare
  extends: [.python]
  script:
  - pip install --prefer-binary -e .
  - pip freeze --exclude-editable | tee requirements.txt
  artifacts:
    paths: [requirements.txt]


Dependency Check:
  stage: test
  image: pyupio/safety:latest
  needs: [Pin]
  allow_failure: true
  script:
  - safety check -r requirements.txt


Quality Gate:
  stage: prepare
  image: docker.kodo.org.uk/ci-images/pre-commit:latest
  variables:
    PRE_COMMIT_HOME: $CI_PROJECT_DIR/cache/pre-commit
  cache:
    key: $CI_JOB_IMAGE
    paths: [cache]
  rules:
  - if: $CI_PIPELINE_SOURCE == "push"
  script:
  - source .gitlab-ci.pre-commit-run.bash
  - pre_commit_run --hook-stage=commit
  - pre_commit_run --hook-stage=push