Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting workflow + cleanup #15

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

JensTimmerman
Copy link
Member

@JensTimmerman JensTimmerman commented Jan 10, 2022

auto linting tests are nice

they brought up some issues, so fixed those here as well

@JensTimmerman
Copy link
Member Author

JensTimmerman commented Jan 10, 2022

the linting output is

 ./import_quotes.py:3:1: F401 'flask.request' imported but unused
./import_quotes.py:3:1: F401 'flask.Response' imported but unused
./import_quotes.py:3:1: F401 'flask.abort' imported but unused
./import_quotes.py:3:1: F401 'flask.render_template' imported but unused
./import_quotes.py:5:1: F401 'flask_migrate.Migrate' imported but unused
./import_quotes.py:19:65: E251 unexpected spaces around keyword / parameter equals
./import_quotes.py:19:67: E251 unexpected spaces around keyword / parameter equals
./import_quotes.py:22:1: W391 blank line at end of file
./passenger_wsgi.py:12:1: F401 'app.app as application' imported but unused
./passenger_wsgi.py:12:1: E402 module level import not at top of file
./migrations/env.py:20:1: E402 module level import not at top of file
./migrations/env.py:77:1: W293 blank line contains whitespace
./migrations/env.py:87:1: E305 expected 2 blank lines after class or function definition, found 1
./migrations/versions/49d24a3cb696_.py:4:9: W291 trailing whitespace
./migrations/versions/49d24a3cb696_.py:22:5: E128 continuation line under-indented for visual indent
./migrations/versions/49d24a3cb696_.py:23:5: E122 continuation line missing indentation or outdented
./migrations/versions/49d24a3cb696_.py:24:5: E122 continuation line missing indentation or outdented
./migrations/versions/49d24a3cb696_.py:25:5: E122 continuation line missing indentation or outdented
./migrations/versions/49d24a3cb696_.py:26:5: E122 continuation line missing indentation or outdented
./migrations/versions/49d24a3cb696_.py:27:5: E122 continuation line missing indentation or outdented
./migrations/versions/49d24a3cb696_.py:28:5: E122 continuation line missing indentation or outdented
./migrations/versions/49d24a3cb696_.py:31:5: E128 continuation line under-indented for visual indent
./migrations/versions/49d24a3cb696_.py:32:5: E122 continuation line missing indentation or outdented
./migrations/versions/49d24a3cb696_.py:33:5: E122 continuation line missing indentation or outdented
./migrations/versions/49d24a3cb696_.py:34:5: E122 continuation line missing indentation or outdented
./migrations/versions/49d24a3cb696_.py:35:5: E122 continuation line missing indentation or outdented
./migrations/versions/49d24a3cb696_.py:36:5: E122 continuation line missing indentation or outdented
./migrations/versions/eb812588d982_add_keyvalue_store.py:22:5: E128 continuation line under-indented for visual indent
./migrations/versions/eb812588d982_add_keyvalue_store.py:23:5: E122 continuation line missing indentation or outdented
./migrations/versions/eb812588d982_add_keyvalue_store.py:24:5: E122 continuation line missing indentation or outdented
./migrations/versions/eb812588d982_add_keyvalue_store.py:25:5: E122 continuation line missing indentation or outdented
./migrations/versions/eb812588d982_add_keyvalue_store.py:26:5: E122 continuation line missing indentation or outdented
./app/app.py:43:1: E402 module level import not at top of file
./app/app.py:44:1: F401 'app.cron' imported but unused
./app/app.py:44:1: E402 module level import not at top of file
./app/app.py:52:5: E722 do not use bare 'except'
./app/app.py:116:1: E302 expected 2 blank lines, found 1
./app/app.py:128:128: E501 line too long (186 > 127 characters)
./app/app.py:131:128: E501 line too long (140 > 127 characters)
./app/app.py:135:128: E501 line too long (130 > 127 characters)
./app/app.py:181:1: E302 expected 2 blank lines, found 1
./app/app.py:196:1: E302 expected 2 blank lines, found 1
./app/app.py:231:1: E302 expected 2 blank lines, found 1
./app/app.py:232:1: C901 'doorkeeper' is too complex (11)
./app/app.py:240:55: E741 ambiguous variable name 'l'
./app/app.py:245:128: E501 line too long (133 > 127 characters)
./app/app.py:246:5: E722 do not use bare 'except'
./app/app.py:247:128: E501 line too long (145 > 127 characters)
./app/app.py:267:1: E302 expected 2 blank lines, found 1
./app/app.py:274:128: E501 line too long (128 > 127 characters)
./app/app.py:337:1: E305 expected 2 blank lines after class or function definition, found 1
./app/app.py:369:1: E302 expected 2 blank lines, found 1
./app/app.py:373:13: E127 continuation line over-indented for visual indent
./app/app.py:410:41: E231 missing whitespace after ','
./app/app.py:415:1: E302 expected 2 blank lines, found 1
./app/__init__.py:1:1: F401 'app.app.app' imported but unused
./app/cron.py:4:1: F401 'flask.current_app' imported but unused
./app/cron.py:6:1: F401 'atexit' imported but unused
./app/cron.py:34:1: E303 too many blank lines (3)
./app/cron.py:47:9: F841 local variable 'news_items' is assigned to but never used
./app/models.py:37:32: W605 invalid escape sequence '\W'
./app/models.py:37:43: W605 invalid escape sequence '\-'

it's not failing on this for now, it did fail on undefined names,
perhaps let it fail on a few of these errors as well? (ignoring the migrations folder?)

@JensTimmerman
Copy link
Member Author

made it fail

@JensTimmerman JensTimmerman changed the title Add linting workflow WIP Add linting workflow Jan 13, 2022
@JensTimmerman
Copy link
Member Author

JensTimmerman commented Jan 13, 2022

wip, should short circuit if reason is reason in doorkeeper

@JensTimmerman JensTimmerman changed the title WIP Add linting workflow Add linting workflow + cleanup Jan 13, 2022

def get_mattermost_id(username):
'''Given a mattermost username, return the user id. Don't call this with stale data'''
try:
response = mm_driver.users.get_user_by_username(username)
return response['id']
except:
# TODO: only KeyError?
except Exception:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's unclear to me what other exceptions are being caught here now, should be more specific, but at least the app will now do more clear things on interupts (keyboardinterupt etc are no longer caught)

@JensTimmerman
Copy link
Member Author

No longer wip, please review

Copy link
Member

@redfast00 redfast00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Het is niet mn beste review-werk, maar hier zijn mijn meningen/opmerkingen

@@ -125,14 +125,22 @@ def authorize(admin_user):
tokens = request.values.get('text').strip().split()
if not tokens:
# list authorized user
response = '\n'.join(f'{"**" if u.admin else ""}{u.username}{" ADMIN**" if u.admin else ""}' for u in models.User.query.filter_by(authorized=True).order_by(models.User.username))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik vond de originele code hier properder, maar ik zal wss in de minderheid zijn. De nieuwe code zet ook op de laatste lijn een newline, dat is niet nodig in principe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja, het is niet beter, ik herwerk

to_authorize_username = get_actual_username(tokens[0])
to_authorize_id = get_mattermost_id(to_authorize_username)
if to_authorize_id is None:
return mattermost_response("User '{}' does not seem to exist in Mattermost".format(to_authorize_username), ephemeral=True)
return mattermost_response(
"User '{}' does not seem to exist in Mattermost".format(to_authorize_username),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We hebben tegenwoordig f-strings in de Pythonversie van de server, dat is mss properder

@@ -8,5 +8,3 @@
os.execl(INTERP, INTERP, *sys.argv)

sys.path.append(os.getcwd())

from app import app as application
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc hebben we dit wel nodig door de manier waarop passenger werkt

@@ -1 +0,0 @@
from app.app import app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik denk dat we dit wel nodig hebben door de manier waarop either passenger of flask werkt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants