From 28f26c43232c44aff7c2c72d75335033461fd73c Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sun, 4 Feb 2024 16:21:33 -0500 Subject: [PATCH] Add isort linting, isort clean --- .github/workflows/lint.yml | 11 ++++++++++- .gitignore | 3 ++- freezing/web/__init__.py | 14 +++++++------- freezing/web/autolog.py | 3 ++- freezing/web/config.py | 8 +++----- freezing/web/data.py | 28 ++++++++++++--------------- freezing/web/utils/auth.py | 5 ++--- freezing/web/utils/genericboard.py | 8 +++----- freezing/web/utils/gviz_api.py | 3 ++- freezing/web/utils/hashboard.py | 4 +--- freezing/web/utils/insta.py | 3 ++- freezing/web/utils/tribes.py | 4 +--- freezing/web/views/alt_scoring.py | 6 ++---- freezing/web/views/api.py | 9 ++++----- freezing/web/views/chartdata.py | 17 +++++++--------- freezing/web/views/general.py | 17 ++++++++-------- freezing/web/views/leaderboard.py | 4 ++-- freezing/web/views/people.py | 14 +++++--------- freezing/web/views/photos.py | 7 +++---- freezing/web/views/pointless.py | 10 +++++----- freezing/web/views/tribes.py | 5 ++--- freezing/web/views/user.py | 3 +-- pyproject.toml | 2 ++ requirements-test.txt | 1 + resources/passenger/passenger_wsgi.py | 4 ++-- 25 files changed, 91 insertions(+), 102 deletions(-) create mode 100644 pyproject.toml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4def3b5..63939ef 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,16 +1,25 @@ --- -# Thanks https://black.readthedocs.io/en/stable/integrations/github_actions.html name: Lint on: [push, pull_request] jobs: + + # Thanks https://black.readthedocs.io/en/stable/integrations/github_actions.html black-lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: psf/black@24.1.1 + isort-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: isort/isort-action@v1 + with: + requirements-files: "requirements.txt requirements-test.txt" + flake8-lint: runs-on: ubuntu-latest name: Lint diff --git a/.gitignore b/.gitignore index 1b57aa3..b235894 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ *.cfg *.egg-info *.pyc -.* +.env* +.venv* /*.iml /build /data/cache/* diff --git a/freezing/web/__init__.py b/freezing/web/__init__.py index 8f8499c..b669e9d 100644 --- a/freezing/web/__init__.py +++ b/freezing/web/__init__.py @@ -1,6 +1,6 @@ -from flask import Flask, session, g - +from flask import Flask, g, session from freezing.model import init_model, meta + from .config import config # Thanks https://stackoverflow.com/a/17073583 @@ -11,16 +11,16 @@ # This needs to be after the app is created, unfortunately. from freezing.web.views import ( # noqa + alt_scoring, + api, + chartdata, general, leaderboard, - chartdata, people, - user, - pointless, photos, - api, - alt_scoring, + pointless, tribes, + user, ) # Register our blueprints diff --git a/freezing/web/autolog.py b/freezing/web/autolog.py index 126c8a8..4f3e415 100644 --- a/freezing/web/autolog.py +++ b/freezing/web/autolog.py @@ -1,6 +1,7 @@ from __future__ import absolute_import -import logging + import inspect +import logging class EagerFormattingAdapter(logging.LoggerAdapter): diff --git a/freezing/web/config.py b/freezing/web/config.py index d7e02e2..89d25f5 100644 --- a/freezing/web/config.py +++ b/freezing/web/config.py @@ -1,14 +1,12 @@ import logging import os -from typing import List from datetime import datetime, tzinfo - -from colorlog import ColoredFormatter -from envparse import env +from typing import List import arrow import pytz - +from colorlog import ColoredFormatter +from envparse import env envfile = os.environ.get("APP_SETTINGS", os.path.join(os.getcwd(), ".env")) diff --git a/freezing/web/data.py b/freezing/web/data.py index 7af8881..d15dfb8 100644 --- a/freezing/web/data.py +++ b/freezing/web/data.py @@ -3,39 +3,35 @@ """ from __future__ import division, unicode_literals -import re -import logging - -from instagram import InstagramAPIError, InstagramClientError - - -from sqlalchemy import and_ -from geoalchemy import WKTSpatialElement - -from requests.exceptions import HTTPError -from stravalib import Client -from stravalib import model as strava_model -from stravalib import unithelper +import logging +import re from freezing.model import meta, orm from freezing.model.orm import ( Athlete, Ride, - RideGeo, RideEffort, + RideGeo, RidePhoto, RideTrack, Team, ) +from geoalchemy import WKTSpatialElement +from instagram import InstagramAPIError, InstagramClientError +from requests.exceptions import HTTPError +from sqlalchemy import and_ +from stravalib import Client +from stravalib import model as strava_model +from stravalib import unithelper from freezing.web import config from freezing.web.autolog import log from freezing.web.exc import ( + DataEntryError, InvalidAuthorizationToken, - NoTeamsError, MultipleTeamsError, - DataEntryError, + NoTeamsError, ) from freezing.web.utils import insta, wktutils diff --git a/freezing/web/utils/auth.py b/freezing/web/utils/auth.py index 8b3b7d3..1c34559 100644 --- a/freezing/web/utils/auth.py +++ b/freezing/web/utils/auth.py @@ -3,11 +3,10 @@ """ import logging -from functools import wraps, update_wrapper from datetime import timedelta +from functools import update_wrapper, wraps -from flask import session, g -from flask import make_response, request, current_app +from flask import current_app, g, make_response, request, session from werkzeug.exceptions import Forbidden diff --git a/freezing/web/utils/genericboard.py b/freezing/web/utils/genericboard.py index 95b5021..91d83ef 100644 --- a/freezing/web/utils/genericboard.py +++ b/freezing/web/utils/genericboard.py @@ -1,14 +1,12 @@ import decimal import os from datetime import datetime -from typing import List, Dict, Any, Tuple +from typing import Any, Dict, List, Tuple import yaml - -from marshmallow import fields - from freezing.model import meta -from freezing.model.msg import BaseSchema, BaseMessage +from freezing.model.msg import BaseMessage, BaseSchema +from marshmallow import fields from freezing.web.config import config from freezing.web.exc import ObjectNotFound diff --git a/freezing/web/utils/gviz_api.py b/freezing/web/utils/gviz_api.py index 88318f4..6e48b9e 100755 --- a/freezing/web/utils/gviz_api.py +++ b/freezing/web/utils/gviz_api.py @@ -34,8 +34,9 @@ import html # Python version 3.2 or higher except ImportError: import cgi as html # Only used for .escape() -import numbers + import json +import numbers import six diff --git a/freezing/web/utils/hashboard.py b/freezing/web/utils/hashboard.py index 944732b..b05cbf8 100644 --- a/freezing/web/utils/hashboard.py +++ b/freezing/web/utils/hashboard.py @@ -2,11 +2,9 @@ from typing import List import yaml - +from freezing.model.msg import BaseMessage, BaseSchema from marshmallow import fields -from freezing.model.msg import BaseSchema, BaseMessage - from freezing.web.config import config from freezing.web.exc import ObjectNotFound diff --git a/freezing/web/utils/insta.py b/freezing/web/utils/insta.py index 7499370..04efcad 100644 --- a/freezing/web/utils/insta.py +++ b/freezing/web/utils/insta.py @@ -3,10 +3,11 @@ """ import os -import urllib import shutil +import urllib from instagram.client import InstagramAPI + from freezing.web import exc from freezing.web.config import config diff --git a/freezing/web/utils/tribes.py b/freezing/web/utils/tribes.py index ac5c69e..96c2ff8 100644 --- a/freezing/web/utils/tribes.py +++ b/freezing/web/utils/tribes.py @@ -2,11 +2,9 @@ from typing import List import yaml - +from freezing.model.msg import BaseMessage, BaseSchema from marshmallow import fields -from freezing.model.msg import BaseSchema, BaseMessage - from freezing.web.config import config from freezing.web.exc import ObjectNotFound diff --git a/freezing/web/views/alt_scoring.py b/freezing/web/views/alt_scoring.py index ca3bb72..d8def31 100644 --- a/freezing/web/views/alt_scoring.py +++ b/freezing/web/views/alt_scoring.py @@ -1,11 +1,10 @@ from collections import defaultdict from itertools import groupby - -from flask import render_template, Blueprint -from sqlalchemy import text from statistics import median +from flask import Blueprint, render_template from freezing.model import meta +from sqlalchemy import text from freezing.web import config from freezing.web.views.shared_sql import ( @@ -16,7 +15,6 @@ team_sleaze_query, ) - blueprint = Blueprint("alt_scoring", __name__) diff --git a/freezing/web/views/api.py b/freezing/web/views/api.py index 4b45295..251682c 100644 --- a/freezing/web/views/api.py +++ b/freezing/web/views/api.py @@ -1,14 +1,13 @@ +import json from datetime import timedelta from decimal import Decimal -import json import arrow -from flask import Blueprint, jsonify, request import pytz -from sqlalchemy import text - +from flask import Blueprint, jsonify, request from freezing.model import meta -from freezing.model.orm import RidePhoto, Ride, RideTrack, Athlete +from freezing.model.orm import Athlete, Ride, RidePhoto, RideTrack +from sqlalchemy import text from freezing.web import config from freezing.web.autolog import log diff --git a/freezing/web/views/chartdata.py b/freezing/web/views/chartdata.py index 8c8175d..d6942fc 100644 --- a/freezing/web/views/chartdata.py +++ b/freezing/web/views/chartdata.py @@ -4,33 +4,30 @@ @author: hans """ -import json import copy +import json from collections import defaultdict from datetime import datetime, timedelta -from flask import current_app, Blueprint, jsonify - -from sqlalchemy import text from dateutil import rrule - +from flask import Blueprint, current_app, jsonify from freezing.model import meta from freezing.model.orm import Team +from pytz import utc +from sqlalchemy import text from freezing.web import config from freezing.web.utils import gviz_api from freezing.web.utils.dates import parse_competition_timestamp from freezing.web.views.shared_sql import ( - team_leaderboard_query, - indiv_sleaze_query, - team_sleaze_query, indiv_freeze_query, indiv_segment_query, + indiv_sleaze_query, + team_leaderboard_query, team_segment_query, + team_sleaze_query, ) -from pytz import utc - blueprint = Blueprint("chartdata", __name__) diff --git a/freezing/web/views/general.py b/freezing/web/views/general.py index f876d12..41b95fc 100644 --- a/freezing/web/views/general.py +++ b/freezing/web/views/general.py @@ -5,24 +5,23 @@ """ from flask import ( - render_template, + Blueprint, + jsonify, redirect, - url_for, + render_template, request, - Blueprint, session, - jsonify, + url_for, ) +from freezing.model import meta +from freezing.model.orm import Ride, RidePhoto from sqlalchemy import text from stravalib import Client -from freezing.model import meta -from freezing.model.orm import RidePhoto, Ride - -from freezing.web import app, data, config -from freezing.web.utils import auth +from freezing.web import app, config, data from freezing.web.autolog import log from freezing.web.exc import MultipleTeamsError, NoTeamsError +from freezing.web.utils import auth blueprint = Blueprint("general", __name__) diff --git a/freezing/web/views/leaderboard.py b/freezing/web/views/leaderboard.py index 5a5787d..dd671f9 100644 --- a/freezing/web/views/leaderboard.py +++ b/freezing/web/views/leaderboard.py @@ -1,8 +1,8 @@ -from flask import url_for, render_template, Blueprint +from flask import Blueprint, render_template, url_for +from freezing.model import meta from sqlalchemy import text from werkzeug.utils import redirect -from freezing.model import meta from freezing.web import config from freezing.web.views.shared_sql import team_leaderboard_query diff --git a/freezing/web/views/people.py b/freezing/web/views/people.py index 9e05488..bd4f7db 100644 --- a/freezing/web/views/people.py +++ b/freezing/web/views/people.py @@ -1,17 +1,13 @@ -from datetime import timedelta -from datetime import datetime - -from flask import render_template, Blueprint, abort -from sqlalchemy import text +from datetime import datetime, timedelta +from flask import Blueprint, abort, render_template from freezing.model import meta -from freezing.model.orm import Team, Athlete +from freezing.model.orm import Athlete, Team +from pytz import timezone, utc +from sqlalchemy import text from freezing.web import config -from pytz import utc, timezone - - blueprint = Blueprint("people", __name__) diff --git a/freezing/web/views/photos.py b/freezing/web/views/photos.py index 7651d47..165903d 100644 --- a/freezing/web/views/photos.py +++ b/freezing/web/views/photos.py @@ -1,13 +1,12 @@ import math -from flask import render_template, Blueprint, send_file, request - +from flask import Blueprint, render_template, request, send_file from freezing.model import meta -from freezing.model.orm import RidePhoto, Ride +from freezing.model.orm import Ride, RidePhoto from freezing.web import config -from freezing.web.utils import insta from freezing.web.autolog import log +from freezing.web.utils import insta blueprint = Blueprint("photos", __name__) diff --git a/freezing/web/views/pointless.py b/freezing/web/views/pointless.py index a93437e..8535c56 100644 --- a/freezing/web/views/pointless.py +++ b/freezing/web/views/pointless.py @@ -1,15 +1,15 @@ import operator -from datetime import datetime, timezone -from collections import defaultdict import re +from collections import defaultdict +from datetime import datetime, timezone -from flask import render_template, Blueprint, abort +from flask import Blueprint, abort, render_template +from freezing.model import meta from sqlalchemy import text -from freezing.model import meta from freezing.web.config import config from freezing.web.exc import ObjectNotFound -from freezing.web.utils.genericboard import load_board_and_data, load_board, format_rows +from freezing.web.utils.genericboard import format_rows, load_board, load_board_and_data from freezing.web.utils.hashboard import load_hashtag blueprint = Blueprint("pointless", __name__) diff --git a/freezing/web/views/tribes.py b/freezing/web/views/tribes.py index 030551f..8b68bbe 100644 --- a/freezing/web/views/tribes.py +++ b/freezing/web/views/tribes.py @@ -1,10 +1,9 @@ -from flask import render_template, Blueprint, session, redirect, request - from collections import defaultdict -from sqlalchemy import text +from flask import Blueprint, redirect, render_template, request, session from freezing.model import meta from freezing.model.orm import Tribe +from sqlalchemy import text from freezing.web.utils.auth import requires_auth from freezing.web.utils.tribes import load_tribes diff --git a/freezing/web/views/user.py b/freezing/web/views/user.py index a7074c6..9ed6964 100644 --- a/freezing/web/views/user.py +++ b/freezing/web/views/user.py @@ -2,8 +2,7 @@ import logging from datetime import datetime -from flask import render_template, current_app, request, Blueprint, session, jsonify - +from flask import Blueprint, current_app, jsonify, render_template, request, session from freezing.model import meta from freezing.model.orm import Ride diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5d7bf33 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.isort] +profile = "black" diff --git a/requirements-test.txt b/requirements-test.txt index 2df0352..4ca7a5d 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,5 +1,6 @@ black==24.1.1 flake8==7.0.0 +isort==5.13.2 pur==7.3.1 pytest==8.0.0 pytest-mock==3.12.0 diff --git a/resources/passenger/passenger_wsgi.py b/resources/passenger/passenger_wsgi.py index 03bbd5b..d49b5f3 100644 --- a/resources/passenger/passenger_wsgi.py +++ b/resources/passenger/passenger_wsgi.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 -import sys -import os import logging +import os +import sys """ This is a file designed to be used with Phusion Passenger.