Skip to content

Commit 2dcf500

Browse files
author
Peter Bengtsson
authored
Black all the Python code (mozilla-services#1005)
* Black all the Python code Fixes #998 * ignore .cache/ * something for black to notice (test) * undo black breakage * documenting use of black
1 parent 79ea79f commit 2dcf500

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+4257
-5890
lines changed

.circleci/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ jobs:
5858
command: |
5959
make test
6060
61+
- run:
62+
name: Run lint check
63+
command: |
64+
docker-compose run test-ci lintcheck
65+
6166
- run:
6267
name: Linting check for frontend
6368
command: |

setup.cfg .flake8

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
[flake8]
2+
max-line-length = 88
23
exclude=
34
# ignore the migrations since they are created faulty by default
45
tecken/*/migrations/*,
56
# No use in checking the Node modules
6-
node_modules/*/*/*,
7+
frontend/node_modules/*/*/*,
78
# No need to traverse our git directory
89
.git,
910
# There's no value in checking cache directories
1011
__pycache__,
1112
# Sphinx docs is best left as is
1213
docs/conf.py,
1314
hack.*py,
15+
tecken/wsgi.py,

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ test-upload-inbox/
2727
upload-inbox/
2828
miniodata/
2929
.pytest_cache/
30+
.cache/

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ WORKDIR /app
1414
RUN bin/build_frontend.sh
1515

1616
FROM python:3.6-slim@sha256:5a96684a1729acd0680b39a3c24ef33f36bb6951873f77cde1e227b059a0f881
17-
MAINTAINER Peter Bengtsson <[email protected]>
1817

1918
ENV PYTHONUNBUFFERED=1 \
2019
PYTHONPATH=/app/ \
@@ -33,13 +32,13 @@ RUN mkdir /app && \
3332
# install a few essentials and clean apt caches afterwards
3433
RUN apt-get update && \
3534
apt-get install -y --no-install-recommends \
36-
apt-transport-https build-essential curl git libpq-dev \
37-
gettext libffi-dev jed
35+
apt-transport-https build-essential curl git libpq-dev \
36+
gettext libffi-dev jed
3837

3938
# Install dump_syms
4039
RUN DEBIAN_FRONTEND=noninteractive \
4140
apt-get install -y --no-install-recommends \
42-
gyp ninja-build binutils-gold gcc-6 g++-6 pkg-config cabextract
41+
gyp ninja-build binutils-gold gcc-6 g++-6 pkg-config cabextract
4342
COPY ./docker/build_dump_syms.sh /tmp
4443
RUN /tmp/build_dump_syms.sh
4544

@@ -50,6 +49,7 @@ RUN apt-get autoremove -y && \
5049

5150
# Install Python dependencies
5251
COPY requirements.txt /tmp/
52+
COPY requirements-constraints.txt /tmp/
5353
# Switch to /tmp to install dependencies outside home dir
5454
WORKDIR /tmp
5555
RUN pip install --no-cache-dir -r requirements.txt

Makefile

+14-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ help:
1717
@echo " systemtest Run system tests against a running tecken"
1818
@echo " django-shell Django integrative shell"
1919
@echo " psql Open the psql cli"
20-
@echo " lint-frontend Runs a linting check on the frontend"
21-
@echo " lint-frontend-ci Runs a linting check on the frontend in CI"
20+
@echo " lintcheck Check that the code is well formatted"
21+
@echo " lintfix Fix all the possible linting errors"
2222
@echo " build-frontend Builds the frontend static files\n"
2323

2424
# Dev configuration steps
@@ -81,11 +81,19 @@ systemtest: .env .docker-build
8181
tag:
8282
@bin/make-tag.py
8383

84-
lint-frontend:
85-
docker-compose run frontend lint
84+
#lint-frontend:
85+
# docker-compose run frontend lint
8686

87-
lint-frontend-ci:
88-
docker-compose run frontend-ci lint
87+
#lint-frontend-ci:
88+
# docker-compose run frontend-ci lint
8989

9090
build-frontend:
9191
docker-compose run -u 0 -e CI base ./bin/build_frontend.sh
92+
93+
lintcheck: .env .docker-build
94+
docker-compose run web lintcheck
95+
docker-compose run frontend lint
96+
97+
lintfix: .env .docker-build
98+
docker-compose run web blackfix
99+
docker-compose run frontend lintfix

README.md

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
Tecken - All things Mozilla Symbol Server
2-
=========================================
1+
# Tecken - All things Mozilla Symbol Server
32

43
[![CircleCI](https://circleci.com/gh/mozilla-services/tecken.svg?style=svg)](https://circleci.com/gh/mozilla-services/tecken)
54
[![Updates](https://pyup.io/repos/github/mozilla-services/tecken/shield.svg)](https://pyup.io/repos/github/mozilla-services/tecken/)
65
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovateapp.com/)
76
[![What's Deployed](https://img.shields.io/badge/whatsdeployed-dev,stage,prod-green.svg)](https://whatsdeployed.io/s-5HY)
8-
9-
7+
[![Code style](https://img.shields.io/badge/Code%20style-black-000000.svg)](https://github.com/ambv/black)
108

119
Please use the documentation on: **https://tecken.readthedocs.io**
1210

1311
The **production server** is: https://symbols.mozilla.org
1412

15-
16-
To Get Coding
17-
-------------
13+
## To Get Coding
1814

1915
You need to be able to run Docker.
2016

@@ -29,9 +25,7 @@ To test the symbolication run:
2925

3026
curl -d '{"stacks":[[[0,11723767],[1, 65802]]],"memoryMap":[["xul.pdb","44E4EC8C2F41492B9369D6B9A059577C2"],["wntdll.pdb","D74F79EB1F8D4A45ABCD2F476CCABACC2"]],"version":4}' http://localhost:8000
3127

32-
33-
Datadog
34-
-------
28+
## Datadog
3529

3630
If you have access to a Mozilla Cloud Ops Datadog account, use this to
3731
consume the metrics Tecken sends via `statsd`. One is for staying health, the other is for
@@ -47,25 +41,20 @@ keeping track how it does things.
4741

4842
[Symbols RDS](https://app.datadoghq.com/screen/280710/symbols-rds)
4943

50-
New Relic
51-
---------
44+
## New Relic
5245

53-
This requires you have access to the
46+
This requires you have access to the
5447
[Mozilla_25 New Relic account](https://rpm.newrelic.com/accounts/1402187/applications).
5548

5649
[symbols-prod](https://rpm.newrelic.com/accounts/1402187/applications/62681492)
5750

5851
[symbols-stage](https://rpm.newrelic.com/accounts/1402187/applications/52227224)
5952

60-
61-
Whatsdeployed
62-
-------------
53+
## Whatsdeployed
6354

6455
Check out https://whatsdeployed.io/s-5HY
6556

66-
67-
The Logo
68-
--------
57+
## The Logo
6958

7059
![logo](logo.png "The Logo")
7160

bin/run.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -eo pipefail
99
: "${GUNICORN_TIMEOUT:=300}"
1010

1111
usage() {
12-
echo "usage: ./bin/run.sh web|web-dev|worker|test|bash|superuser"
12+
echo "usage: ./bin/run.sh web|web-dev|worker|test|bash|blackfix|lintcheck|superuser"
1313
exit 1
1414
}
1515

@@ -55,13 +55,22 @@ case $1 in
5555
# the docker container.
5656
exec celery -A tecken.celery:app worker -l info --purge
5757
;;
58+
blackfix)
59+
# This exclude is ugly because it's not additive
60+
# See https://github.com/ambv/black/issues/65
61+
black tecken tests --exclude '/(\.git|\.hg|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist|migrations)/'
62+
;;
63+
lintcheck)
64+
flake8 tecken tests
65+
black --check tecken tests --exclude '/(\.git|\.hg|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist|migrations)/'
66+
;;
5867
superuser)
5968
exec python manage.py superuser "${@:2}"
6069
;;
6170
test)
6271
# python manage.py collectstatic --noinput
6372
coverage erase
64-
coverage run -m py.test --flake8 "${@:2}"
73+
coverage run -m py.test "${@:2}"
6574
coverage report -m
6675
if [[ -z ${CI+check} ]]; then # when doing local `make test`
6776
# generate code coverage to disk

docs/dev.rst

+24-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ It will exit non-zero if there are files lacking the preamble. It only
2121
checks git checked in files.
2222

2323
PEP8 is nice. All files are expected to be PEP8 and pyflakes compliant
24-
and the PEP8 rules (and exceptions) are defined in ``setup.cfg`` under
24+
and the PEP8 rules (and exceptions) are defined in ``.flake8`` under
2525
the ``[flake8]`` heading.
2626

27-
The tests use ``py.test`` with a plugin called ``flake8`` which will
28-
check files according to the flake8 rules as it runs tests.
29-
3027
If you hit issues, instead of re-writing the rules consider
3128
appending a comment on the end of the line that says ``# noqa``.
3229

30+
All Python code is and should be formatted with `black <https://github.com/ambv/black>`_.
31+
3332
Local development
3433
=================
3534

@@ -652,3 +651,24 @@ if there were multiple files:
652651
$ zip mysymbols -r *
653652
$ ls -l mysymbols.zip
654653
-rw-r--r-- 1 peterbe staff 40945250 Aug 10 14:54 mysymbols.zip
654+
655+
656+
``black``
657+
=========
658+
659+
`black <https://github.com/ambv/black>`_. is the Python code formatting tool we use
660+
to format all non-generated Python code. In CI, we test that all code passes
661+
``black --check ...``. When doing local development, consider setting up either
662+
some sort of "format on save" in your editor or a git pre-commit hook.
663+
664+
To check that all code is formatted correctly, run:
665+
666+
.. code-block:: shell
667+
668+
$ docker-compose run web lintcheck
669+
670+
If you have a bunch of formatting complaints you can automatically fix them all with:
671+
672+
.. code-block:: shell
673+
674+
$ docker-compose run web blackfix

requirements-constraints.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
click==6.7 \
2+
--hash=sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d \
3+
--hash=sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b
4+
toml==0.9.4 \
5+
--hash=sha256:8e86bd6ce8cc11b9620cb637466453d94f5d57ad86f17e98a98d1f73e3baab2d
6+
appdirs==1.4.3 \
7+
--hash=sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92 \
8+
--hash=sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e

requirements.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-c requirements-constraints.txt
2+
13
Django==2.0.7 \
24
--hash=sha256:97886b8a13bbc33bfeba2ff133035d3eca014e2309dff2b6da0bdfc0b8656613 \
35
--hash=sha256:e900b73beee8977c7b887d90c6c57d68af10066b9dac898e1eaf0f82313de334
@@ -357,9 +359,6 @@ pytest-mock==1.7.1 \
357359
requests-mock==1.4.0 \
358360
--hash=sha256:96a1e45b1c0bd18d14fcb2d55b3b09d6d46237e37bcae3155df4cb75bc42619e \
359361
--hash=sha256:2931887853c42e1d73879983d5bf03041109472991c5b4b8dba5d11ed23b9d0b
360-
pytest-flake8==0.9.1 \
361-
--hash=sha256:e67686645860009cf1f9a5016e110234b4a2c4584711d62ba753ed651ab9ab28 \
362-
--hash=sha256:e716072d07a557defdd5c4141984569731e292961370a5663c1697283aa16200
363362
mccabe==0.6.1 \
364363
--hash=sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42 \
365364
--hash=sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f
@@ -399,3 +398,6 @@ pycryptodome==3.5.1 \
399398
--hash=sha256:90c1c08431ccf8d6385b5071e5d3f7ecbf85dbd1cbd45439fe136bc514c73136 \
400399
--hash=sha256:008e0bfc02f8c409fbe31a1dd1ff3aa18b5c109b47a05603ca734506a7b3a8cb \
401400
--hash=sha256:b7957736f5e868416b06ff033f8525e64630c99a8880b531836605190b0cac96
401+
black==18.6b4 \
402+
--hash=sha256:22158b89c1a6b4eb333a1e65e791a3f8b998cf3b11ae094adb2570f31f769a44 \
403+
--hash=sha256:4b475bbd528acce094c503a3d2dbc2d05a4075f6d0ef7d9e7514518e14cc5191

tecken/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
44
from .celery import app as celery_app
55

6-
default_app_config = 'tecken.apps.TeckenAppConfig'
6+
default_app_config = "tecken.apps.TeckenAppConfig"
77

88

99
# This will make sure the app is always imported when
1010
# Django starts so that shared_task will use this app.
11-
__all__ = ['celery_app', 'default_app_config']
11+
__all__ = ["celery_app", "default_app_config"]

0 commit comments

Comments
 (0)