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

Replace black and flake8 with ruff #1943

Merged
merged 1 commit into from
Nov 21, 2023
Merged
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
17 changes: 9 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ repos:
hooks:
- id: check-yaml
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.3.0
hooks:
- id: djlint-jinja
files: '.*\.html'
entry: djlint --reformat
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.5
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format

1 change: 0 additions & 1 deletion app/account_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def process(self) -> LinkResult:

class ExistingUnlinkedUserStrategy(ClientMergeStrategy):
def process(self) -> LinkResult:

partner_user = ensure_partner_user_exists_for_user(
self.link_request, self.user, self.partner
)
Expand Down
1 change: 0 additions & 1 deletion app/alias_suffix.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def verify_prefix_suffix(
# when DISABLE_ALIAS_SUFFIX is true, alias_domain_prefix is empty
and not config.DISABLE_ALIAS_SUFFIX
):

if not alias_domain_prefix.startswith("."):
LOG.e("User %s submits a wrong alias suffix %s", user, alias_suffix)
return False
Expand Down
19 changes: 19 additions & 0 deletions app/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,22 @@
sudo,
user,
)

__all__ = [
"alias_options",
"new_custom_alias",
"custom_domain",
"new_random_alias",
"user_info",
"auth",
"auth_mfa",
"alias",
"apple",
"mailbox",
"notification",
"setting",
"export",
"phone",
"sudo",
"user",
]
2 changes: 1 addition & 1 deletion app/api/views/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create_mailbox():
mailbox_email = sanitize_email(request.get_json().get("email"))

if not user.is_premium():
return jsonify(error=f"Only premium plan can add additional mailbox"), 400
return jsonify(error="Only premium plan can add additional mailbox"), 400

if not is_valid_email(mailbox_email):
return jsonify(error=f"{mailbox_email} invalid"), 400
Expand Down
4 changes: 2 additions & 2 deletions app/api/views/new_custom_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def new_custom_alias_v3():
if not data:
return jsonify(error="request body cannot be empty"), 400

if type(data) is not dict:
if not isinstance(data, dict):
return jsonify(error="request body does not follow the required format"), 400

alias_prefix = data.get("alias_prefix", "").strip().lower().replace(" ", "")
Expand All @@ -168,7 +168,7 @@ def new_custom_alias_v3():
return jsonify(error="alias prefix invalid format or too long"), 400

# check if mailbox is not tempered with
if type(mailbox_ids) is not list:
if not isinstance(mailbox_ids, list):
return jsonify(error="mailbox_ids must be an array of id"), 400
mailboxes = []
for mailbox_id in mailbox_ids:
Expand Down
20 changes: 20 additions & 0 deletions app/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,23 @@
recovery,
api_to_cookie,
)

__all__ = [
"login",
"logout",
"register",
"activate",
"resend_activation",
"reset_password",
"forgot_password",
"github",
"google",
"facebook",
"proton",
"change_email",
"mfa",
"fido",
"social",
"recovery",
"api_to_cookie",
]
4 changes: 2 additions & 2 deletions app/auth/views/fido.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def fido():
browser = MfaBrowser.get_by(token=request.cookies.get("mfa"))
if browser and not browser.is_expired() and browser.user_id == user.id:
login_user(user)
flash(f"Welcome back!", "success")
flash("Welcome back!", "success")
# Redirect user to correct page
return redirect(next_url or url_for("dashboard.index"))
else:
Expand Down Expand Up @@ -110,7 +110,7 @@ def fido():

session["sudo_time"] = int(time())
login_user(user)
flash(f"Welcome back!", "success")
flash("Welcome back!", "success")

# Redirect user to correct page
response = make_response(redirect(next_url or url_for("dashboard.index")))
Expand Down
4 changes: 2 additions & 2 deletions app/auth/views/mfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def mfa():
browser = MfaBrowser.get_by(token=request.cookies.get("mfa"))
if browser and not browser.is_expired() and browser.user_id == user.id:
login_user(user)
flash(f"Welcome back!", "success")
flash("Welcome back!", "success")
# Redirect user to correct page
return redirect(next_url or url_for("dashboard.index"))
else:
Expand All @@ -73,7 +73,7 @@ def mfa():
Session.commit()

login_user(user)
flash(f"Welcome back!", "success")
flash("Welcome back!", "success")

# Redirect user to correct page
response = make_response(redirect(next_url or url_for("dashboard.index")))
Expand Down
2 changes: 1 addition & 1 deletion app/auth/views/recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def recovery_route():
del session[MFA_USER_ID]

login_user(user)
flash(f"Welcome back!", "success")
flash("Welcome back!", "success")

recovery_code.used = True
recovery_code.used_at = arrow.now()
Expand Down
4 changes: 1 addition & 3 deletions app/auth/views/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def register():
try:
send_activation_email(user, next_url)
RegisterEvent(RegisterEvent.ActionType.success).send()
DailyMetric.get_or_create_today_metric().nb_new_web_non_proton_user += (
1
)
DailyMetric.get_or_create_today_metric().nb_new_web_non_proton_user += 1
Session.commit()
except Exception:
flash("Invalid email, are you sure the email is correct?", "error")
Expand Down
36 changes: 36 additions & 0 deletions app/dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,39 @@
notification,
support,
)

__all__ = [
"index",
"pricing",
"setting",
"custom_alias",
"subdomain",
"billing",
"alias_log",
"alias_export",
"unsubscribe",
"api_key",
"custom_domain",
"alias_contact_manager",
"enter_sudo",
"mfa_setup",
"mfa_cancel",
"fido_setup",
"coupon",
"fido_manage",
"domain_detail",
"lifetime_licence",
"directory",
"mailbox",
"mailbox_detail",
"refused_email",
"referral",
"contact_detail",
"setup_done",
"batch_import",
"alias_transfer",
"app",
"delete_account",
"notification",
"support",
]
2 changes: 1 addition & 1 deletion app/dashboard/views/alias_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ def get_alias_log(alias: Alias, page_id=0) -> [AliasLog]:
contact=contact,
)
logs.append(al)
logs = sorted(logs, key=lambda l: l.when, reverse=True)
logs = sorted(logs, key=lambda log: log.when, reverse=True)

return logs
11 changes: 5 additions & 6 deletions app/dashboard/views/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from app.db import Session

"""
List of apps that user has used via the "Sign in with SimpleLogin"
"""

from flask import render_template, request, flash, redirect
from flask_login import login_required, current_user
from sqlalchemy.orm import joinedload

from app.dashboard.base import dashboard_bp
from app.db import Session
from app.models import (
ClientUser,
)
Expand All @@ -17,6 +12,10 @@
@dashboard_bp.route("/app", methods=["GET", "POST"])
@login_required
def app_route():
"""
List of apps that user has used via the "Sign in with SimpleLogin"
"""

client_users = (
ClientUser.filter_by(user_id=current_user.id)
.options(joinedload(ClientUser.client))
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/views/coupon.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def coupon_route():
commit=True,
)
flash(
f"Your account has been upgraded to Premium, thanks for your support!",
"Your account has been upgraded to Premium, thanks for your support!",
"success",
)

Expand Down
6 changes: 3 additions & 3 deletions app/dashboard/views/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def directory():
if request.method == "POST":
if request.form.get("form-name") == "delete":
if not delete_dir_form.validate():
flash(f"Invalid request", "warning")
flash("Invalid request", "warning")
return redirect(url_for("dashboard.directory"))
dir_obj = Directory.get(delete_dir_form.directory_id.data)

Expand All @@ -87,7 +87,7 @@ def directory():

if request.form.get("form-name") == "toggle-directory":
if not toggle_dir_form.validate():
flash(f"Invalid request", "warning")
flash("Invalid request", "warning")
return redirect(url_for("dashboard.directory"))
dir_id = toggle_dir_form.directory_id.data
dir_obj = Directory.get(dir_id)
Expand All @@ -109,7 +109,7 @@ def directory():

elif request.form.get("form-name") == "update":
if not update_dir_form.validate():
flash(f"Invalid request", "warning")
flash("Invalid request", "warning")
return redirect(url_for("dashboard.directory"))
dir_id = update_dir_form.directory_id.data
dir_obj = Directory.get(dir_id)
Expand Down
1 change: 0 additions & 1 deletion app/dashboard/views/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ def setting():
new_email_valid = True
new_email = canonicalize_email(change_email_form.email.data)
if new_email != current_user.email and not pending_email:

# check if this email is not already used
if personal_email_already_used(new_email) or Alias.get_by(
email=new_email
Expand Down
7 changes: 3 additions & 4 deletions app/dashboard/views/unsubscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ def block_contact(contact_id):
@dashboard_bp.route("/unsubscribe/encoded/<encoded_request>", methods=["GET"])
@login_required
def encoded_unsubscribe(encoded_request: str):

unsub_data = UnsubscribeHandler().handle_unsubscribe_from_request(
current_user, encoded_request
)
if not unsub_data:
flash(f"Invalid unsubscribe request", "error")
flash("Invalid unsubscribe request", "error")
return redirect(url_for("dashboard.index"))
if unsub_data.action == UnsubscribeAction.DisableAlias:
alias = Alias.get(unsub_data.data)
Expand All @@ -97,14 +96,14 @@ def encoded_unsubscribe(encoded_request: str):
)
)
if unsub_data.action == UnsubscribeAction.UnsubscribeNewsletter:
flash(f"You've unsubscribed from the newsletter", "success")
flash("You've unsubscribed from the newsletter", "success")
return redirect(
url_for(
"dashboard.index",
)
)
if unsub_data.action == UnsubscribeAction.OriginalUnsubscribeMailto:
flash(f"The original unsubscribe request has been forwarded", "success")
flash("The original unsubscribe request has been forwarded", "success")
return redirect(
url_for(
"dashboard.index",
Expand Down
2 changes: 2 additions & 0 deletions app/developer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .views import index, new_client, client_detail

__all__ = ["index", "new_client", "client_detail"]
2 changes: 1 addition & 1 deletion app/developer/views/client_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def client_detail(client_id):
)

flash(
f"Thanks for submitting, we are informed and will come back to you asap!",
"Thanks for submitting, we are informed and will come back to you asap!",
"success",
)

Expand Down
2 changes: 2 additions & 0 deletions app/discover/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .views import index

__all__ = ["index"]
Loading
Loading