Skip to content

Commit

Permalink
CI fixes:
Browse files Browse the repository at this point in the history
- PEP8 cleanup
- do pytest and flake8 within Travis CI
  • Loading branch information
fivaldi committed Jun 4, 2020
1 parent 9b8bcf2 commit 25e9ad5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ python:
- "3.6"
cache: "pip"
script:
- "python pyladies_cz.py freeze"
- "python -m pip install -r test-requirements.txt && pytest tests/ &&
flake8 --ignore=E266,F811 --max-line-length=100 --exclude=original/ &&
python pyladies_cz.py freeze"
env:
global:
- secure: "N+iAAkw+nVaPyI/yPUr3LeHRlLgbmjcn58768zKdeHqBYjJGB+wLe54yE4a6ed5evT5wabHV6fc2XfYbjkjmWNh7XLbEYqzU1HfelhZogo7VZEL2txkpjx8MM37XDFb2BxXieDuX/Gs0myCJj+eoVNWmD9ia6Y3lKgryJmtdR+qRDrxvLpHrDhJ3bpbd0nk14O6LKQI5SW7fMm9wLx62xb9F94H5hWx/TPRuKq/txuda7eATbiWvsDGfH6TDmJD89DKmMiLdJkVms1BA9wi5fAetf8orsAD+CUdm0QZm368MexIxeRbIUDUkqsFgyQk3UOUny7sc4HyXxO6WBaAE7qsxFeiSTzBvAY0ZH+OfTG8QW26tZy7aGBwcbDWvsFUoZ7egX5GLJ83g14xd2tY63S0iNbKuQUAhz3FEUoCrLCzOeY3kP2q6X12BCYqJkcPw4ylUnQYnHKloeacw52ae1KCwm/JE3wq0/9yQ2NwlEY5QYAAi895Say/BIxMkIdJp8qXa0bIRmKLJlgArtoCEXOdwlMckP2aYS0YLF8dsOQpdvTp0+32dcfeaL8W3Cg9SAgic9yOq0GWH0L6kMkYLQRDj6iZU9mgpuMFkEebuV06BwO0795HB0QrqC2mW+EgpvY0kuSjsDGmloozSx0h4wWGHKQ6i+Ai6tgXxGSvO3Jw="
Expand Down
53 changes: 38 additions & 15 deletions pyladies_cz.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
"""

import sys
if sys.version_info < (3, 0):
raise RuntimeError('You need Python 3.')

import os
import fnmatch
import time
import datetime
import collections
from urllib.parse import urlencode

from flask import Flask, render_template, url_for, send_from_directory
from flask_frozen import Freezer
import yaml
import jinja2
import markdown
import random

from elsa import cli
from functools import lru_cache
from urllib.parse import urlencode
from flask import Flask, render_template, url_for, send_from_directory, abort
from flask_frozen import Freezer

from elsa import cli

if sys.version_info < (3, 0):
raise RuntimeError('You need Python 3.')


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


def redirect(url):
"""Return a response with a Meta redirect"""

Expand Down Expand Up @@ -67,7 +69,7 @@ def city(city_slug):
current_meetups = [m for m in meetups if m['current']]
past_meetups = [m for m in meetups if not m['current']]
registration_meetups = [
m for m in current_meetups if m.get('registration_status')=='running']
m for m in current_meetups if m.get('registration_status') == 'running']
return render_template(
'city.html',
city_slug=city_slug,
Expand All @@ -80,44 +82,54 @@ def city(city_slug):
team=read_yaml(os.path.join('cities', city_slug, 'team.yml'), default=()),
)


@app.route('/<city>_course/')
def course_redirect(city):
return redirect(url_for('city', city_slug=city, _anchor='meetups'))


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


@app.route('/praha-cznic/')
def praha_cznic():
return redirect('https://naucse.python.cz/2018/pyladies-praha-jaro-cznic/')


@app.route('/praha-ntk/')
def praha_ntk():
return redirect('https://naucse.python.cz/2018/pyladies-praha-jaro-ntk/')


@app.route('/stan_se/')
def stan_se():
return render_template('stan_se.html')


@app.route('/faq/')
def faq():
return render_template('faq.html')


@app.route('/v1/<path:path>')
def v1(path):
if path in REDIRECTS:
return redirect(REDIRECTS[path])
return send_from_directory(v1_path, path)


@app.route('/index.html')
def index_html():
return redirect(url_for('index'))


@app.route('/course.html')
def course_html():
return send_from_directory(orig_path, 'course.html')


@app.route('/googlecc704f0f191eda8f.html')
def google_verification():
# Verification page for GMail on our domain
Expand All @@ -135,7 +147,8 @@ def inject_cities():
meetups_nonpermanent = [m for m in meetups if m.get('start')]
cities[city_name] = {
**city_info,
'active_registration': any(m.get('registration_status') == 'running' for m in meetups_nonpermanent),
'active_registration': any(m.get('registration_status') == 'running'
for m in meetups_nonpermanent),
}
return dict(cities=cities)

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

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


@app.template_filter('markdown')
def convert_markdown(text, inline=False):
result = jinja2.Markup(md.convert(text))
if inline and result[:3] == '<p>' and result[-4:] == '</p>':
result = result[3:-4]
return result


@app.template_filter('date_range')
def date_range(dates, sep='–'):
start, end = dates
Expand Down Expand Up @@ -225,6 +240,7 @@ def read_yaml(filename, default=MISSING):
data = yaml.safe_load(file)
return data


def read_lessons_yaml(filename):
data = read_yaml(filename)

Expand Down Expand Up @@ -269,8 +285,8 @@ def read_meetups_yaml(filename):

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

return list(reversed(data))


def read_news_yaml(filename):
data = read_yaml(filename)
today = datetime.date.today()
Expand All @@ -305,6 +322,7 @@ def read_news_yaml(filename):

return news


def pathto(name, static=False):
if static:
prefix = '_static/'
Expand Down Expand Up @@ -342,8 +360,9 @@ def inject_context():

freezer = Freezer(app)


@freezer.register_generator
def v1():
def v1(): # noqa: F811
IGNORE = ['*.aux', '*.out', '*.log', '*.scss', '.travis.yml', '.gitignore']
for name, dirs, files in os.walk(v1_path):
if '.git' in dirs:
Expand All @@ -357,17 +376,21 @@ def v1():
for path in REDIRECTS:
yield url_for('v1', path=path)


OLD_CITIES = 'praha', 'brno', 'ostrava'


@freezer.register_generator
def course_redirect():
def course_redirect(): # noqa: F811
for city in OLD_CITIES:
yield {'city': city}


@freezer.register_generator
def info_redirect():
def info_redirect(): # noqa: F811
for city in OLD_CITIES:
yield {'city': city}


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

0 comments on commit 25e9ad5

Please sign in to comment.