Skip to content

Commit

Permalink
Add pre-commit and setup from sktime
Browse files Browse the repository at this point in the history
  • Loading branch information
Tveten committed Dec 2, 2023
1 parent 69cc04b commit 9a574b8
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 18 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
name: tests
on: [push, pull_request]
jobs:
all-pytests:
code-quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- id: file_changes
uses: trilom/[email protected]
with:
output: " "
- name: List changed files
run: echo '${{ steps.file_changes.outputs.files}}'
- uses: pre-commit/[email protected]
with:
extra_args: --files ${{ steps.file_changes.outputs.files}}
- name: Check for missing init files
run: build_tools/fail_on_missing_init_files.sh
shell: bash

pytests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -14,12 +32,5 @@ jobs:
python -m pip install --upgrade pip
python -m pip install .[all_extras]
python -m pip install pytest
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
#flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
#flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
python -m pytest
80 changes: 80 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# copyright: sktime developers, BSD-3-Clause License (see LICENSE file)

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
args: ["--maxkb=1000"]
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude: "^docs/source/examples/"
- id: fix-encoding-pragma
args:
- --remove
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args:
- --py38-plus

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3
# args: [--line-length 79]

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
exclude: docs/conf.py
additional_dependencies: [flake8-bugbear, flake8-print]

- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
hooks:
- id: check-manifest
stages: [manual]

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
hooks:
- id: nbqa-black
args: [--nbqa-mutate, --nbqa-dont-skip-bad-cells]
additional_dependencies: [black==22.3.0]
- id: nbqa-isort
args: [--nbqa-mutate, --nbqa-dont-skip-bad-cells]
additional_dependencies: [isort==5.6.4]
- id: nbqa-flake8
args: [--nbqa-dont-skip-bad-cells, "--extend-ignore=E402,E203"]
additional_dependencies: [flake8==3.8.3]

- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
args: ["--config=setup.cfg"]

# We use the Python version instead of the original version which seems to require Docker
# https://github.com/koalaman/shellcheck-precommit
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.5
hooks:
- id: shellcheck
name: shellcheck
14 changes: 14 additions & 0 deletions build_tools/fail_on_missing_init_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# copyright: sktime developers, BSD-3-Clause License (see LICENSE file)

# Script to search for missing init FILES.
set -euxo pipefail

FILES=$( find ./skchange -type d '!' -exec test -e "{}/__init__.py" ";" -not -path "**/__pycache__" -not -path "**/datasets/data*" -not -path "**/contrib/*" -print )

if [[ -n "$FILES" ]]
then
echo "Missing __init__.py files detected in the following modules:"
echo "$FILES"
exit 1
fi
10 changes: 1 addition & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ all_extras = [
# dev - the developer dependency set, install via "pip install skchange[dev]"
dev = [
"black>=23.1.0",
"pre-commit",
"pytest>=7.2.1",
"ipykernel>=6.23.0",
"nbformat>=5.7.3",
Expand All @@ -73,14 +74,5 @@ requires = ["setuptools>61"]
[tool.setuptools.packages.find]
exclude = ["tests", "tests.*"]

[tool.isort]
profile = "black"
src_paths = ["skchange/*"]
multi_line_output = 3
known_first_party = ["skchange"]

[tool.black]
line-length = 88

[tool.pydocstyle]
convention = "numpy"
52 changes: 51 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
[aliases]
test = pytest

[tool.isort]
profile = "black"
multi_line_output = 3

[tool:pytest]
# ignore certain folders and pytest warnings
addopts =
--ignore build_tools
--ignore interactive
--ignore docs
# --doctest-modules
# --durations 20
# --timeout 600
# --cov sktime
# --cov-report xml
# --cov-report html
# --showlocals
# --matrixdesign True
# --only_changed_modules True
# -n auto
filterwarnings =
ignore::UserWarning
ignore:numpy.dtype size changed
ignore:numpy.ufunc size changed

[flake8]
# Default flake8 3.5 ignored flags
ignore = E121, E123, E126, E226, E24, E704, W503, W504
Expand All @@ -9,4 +37,26 @@ extend-ignore =

[metadata]
description_file = README.md
long_description_content_type = text/markdown
long_description_content_type = text/markdown

[check-manifest]
ignore =
# .binder/**
# .all-contributorsrc
# .coveragerc
# examples/**
build_tools/**
# __check_build/**
# docs/**
# Makefile
# CODEOWNERS
# CONTRIBUTING.md
# *.yaml
# *.yml

[isort]
profile = black

[pydocstyle]
convention = numpy
match = (?!test_).*\.py

0 comments on commit 9a574b8

Please sign in to comment.