Skip to content

Commit 8cb9a1a

Browse files
committed
Apply black styles
1 parent 3d7c917 commit 8cb9a1a

File tree

12 files changed

+88
-83
lines changed

12 files changed

+88
-83
lines changed

go_capture/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .tasks import app as celery_app
22

3-
__all__ = ('celery_app',)
3+
__all__ = ("celery_app",)

go_capture/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
from django.core.asgi import get_asgi_application
1313

14-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'go_capture.settings')
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "go_capture.settings")
1515

1616
application = get_asgi_application()

go_capture/settings.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,62 +23,62 @@
2323
# Quick-start development settings - unsuitable for production
2424
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
2525

26-
SECRET_KEY = env.str('DJANGO_SECRET_KEY')
26+
SECRET_KEY = env.str("DJANGO_SECRET_KEY")
2727

2828
# SECURITY WARNING: don't run with debug turned on in production!
29-
DEBUG = env.bool('DJANGO_DEBUG', False)
29+
DEBUG = env.bool("DJANGO_DEBUG", False)
3030

31-
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS')
31+
ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS")
3232

3333

3434
# Application definition
3535

3636
INSTALLED_APPS = [
37-
'django.contrib.admin',
38-
'django.contrib.auth',
39-
'django.contrib.contenttypes',
40-
'django.contrib.sessions',
41-
'django.contrib.messages',
42-
'django.contrib.staticfiles',
37+
"django.contrib.admin",
38+
"django.contrib.auth",
39+
"django.contrib.contenttypes",
40+
"django.contrib.sessions",
41+
"django.contrib.messages",
42+
"django.contrib.staticfiles",
4343
]
4444

4545
MIDDLEWARE = [
46-
'django.middleware.security.SecurityMiddleware',
47-
'django.contrib.sessions.middleware.SessionMiddleware',
48-
'django.middleware.common.CommonMiddleware',
49-
'django.contrib.auth.middleware.AuthenticationMiddleware',
50-
'django.contrib.messages.middleware.MessageMiddleware',
51-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
46+
"django.middleware.security.SecurityMiddleware",
47+
"django.contrib.sessions.middleware.SessionMiddleware",
48+
"django.middleware.common.CommonMiddleware",
49+
"django.contrib.auth.middleware.AuthenticationMiddleware",
50+
"django.contrib.messages.middleware.MessageMiddleware",
51+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5252
]
5353

54-
ROOT_URLCONF = 'go_capture.urls'
54+
ROOT_URLCONF = "go_capture.urls"
5555

5656
TEMPLATES = [
5757
{
58-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
59-
'DIRS': [],
60-
'APP_DIRS': True,
61-
'OPTIONS': {
62-
'context_processors': [
63-
'django.template.context_processors.debug',
64-
'django.template.context_processors.request',
65-
'django.contrib.auth.context_processors.auth',
66-
'django.contrib.messages.context_processors.messages',
58+
"BACKEND": "django.template.backends.django.DjangoTemplates",
59+
"DIRS": [],
60+
"APP_DIRS": True,
61+
"OPTIONS": {
62+
"context_processors": [
63+
"django.template.context_processors.debug",
64+
"django.template.context_processors.request",
65+
"django.contrib.auth.context_processors.auth",
66+
"django.contrib.messages.context_processors.messages",
6767
],
6868
},
6969
},
7070
]
7171

72-
WSGI_APPLICATION = 'go_capture.wsgi.application'
72+
WSGI_APPLICATION = "go_capture.wsgi.application"
7373

7474

7575
# Database
7676
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
7777

7878
DATABASES = {
79-
'default': {
80-
'ENGINE': 'django.db.backends.sqlite3',
81-
'NAME': BASE_DIR / 'db.sqlite3',
79+
"default": {
80+
"ENGINE": "django.db.backends.sqlite3",
81+
"NAME": BASE_DIR / "db.sqlite3",
8282
}
8383
}
8484

@@ -88,26 +88,26 @@
8888

8989
AUTH_PASSWORD_VALIDATORS = [
9090
{
91-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
9292
},
9393
{
94-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
9595
},
9696
{
97-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
9898
},
9999
{
100-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
101101
},
102102
]
103103

104104

105105
# Internationalization
106106
# https://docs.djangoproject.com/en/4.1/topics/i18n/
107107

108-
LANGUAGE_CODE = 'en-us'
108+
LANGUAGE_CODE = "en-us"
109109

110-
TIME_ZONE = 'UTC'
110+
TIME_ZONE = "UTC"
111111

112112
USE_I18N = True
113113

@@ -117,21 +117,21 @@
117117
# Static files (CSS, JavaScript, Images)
118118
# https://docs.djangoproject.com/en/4.1/howto/static-files/
119119

120-
STATIC_URL = 'static/'
120+
STATIC_URL = "static/"
121121

122122
# Default primary key field type
123123
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
124124

125-
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
125+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
126126

127-
MEDIA_URL = 'media/'
128-
MEDIA_ROOT = BASE_DIR / 'media'
127+
MEDIA_URL = "media/"
128+
MEDIA_ROOT = BASE_DIR / "media"
129129
MEDIA_ROOT.mkdir(exist_ok=True)
130130

131-
IMAGES_DIR = MEDIA_ROOT / 'images'
131+
IMAGES_DIR = MEDIA_ROOT / "images"
132132
IMAGES_DIR.mkdir(exist_ok=True)
133133

134-
SGF_DIR = MEDIA_ROOT / 'sgf'
134+
SGF_DIR = MEDIA_ROOT / "sgf"
135135
SGF_DIR.mkdir(exist_ok=True)
136136

137-
FIREBASE_CREDENTIALS_FILE = BASE_DIR / env.str('FIREBASE_CREDENTIALS_FILE')
137+
FIREBASE_CREDENTIALS_FILE = BASE_DIR / env.str("FIREBASE_CREDENTIALS_FILE")

go_capture/sgf/find_stones.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def draw_patches(image, coords, color):
5656

5757
def get_clusters(board):
5858
pixels = np.float32(board.reshape(-1, 3))
59-
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
59+
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, 0.1)
6060
flags = cv2.KMEANS_RANDOM_CENTERS
6161
_, labels, palette = cv2.kmeans(pixels, 6, None, criteria, 10, flags)
6262
width, height, _ = board.shape

go_capture/sgf/make_sgf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ def write_stones(file, stones):
44

55

66
def make_sgf(file, black, white):
7-
file.write('(;FF[4]\n')
8-
file.write('GM[1]\n')
9-
file.write(';AB')
7+
file.write("(;FF[4]\n")
8+
file.write("GM[1]\n")
9+
file.write(";AB")
1010
write_stones(file, black)
11-
file.write('\n;AW')
11+
file.write("\n;AW")
1212
write_stones(file, white)
13-
file.write('\n)\n')
13+
file.write("\n)\n")

go_capture/sgf/perspective.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def perspective_transform(image, corners):
2424

2525
# Construct new points to obtain top-down view of image in
2626
# top_r, top_l, bottom_l, bottom_r order
27-
dimensions = np.array([[0, 0], [width - 1, 0], [width - 1, height - 1], [0, height - 1]], dtype="float32")
27+
dimensions = np.array(
28+
[[0, 0], [width - 1, 0], [width - 1, height - 1], [0, height - 1]],
29+
dtype="float32",
30+
)
2831

2932
# Convert to Numpy format
3033
ordered_corners = np.array((top_l, top_r, bottom_r, bottom_l), dtype="float32")
@@ -40,7 +43,9 @@ def get_corners(image):
4043
copy = image.copy()
4144
gray = cv2.cvtColor(copy, cv2.COLOR_BGR2GRAY)
4245
blur = cv2.medianBlur(gray, 3)
43-
thresh = cv2.adaptiveThreshold(blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 3)
46+
thresh = cv2.adaptiveThreshold(
47+
blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 3
48+
)
4449
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
4550
sorted_contours = sorted(contours, key=cv2.contourArea, reverse=True)
4651
return sorted_contours[0]

go_capture/tasks.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
from go_capture.sgf.process_image import process_image
1010

1111
# Set the default Django settings module for the 'celery' program.
12-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'go_capture.settings')
12+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "go_capture.settings")
1313

14-
app = Celery('go_capture')
14+
app = Celery("go_capture")
1515

1616
# Using a string here means the worker doesn't have to serialize
1717
# the configuration object to child processes.
1818
# - namespace='CELERY' means all celery-related configuration keys
1919
# should have a `CELERY_` prefix.
20-
app.config_from_object('django.conf:settings', namespace='CELERY')
20+
app.config_from_object("django.conf:settings", namespace="CELERY")
2121

2222
# Load task modules from all registered Django apps.
2323
app.autodiscover_tasks()
@@ -28,14 +28,14 @@
2828

2929
@app.task(bind=True)
3030
def debug_task(self):
31-
print(f'Request: {self.request!r}')
31+
print(f"Request: {self.request!r}")
3232

3333

3434
@app.task
3535
def process_image_task(image_filename, fcm_token):
36-
print(f'token: {fcm_token}')
37-
print(f'Processing {image_filename}')
38-
with open(image_filename, 'rb') as image_file:
36+
print(f"token: {fcm_token}")
37+
print(f"Processing {image_filename}")
38+
with open(image_filename, "rb") as image_file:
3939
sgf_buffer = io.StringIO()
4040
process_image(image_file, sgf_buffer)
4141

@@ -44,7 +44,7 @@ def process_image_task(image_filename, fcm_token):
4444
print(sgf_data)
4545
message = messaging.Message(
4646
data={
47-
'sgf': sgf_data,
47+
"sgf": sgf_data,
4848
},
4949
token=fcm_token,
5050
)
@@ -53,4 +53,4 @@ def process_image_task(image_filename, fcm_token):
5353
# registration token.
5454
response = messaging.send(message)
5555
# Response is a message ID string.
56-
print('Successfully sent message:', response)
56+
print("Successfully sent message:", response)

go_capture/tests.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88

99

1010
def get_images(image_folder):
11-
image_path = Path('../images/whole_board')
12-
for image_filename in image_path.glob('*.jpg'):
11+
image_path = Path("../images/whole_board")
12+
for image_filename in image_path.glob("*.jpg"):
1313
yield image_filename
1414

1515

16-
@pytest.mark.parametrize('image_filename', list(get_images('../images/whole_board')), ids=lambda x: x.stem)
16+
@pytest.mark.parametrize(
17+
"image_filename", list(get_images("../images/whole_board")), ids=lambda x: x.stem
18+
)
1719
def test_whole_board(image_filename):
1820
image = cv2.imread(str(image_filename))
1921
board = perspective.get_grid(image)
2022
black, white = find_stones.find_stones(board)
2123
out_stream = io.StringIO()
2224
make_sgf.make_sgf(out_stream, black, white)
23-
expected_path = Path('../expected') / (image_filename.stem + '.sgf')
25+
expected_path = Path("../expected") / (image_filename.stem + ".sgf")
2426
with expected_path.open() as expected_file:
2527
expected = expected_file.readlines()
2628
out_stream.seek(0)
27-
assert out_stream.read() == ''.join(expected)
29+
assert out_stream.read() == "".join(expected)

go_capture/urls.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from go_capture import views
2020

2121
urlpatterns = [
22-
path('admin/', admin.site.urls),
23-
path('capture/', views.capture),
24-
path('capture_async/', views.capture_async),
25-
path('health_check/', views.health_check),
22+
path("admin/", admin.site.urls),
23+
path("capture/", views.capture),
24+
path("capture_async/", views.capture_async),
25+
path("health_check/", views.health_check),
2626
]

go_capture/views.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,35 @@
1111

1212
@require_POST
1313
def capture(request):
14-
image_file = request.FILES['image']
14+
image_file = request.FILES["image"]
1515
output_file = io.StringIO()
1616
process_image(image_file, output_file)
1717
output_file.seek(0)
1818
filename = Path(image_file.name).stem
1919
return FileResponse(
2020
output_file.read(),
2121
status=201,
22-
filename=f'${filename}.sgf',
22+
filename=f"${filename}.sgf",
2323
as_attachment=True,
24-
content_type='application/x-go-sgf'
24+
content_type="application/x-go-sgf",
2525
)
2626

2727

2828
@require_POST
2929
def capture_async(request):
30-
image_file = request.FILES['image']
31-
fcm_token = request.POST['fcm_registration_token']
32-
print(f'token: {fcm_token}')
30+
image_file = request.FILES["image"]
31+
fcm_token = request.POST["fcm_registration_token"]
32+
print(f"token: {fcm_token}")
3333
filename = Path(image_file.name)
3434
print(filename)
3535
output_path = settings.IMAGES_DIR / filename
36-
with output_path.open('wb') as output_file:
36+
with output_path.open("wb") as output_file:
3737
output_file.write(image_file.read())
3838
process_image_task.delay(str(output_path.absolute()), fcm_token)
3939
return HttpResponse(status=201)
4040

4141

4242
@require_GET
4343
def health_check(request):
44-
body = {
45-
'message': 'Healthy!'
46-
}
44+
body = {"message": "Healthy!"}
4745
return JsonResponse(body)

0 commit comments

Comments
 (0)