Skip to content

Commit

Permalink
Merge pull request #4988 from willkg/1567990-black
Browse files Browse the repository at this point in the history
bug 1567990: add scaffolding for running black and reformat python code
  • Loading branch information
willkg committed Jul 23, 2019
2 parents f550a19 + f2d989b commit 677212d
Show file tree
Hide file tree
Showing 269 changed files with 19,695 additions and 20,740 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ default:
@echo ""
@echo " shell - open a shell in the app container"
@echo " clean - remove all build, test, coverage and Python artifacts"
@echo " lint - check style with flake8"
@echo " lint - lint code"
@echo " lintfix - reformat code"
@echo " test - run unit tests"
@echo " testshell - open a shell for running tests"
@echo " docs - generate Sphinx HTML documentation, including API docs"
Expand Down Expand Up @@ -66,6 +67,10 @@ docs: my.env .docker-build-docs
lint: my.env
${DC} run --rm --no-deps app shell ./docker/run_lint.sh

.PHONY: lintfix
lintfix: my.env
${DC} run --rm --no-deps app shell ./docker/run_lint.sh --fix

my.env:
@if [ ! -f my.env ]; \
then \
Expand Down
60 changes: 24 additions & 36 deletions docker/config/gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from decouple import config as CONFIG


LOGGING_LEVEL = CONFIG('LOGGING_LEVEL', 'INFO')
LOCAL_DEV_ENV = CONFIG('LOCAL_DEV_ENV', False, cast=bool)
LOGGING_LEVEL = CONFIG("LOGGING_LEVEL", "INFO")
LOCAL_DEV_ENV = CONFIG("LOCAL_DEV_ENV", False, cast=bool)

HOST_ID = socket.gethostname()

Expand All @@ -23,33 +23,27 @@ def filter(self, record):


logconfig_dict = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'add_hostid': {
'()': AddHostID
"version": 1,
"disable_existing_loggers": False,
"filters": {"add_hostid": {"()": AddHostID}},
"handlers": {
"console": {
"level": LOGGING_LEVEL,
"class": "logging.StreamHandler",
"formatter": "socorroapp",
},
},
'handlers': {
'console': {
'level': LOGGING_LEVEL,
'class': 'logging.StreamHandler',
'formatter': 'socorroapp',
},
'mozlog': {
'level': LOGGING_LEVEL,
'class': 'logging.StreamHandler',
'formatter': 'mozlog',
'filters': ['add_hostid']
"mozlog": {
"level": LOGGING_LEVEL,
"class": "logging.StreamHandler",
"formatter": "mozlog",
"filters": ["add_hostid"],
},
},
'formatters': {
'socorroapp': {
'format': '%(asctime)s %(levelname)s - %(name)s - %(message)s',
},
'mozlog': {
'()': 'dockerflow.logging.JsonLogFormatter',
'logger_name': 'socorro'
"formatters": {
"socorroapp": {"format": "%(asctime)s %(levelname)s - %(name)s - %(message)s"},
"mozlog": {
"()": "dockerflow.logging.JsonLogFormatter",
"logger_name": "socorro",
},
},
}
Expand All @@ -58,17 +52,11 @@ def filter(self, record):
# In a local development environment, we don't want to see mozlog
# format at all, but we do want to see markus things and py.warnings.
# So set the logging up that way.
logconfig_dict['loggers'] = {
'gunicorn': {
'handlers': ['console'],
'level': LOGGING_LEVEL,
}
logconfig_dict["loggers"] = {
"gunicorn": {"handlers": ["console"], "level": LOGGING_LEVEL}
}
else:
# In a server environment, we want to use mozlog format.
logconfig_dict['loggers'] = {
'gunicorn': {
'handlers': ['mozlog'],
'level': LOGGING_LEVEL,
}
logconfig_dict["loggers"] = {
"gunicorn": {"handlers": ["mozlog"], "level": LOGGING_LEVEL}
}
29 changes: 21 additions & 8 deletions docker/run_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Runs linting.

# Usage: docker/run_lint.sh [--fix]
#
# Runs linting and code fixing.
#
# This should be called from inside a container.

set -e

echo ">>> flake8 ($(python --version))"
cd /app
flake8
BLACKARGS=("--line-length=88" "--target-version=py36" docker socorro webapp-django scripts)

if [[ $1 == "--fix" ]]; then
echo ">>> black fix"
black "${BLACKARGS[@]}"

else
echo ">>> flake8 ($(python --version))"
cd /app
flake8

echo ">>> black"
black --check "${BLACKARGS[@]}"

echo ">>> eslint (js)"
cd /app/webapp-django
/webapp-frontend-deps/node_modules/.bin/eslint .
echo ">>> eslint (js)"
cd /app/webapp-django
/webapp-frontend-deps/node_modules/.bin/eslint .
fi
10 changes: 10 additions & 0 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,13 @@ zipp==0.5.1 \
importlib-metadata==0.17 \
--hash=sha256:a9f185022cfa69e9ca5f7eabfd5a58b689894cb78a11e3c8c89398a8ccbb8e7f \
--hash=sha256:df1403cd3aebeb2b1dcd3515ca062eecb5bd3ea7611f18cba81130c68707e879
toml==0.10.0 \
--hash=sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c \
--hash=sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e \
--hash=sha256:f1db651f9657708513243e61e6cc67d101a39bad662eaa9b5546f789338e07a3
click==7.0 \
--hash=sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13 \
--hash=sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7
appdirs==1.4.3 \
--hash=sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92 \
--hash=sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e
3 changes: 3 additions & 0 deletions requirements/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,6 @@ google-cloud-pubsub==0.42.1 \
sentry-sdk==0.9.5 \
--hash=sha256:692aa93637273365166041ee8e06ccd6b61d5f06560765d78828edbaac83fae1 \
--hash=sha256:7c9db0e419fb0fb31c1b1d2ec9247667d2b77bd4f3136119ee6f1464e9b088a4
black==19.3b0 \
--hash=sha256:09a9dcb7c46ed496a9850b76e4e825d6049ecd38b611f1224857a79bd985a8cf \
--hash=sha256:68950ffd4d9169716bcb8719a56c07a2f4485354fec061cdd5910aa07369731c

0 comments on commit 677212d

Please sign in to comment.