Skip to content

Commit 4976e8a

Browse files
committed
CI fixes:
- PEP8 cleanup - do pytest and flake8 within Travis CI
1 parent 9b8bcf2 commit 4976e8a

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ python:
33
- "3.6"
44
cache: "pip"
55
script:
6-
- "python pyladies_cz.py freeze"
6+
- "python -m pip install -r test-requirements.txt && pytest tests/ &&
7+
flake8 --ignore=E266 --max-line-length=100 --exclude=original/ &&
8+
python pyladies_cz.py freeze"
79
env:
810
global:
911
- secure: "N+iAAkw+nVaPyI/yPUr3LeHRlLgbmjcn58768zKdeHqBYjJGB+wLe54yE4a6ed5evT5wabHV6fc2XfYbjkjmWNh7XLbEYqzU1HfelhZogo7VZEL2txkpjx8MM37XDFb2BxXieDuX/Gs0myCJj+eoVNWmD9ia6Y3lKgryJmtdR+qRDrxvLpHrDhJ3bpbd0nk14O6LKQI5SW7fMm9wLx62xb9F94H5hWx/TPRuKq/txuda7eATbiWvsDGfH6TDmJD89DKmMiLdJkVms1BA9wi5fAetf8orsAD+CUdm0QZm368MexIxeRbIUDUkqsFgyQk3UOUny7sc4HyXxO6WBaAE7qsxFeiSTzBvAY0ZH+OfTG8QW26tZy7aGBwcbDWvsFUoZ7egX5GLJ83g14xd2tY63S0iNbKuQUAhz3FEUoCrLCzOeY3kP2q6X12BCYqJkcPw4ylUnQYnHKloeacw52ae1KCwm/JE3wq0/9yQ2NwlEY5QYAAi895Say/BIxMkIdJp8qXa0bIRmKLJlgArtoCEXOdwlMckP2aYS0YLF8dsOQpdvTp0+32dcfeaL8W3Cg9SAgic9yOq0GWH0L6kMkYLQRDj6iZU9mgpuMFkEebuV06BwO0795HB0QrqC2mW+EgpvY0kuSjsDGmloozSx0h4wWGHKQ6i+Ai6tgXxGSvO3Jw="

pyladies_cz.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@
44
"""
55

66
import sys
7-
if sys.version_info < (3, 0):
8-
raise RuntimeError('You need Python 3.')
9-
107
import os
118
import fnmatch
129
import time
1310
import datetime
1411
import collections
15-
from urllib.parse import urlencode
16-
17-
from flask import Flask, render_template, url_for, send_from_directory
18-
from flask_frozen import Freezer
1912
import yaml
2013
import jinja2
2114
import markdown
2215
import random
2316

24-
from elsa import cli
2517
from functools import lru_cache
18+
from urllib.parse import urlencode
19+
from flask import Flask, render_template, url_for, send_from_directory, abort
20+
from flask_frozen import Freezer
21+
22+
from elsa import cli
23+
24+
if sys.version_info < (3, 0):
25+
raise RuntimeError('You need Python 3.')
26+
2627

2728
app = Flask('pyladies_cz')
2829
app.config['TEMPLATES_AUTO_RELOAD'] = True
@@ -32,6 +33,7 @@
3233
v1_path = os.path.join(orig_path, 'v1/')
3334
MISSING = object()
3435

36+
3537
def redirect(url):
3638
"""Return a response with a Meta redirect"""
3739

@@ -67,7 +69,7 @@ def city(city_slug):
6769
current_meetups = [m for m in meetups if m['current']]
6870
past_meetups = [m for m in meetups if not m['current']]
6971
registration_meetups = [
70-
m for m in current_meetups if m.get('registration_status')=='running']
72+
m for m in current_meetups if m.get('registration_status') == 'running']
7173
return render_template(
7274
'city.html',
7375
city_slug=city_slug,
@@ -80,44 +82,54 @@ def city(city_slug):
8082
team=read_yaml(os.path.join('cities', city_slug, 'team.yml'), default=()),
8183
)
8284

85+
8386
@app.route('/<city>_course/')
8487
def course_redirect(city):
8588
return redirect(url_for('city', city_slug=city, _anchor='meetups'))
8689

90+
8791
@app.route('/<city>_info/')
8892
def info_redirect(city):
8993
return redirect(url_for('city', city_slug=city, _anchor='city-info'))
9094

95+
9196
@app.route('/praha-cznic/')
9297
def praha_cznic():
9398
return redirect('https://naucse.python.cz/2018/pyladies-praha-jaro-cznic/')
9499

100+
95101
@app.route('/praha-ntk/')
96102
def praha_ntk():
97103
return redirect('https://naucse.python.cz/2018/pyladies-praha-jaro-ntk/')
98104

105+
99106
@app.route('/stan_se/')
100107
def stan_se():
101108
return render_template('stan_se.html')
102109

110+
103111
@app.route('/faq/')
104112
def faq():
105113
return render_template('faq.html')
106114

115+
107116
@app.route('/v1/<path:path>')
108117
def v1(path):
109118
if path in REDIRECTS:
110119
return redirect(REDIRECTS[path])
111120
return send_from_directory(v1_path, path)
112121

122+
113123
@app.route('/index.html')
114124
def index_html():
115125
return redirect(url_for('index'))
116126

127+
117128
@app.route('/course.html')
118129
def course_html():
119130
return send_from_directory(orig_path, 'course.html')
120131

132+
121133
@app.route('/googlecc704f0f191eda8f.html')
122134
def google_verification():
123135
# Verification page for GMail on our domain
@@ -135,7 +147,8 @@ def inject_cities():
135147
meetups_nonpermanent = [m for m in meetups if m.get('start')]
136148
cities[city_name] = {
137149
**city_info,
138-
'active_registration': any(m.get('registration_status') == 'running' for m in meetups_nonpermanent),
150+
'active_registration': any(m.get('registration_status') == 'running'
151+
for m in meetups_nonpermanent),
139152
}
140153
return dict(cities=cities)
141154

@@ -145,13 +158,15 @@ def inject_cities():
145158

146159
md = markdown.Markdown(extensions=['meta', 'markdown.extensions.toc'])
147160

161+
148162
@app.template_filter('markdown')
149163
def convert_markdown(text, inline=False):
150164
result = jinja2.Markup(md.convert(text))
151165
if inline and result[:3] == '<p>' and result[-4:] == '</p>':
152166
result = result[3:-4]
153167
return result
154168

169+
155170
@app.template_filter('date_range')
156171
def date_range(dates, sep='–'):
157172
start, end = dates
@@ -225,6 +240,7 @@ def read_yaml(filename, default=MISSING):
225240
data = yaml.safe_load(file)
226241
return data
227242

243+
228244
def read_lessons_yaml(filename):
229245
data = read_yaml(filename)
230246

@@ -269,8 +285,8 @@ def read_meetups_yaml(filename):
269285

270286
# Derive a URL for places that don't have one from the location
271287
if 'place' in meetup:
272-
if ('url' not in meetup['place']
273-
and {'latitude', 'longitude'} <= meetup['place'].keys()):
288+
if ('url' not in meetup['place'] and {'latitude',
289+
'longitude'} <= meetup['place'].keys()):
274290
place = meetup['place']
275291
place['url'] = 'http://mapy.cz/zakladni?' + urlencode({
276292
'y': place['latitude'],
@@ -294,6 +310,7 @@ def read_meetups_yaml(filename):
294310

295311
return list(reversed(data))
296312

313+
297314
def read_news_yaml(filename):
298315
data = read_yaml(filename)
299316
today = datetime.date.today()
@@ -305,6 +322,7 @@ def read_news_yaml(filename):
305322

306323
return news
307324

325+
308326
def pathto(name, static=False):
309327
if static:
310328
prefix = '_static/'
@@ -342,8 +360,9 @@ def inject_context():
342360

343361
freezer = Freezer(app)
344362

363+
345364
@freezer.register_generator
346-
def v1():
365+
def v1(): # noqa
347366
IGNORE = ['*.aux', '*.out', '*.log', '*.scss', '.travis.yml', '.gitignore']
348367
for name, dirs, files in os.walk(v1_path):
349368
if '.git' in dirs:
@@ -357,17 +376,21 @@ def v1():
357376
for path in REDIRECTS:
358377
yield url_for('v1', path=path)
359378

379+
360380
OLD_CITIES = 'praha', 'brno', 'ostrava'
361381

382+
362383
@freezer.register_generator
363-
def course_redirect():
384+
def course_redirect(): # noqa
364385
for city in OLD_CITIES:
365386
yield {'city': city}
366387

388+
367389
@freezer.register_generator
368-
def info_redirect():
390+
def info_redirect(): # noqa
369391
for city in OLD_CITIES:
370392
yield {'city': city}
371393

394+
372395
if __name__ == '__main__':
373396
cli(app, freezer=freezer, base_url='http://pyladies.cz')

0 commit comments

Comments
 (0)