Skip to content

Commit

Permalink
Added editorconfig, black, flake8, isort, pre-commit (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslay-excella authored Apr 18, 2022
1 parent 0747773 commit 59cfcf7
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 7 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# Matches multiple files with brace expansion notation
# Set default charset
# Set max line length
# 4 space indentation
[*.py]
charset = utf-8
max_line_length = 79
indent_style = space
indent_size = 4
23 changes: 23 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[flake8]
max-line-length = 79
select = C,E,F,W,B,B950
ignore =
# black https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
E203, E501
# There's nothing wrong with assigning lambdas
E731,
# PEP8 weakly recommends Knuth-style line breaks before binary
# operators
W503, W504
exclude =
# These are directories that it's a waste of time to traverse
.git,
.tox,
.venv,
docs,
venv,

# Generated migration files will throw errors. We need to find a way
# to exclude django-generated migrations while including
# manually-written migrations.
*/migrations/*.py,
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ Thumbs.db
mtg_ins_monthly_data*.csv
mtg_ins_upfront_data*.csv
site/

# IDEs
.idea/

# In-Directory Venvs
venv/
.venv/
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args: ["countylimits", "oahapi", "ratechecker", "setup.py", "--line-length=79"]
exclude: migrations
- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear==22.1.11]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
args: ["countylimits", "oahapi", "ratechecker"]
3 changes: 2 additions & 1 deletion countylimits/data_collection/gather_county_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import datetime
import os
from collections import OrderedDict
from csv import DictReader, writer as Writer
from csv import DictReader
from csv import writer as Writer

import requests

Expand Down
5 changes: 3 additions & 2 deletions countylimits/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from django.test import TestCase

import mock
from model_mommy import mommy
from rest_framework import status

from countylimits.data_collection.county_data_monitor import (
check_for_county_changes,
get_base_log,
Expand All @@ -27,8 +30,6 @@
)
from countylimits.management.commands import load_county_limits
from countylimits.models import County, CountyLimit, State
from model_mommy import mommy
from rest_framework import status


BASE_PATH = os.path.dirname(os.path.abspath(__file__)) + "/"
Expand Down
3 changes: 2 additions & 1 deletion countylimits/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from countylimits.models import CountyLimit
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response

from countylimits.models import CountyLimit


# A static allowlist of abbreviations and FIPS codes
SAFE_STATE_LIST = [
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,20 @@ exclude = '''
)
'''

[tool.isort]
profile = "black"
line_length = 79
lines_after_imports = 2
skip = [".tox", "migrations", ".venv", "venv"]
known_django = ["django"]
default_section = "THIRDPARTY"
sections = [
"STDLIB",
"DJANGO",
"THIRDPARTY",
"FIRSTPARTY",
"LOCALFOLDER"
]

[build-system]
requires = ["setuptools", "wheel"]
8 changes: 6 additions & 2 deletions ratechecker/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def get_sample_cover_sheet(day=None):
).format(day=day.strftime("%Y%m%d"))


def get_sample_dataset_zipfile(day=None, datasets={}):
def get_sample_dataset_zipfile(day=None, datasets=None):
if datasets is None:
datasets = {}
day = day or date.today()

f = BytesIO()
Expand Down Expand Up @@ -51,5 +53,7 @@ def write_sample_dataset(filename):
f.write(content)


def get_sample_dataset(day=None, datasets={}):
def get_sample_dataset(day=None, datasets=None):
if datasets is None:
datasets = {}
return Dataset(get_sample_dataset_zipfile(day=day, datasets=datasets))
4 changes: 3 additions & 1 deletion ratechecker/tests/test_views_rate_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,10 @@ def setUp(self):
)
adjustment.save()

def initialize_params(self, values={}):
def initialize_params(self, values=None):
"""a helper method to init params"""
if values is None:
values = {}
self.params = Object
self.params.state = values.get("state", "DC")
self.params.loan_purpose = values.get("loan_purpose", "PURCH")
Expand Down

0 comments on commit 59cfcf7

Please sign in to comment.