Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken CI: add pre-commit checks for better CI #896

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: "2" # required to adjust maintainability checks
checks:
argument-count:
Expand Down Expand Up @@ -26,10 +27,10 @@ checks:
threshold: 4
similar-code:
config:
threshold: 50 # language-specific defaults. an override will affect all languages.
threshold: 50 # language-specific defaults. an override will affect all languages.
identical-code:
config:
threshold: # language-specific defaults. an override will affect all languages.
threshold: # language-specific defaults. an override will affect all languages.
plugins:
bandit:
enabled: true
Expand Down
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: 2
updates:
- package-ecosystem: "pip"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
name: Release

on:
push:
tags:
- '*'
- '*'

jobs:
build:
Expand Down
69 changes: 35 additions & 34 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Test

on: [push, pull_request]
Expand All @@ -14,10 +15,10 @@ jobs:
django-version: ['2.2', '3.1', '3.2', 'main']

exclude:
- python-version: '3.6'
django-version: 'main'
- python-version: '3.7'
django-version: 'main'
- python-version: '3.6'
django-version: 'main'
- python-version: '3.7'
django-version: 'main'

services:

Expand Down Expand Up @@ -51,39 +52,39 @@ jobs:
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

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

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"

- name: Cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key:
${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/tox.ini') }}
restore-keys: |
${{ matrix.python-version }}-v1-
- name: Cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key:
${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/tox.ini') }}
restore-keys: |
${{ matrix.python-version }}-v1-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements/tox.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements/tox.txt

- name: Tox tests
run: |
tox -v
env:
DJANGO: ${{ matrix.django-version }}
- name: Tox tests
run: |
tox -v
env:
DJANGO: ${{ matrix.django-version }}

- name: Upload coverage
uses: codecov/codecov-action@v1
with:
name: Python ${{ matrix.python-version }}
- name: Upload coverage
uses: codecov/codecov-action@v1
with:
name: Python ${{ matrix.python-version }}
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
repos:
- repo: https://github.com/PyCQA/bandit
rev: 1.7.0
hooks:
- id: bandit
args:
- "-x *test*.py"

- repo: https://github.com/ambv/black
rev: 21.9b0
hooks:
- id: black
language_version: python3.8

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
args:
- "--config=tox.ini"

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: requirements-txt-fixer
files: requirements/.*\.txt$
- id: trailing-whitespace
- id: check-added-large-files
- id: fix-byte-order-marker
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key

- repo: https://github.com/adrienverge/yamllint
rev: v1.26.3
hooks:
- id: yamllint
args:
- "--strict"
13 changes: 13 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# allow "on" until yamllint stops checking keys for truthy!
# https://github.com/adrienverge/yamllint/issues/158
---
extends: default

rules:
comments-indentation: disable
braces: disable
line-length:
max: 120
truthy:
level: error
allowed-values: ['true', 'false', 'on']
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Full list of changes:
- Support ``included_fields`` for ``history.diff_against`` (gh-776)
- Improve performance of ``history.diff_against`` by reducing number of queries to 0 in most cases (gh-776)
- Added Czech translations (gh-885)
- Added pre-commit for better commit quality (gh-896)

3.0.0 (2021-04-16)
------------------
Expand Down
8 changes: 6 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ We make use of `black`_ for code formatting.

.. _black: https://black.readthedocs.io/en/stable/installation_and_usage.html

Once it is installed you can make sure the code is properly formatted by running::
You can install and run it along with other linters through pre-commit:

make format
pre-commit install
pre-commit run

Once you install pre-commit it will sanity check any commit you make.
Additionally, the CI process runs this check as well.

Translations
------------
Expand Down
2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] I have run the `make format` command to format my code
- [ ] I have run the `pre-commit run` command to format and lint.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the **CONTRIBUTING** document.
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
coverage:
status:
patch:
Expand Down
7 changes: 3 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.

import os
import sys

Expand Down Expand Up @@ -176,11 +175,11 @@

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# 'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
Expand Down
6 changes: 3 additions & 3 deletions docs/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ from the duplicate check
clean_old_history
-----------------------

You may want to remove historical records that have existed for a certain amount of time.
You may want to remove historical records that have existed for a certain amount of time.

If you find yourself with a lot of old history you can schedule the
``clean_old_history`` command
Expand All @@ -43,9 +43,9 @@ If you find yourself with a lot of old history you can schedule the

$ python manage.py clean_old_history --auto

You can use ``--auto`` to remove old historial entries
You can use ``--auto`` to remove old historial entries
with ``HistoricalRecords`` or enumerate specific models as args.
You may also specify a ``--days`` parameter, which indicates how many
You may also specify a ``--days`` parameter, which indicates how many
days of records you want to keep. The default it 30 days, meaning that
all records older than 30 days would be removed.

Expand Down
2 changes: 1 addition & 1 deletion requirements/mysql.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mysqlclient==2.0.3
mysqlclient==2.0.3
2 changes: 1 addition & 1 deletion requirements/postgres.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
psycopg2-binary==2.9.1
psycopg2-binary==2.9.1
2 changes: 1 addition & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __getitem__(self, item):
}


DEFAULT_SETTINGS = dict(
DEFAULT_SETTINGS = dict( # nosec
SECRET_KEY="not a secret",
ALLOWED_HOSTS=["localhost"],
AUTH_USER_MODEL="custom_user.CustomUser",
Expand Down
Empty file modified simple_history/__init__.py
100755 → 100644
Empty file.
Empty file modified simple_history/manager.py
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
class Migration(migrations.Migration):

dependencies = [
('migration_test_app', '0005_historicalmodelwithcustomattronetoonefield_modelwithcustomattronetoonefield'),
(
"migration_test_app",
"0005_historicalmodelwithcustomattronetoonefield_modelwithcustomattronetoonefield",
),
]

operations = [
migrations.AlterModelOptions(
name='historicalmodelwithcustomattronetoonefield',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical model with custom attr one to one field'},
name="historicalmodelwithcustomattronetoonefield",
options={
"get_latest_by": ("history_date", "history_id"),
"ordering": ("-history_date", "-history_id"),
"verbose_name": "historical model with custom attr one to one field",
},
),
migrations.AlterField(
model_name='historicalmodelwithcustomattronetoonefield',
name='history_date',
model_name="historicalmodelwithcustomattronetoonefield",
name="history_date",
field=models.DateTimeField(db_index=True),
),
]
6 changes: 3 additions & 3 deletions simple_history/registry_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_history(model):

self.assertRaises(AttributeError, get_history, User)
self.assertEqual(len(User.histories.all()), 0)
user = User.objects.create(username="bob", password="pass")
user = User.objects.create(username="bob", password="pass") # nosec
self.assertEqual(len(User.histories.all()), 1)
self.assertEqual(len(user.histories.all()), 1)

Expand Down Expand Up @@ -80,11 +80,11 @@ def test_register_history_id_field(self):
class TestUserAccessor(unittest.TestCase):
def test_accessor_default(self):
register(UserAccessorDefault)
assert not hasattr(User, "historicaluseraccessordefault_set")
self.assertFalse(hasattr(User, "historicaluseraccessordefault_set"))

def test_accessor_override(self):
register(UserAccessorOverride, user_related_name="my_history_model_accessor")
assert hasattr(User, "my_history_model_accessor")
self.assertTrue(hasattr(User, "my_history_model_accessor"))


class TestInheritedModule(TestCase):
Expand Down
6 changes: 3 additions & 3 deletions simple_history/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,9 @@ class CustomManagerNameModel(models.Model):
log = HistoricalRecords()


"""
Following classes test the "custom_model_name" option
"""
#
# Following classes test the "custom_model_name" option
#


class OverrideModelNameAsString(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion simple_history/tests/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_simple_bulk_history_create(self):
self.assertEqual(Poll.history.count(), 4)

@override_settings(SIMPLE_HISTORY_ENABLED=False)
def test_simple_bulk_history_create(self):
def test_simple_bulk_history_create_without_history_enabled(self):
Poll.history.bulk_history_create(self.data)
self.assertEqual(Poll.history.count(), 0)

Expand Down
Loading