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

Lint howitz with ruff #125

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/howitz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from logging.config import dictConfig
from flask_caching import Cache

from flask import Flask, g, redirect, url_for, current_app
from flask import Flask, redirect, url_for, current_app
from flask.logging import default_handler
from flask_assets import Bundle, Environment
from flask_login import LoginManager, logout_user
Expand Down
2 changes: 0 additions & 2 deletions src/howitz/config/howitz.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import Path

from zinolib.config.toml import parse_toml_config
from .models import HowitzConfig, DevHowitzConfig

Expand Down
2 changes: 1 addition & 1 deletion src/howitz/config/zino1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def get_config_dict(config_dict, section="default"):
zino_dict = config_dict.get('zino', {})
if not zino_dict or not 'connections' in zino_dict:
if not zino_dict or 'connections' not in zino_dict:
return {}
if zino_dict["connections"][section]:
connection = zino_dict["connections"][section]
Expand Down
10 changes: 4 additions & 6 deletions src/howitz/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import os
from enum import Enum

from flask import (
Blueprint,
current_app,
flash,
g,
make_response,
redirect,
render_template,
Expand Down Expand Up @@ -571,13 +569,13 @@ def update_event_status(event_id):

try:
if not current_state == new_state:
set_state_res = current_app.event_manager.change_admin_state_for_id(event_id, AdmState(new_state))
current_app.event_manager.change_admin_state_for_id(event_id, AdmState(new_state))
except EventClosedError as closedErr:
current_app.logger.exception('EventClosedError %s', closedErr)
raise BadRequest(description=closedErr.args[0]) from closedErr

if new_history:
add_history_res = current_app.event_manager.add_history_entry_for_id(event_id, new_history)
current_app.event_manager.add_history_entry_for_id(event_id, new_history)

event_attr, event_logs, event_history, event_msgs = get_event_details(event_id)
event = create_table_event(current_app.event_manager.create_event_from_id(event_id))["event"]
Expand Down Expand Up @@ -607,13 +605,13 @@ def bulk_update_events_status():
for event_id in selected_events:
try:
if new_state:
set_state_res = current_app.event_manager.change_admin_state_for_id(int(event_id), AdmState(new_state))
current_app.event_manager.change_admin_state_for_id(int(event_id), AdmState(new_state))
except EventClosedError as closedErr:
current_app.logger.exception('EventClosedError %s', closedErr)
raise BadRequest(description=closedErr.args[0]) from closedErr

if new_history:
add_history_res = current_app.event_manager.add_history_entry_for_id(int(event_id), new_history)
current_app.event_manager.add_history_entry_for_id(int(event_id), new_history)

# Clear selected events
session["selected_events"] = {}
Expand Down
6 changes: 3 additions & 3 deletions src/howitz/error_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def handle_generic_http_exception(e):
alert_random_id = str(uuid.uuid4())
short_err_msg = f"{e.code} {e.name}: {e.description}"

if not "errors" in session:
if "errors" not in session:
session["errors"] = dict()
session["errors"][str(alert_random_id)] = serialize_exception(e)
session.modified = True
Expand All @@ -39,7 +39,7 @@ def handle_generic_exception(e):
except IndexError:
short_err_msg = 'An unexpected error has occurred'

if not "errors" in session:
if "errors" not in session:
session["errors"] = dict()
session["errors"][str(alert_random_id)] = serialize_exception(e)
session.modified = True
Expand Down Expand Up @@ -97,7 +97,7 @@ def handle_lost_connection(e):
except IndexError:
short_err_msg = 'Temporarily lost connection to Zino server'

if not "errors" in session:
if "errors" not in session:
session["errors"] = dict()
session["errors"][str(alert_random_id)] = serialize_exception(e)
session.modified = True
Expand Down
4 changes: 2 additions & 2 deletions src/howitz/users/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_user(username, password, token):
def update_user(username, password, token):
with current_app.app_context():
if not (password or token):
click.echo(f'Neither token nor password given, aborting', err=True)
click.echo('Neither token nor password given, aborting', err=True)
sys.exit(1)
user = current_app.database.get(username)
if not user:
Expand Down Expand Up @@ -75,7 +75,7 @@ def list_users():
with current_app.app_context():
users = current_app.database.get_all()
if not users:
click.echo(f'No users found, aborting', err=True)
click.echo('No users found, aborting', err=True)
sys.exit(1)
for user in users:
click.echo(user.username)
Expand Down
5 changes: 2 additions & 3 deletions src/howitz/users/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ class User(UserMixin, BaseModel):
token: str

def __str__(self):
token = "'SET'" if self.token else "'NOT SET'"
password = "'SET'" if self.password.startswith(('scrypt:', 'pdkbdf2:')) else "'NOT SET'"
return f'username={self.username} password=XXX token=XXX'
token = "SET" if self.token else "NOT SET"
return f'username={self.username} *** token="{token}"'

def get_id(self):
return self.username
Expand Down
2 changes: 0 additions & 2 deletions src/howitz/users/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import hashlib

from werkzeug.exceptions import Forbidden
from werkzeug.security import generate_password_hash, check_password_hash

Expand Down
2 changes: 1 addition & 1 deletion tests/test_users_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UserTest(unittest.TestCase):

def test_print_user_return_username(self):
user = User(**{'username': 'foo', 'password': 'bar', 'token': 'xux'})
self.assertEqual(str(user), 'username=foo password=XXX token=XXX')
self.assertEqual(str(user), 'username=foo *** token="SET"')

def test_autenticater_with_correct_password_returns_true(self):
user = User(**{'username': 'foo', 'password': 'bar', 'token': 'xux'})
Expand Down