Skip to content

Commit

Permalink
Add Pylint and djLint to workflow and increase typing coverage (hasge…
Browse files Browse the repository at this point in the history
  • Loading branch information
jace authored Jul 6, 2022
1 parent a7cd476 commit f34657c
Show file tree
Hide file tree
Showing 181 changed files with 1,633 additions and 1,134 deletions.
54 changes: 29 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ repos:
rev: 6.8.0
hooks:
- id: pip-compile
name: pip-compile --upgrade requirements.in
args: ['--upgrade', 'requirements.in']
name: pip-compile requirements.in
args: ['requirements.in']
files: ^requirements\.(in|txt)$
- id: pip-compile
name: pip-compile --upgrade requirements_dev.in
args: ['--upgrade', 'requirements_dev.in']
name: pip-compile requirements_dev.in
args: ['requirements_dev.in']
files: ^requirements_dev\.(in|txt)$
- id: pip-compile
name: pip-compile --upgrade requirements_test.in
args: ['--upgrade', 'requirements_test.in']
name: pip-compile requirements_test.in
args: ['requirements_test.in']
files: ^requirements_test\.(in|txt)$
- repo: https://github.com/lucasmbrown/mirrors-autoflake
rev: v1.3
Expand Down Expand Up @@ -49,7 +49,7 @@ repos:
- flake8-assertive==2.1.0
- flake8-bandit==3.0.0
- flake8-blind-except==0.2.1
- flake8-bugbear==22.4.25
- flake8-bugbear==22.7.1
- flake8-builtins==1.5.3
- flake8-comprehensions==3.10.0
- flake8-docstrings==1.6.0
Expand Down Expand Up @@ -82,7 +82,7 @@ repos:
- toml
- lxml-stubs==0.4.0
- sqlalchemy-stubs==0.4
- types-certifi==2021.10.8.2
- types-certifi==2021.10.8.3
- types-click==7.1.8
- types-cryptography==3.3.21
- types-flask==1.1.6
Expand All @@ -92,27 +92,31 @@ repos:
- types-jinja2==2.11.9
- types-markupsafe==1.1.10
- types-maxminddb==1.5.0
- types-python-dateutil==2.8.17
- types-pytz==2021.3.8
- types-requests==2.27.29
- types-setuptools==57.4.17
- types-python-dateutil==2.8.18
- types-pytz==2022.1.1
- types-requests==2.28.0
- types-setuptools==57.4.18
- types-simplejson==3.17.6
- types-six==1.16.15
- types-six==1.16.17
- types-toml==0.10.7
- types-urllib3==1.26.15
- types-werkzeug==1.0.9
- typing-extensions==4.3.0
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: *flake8deps
# - repo: https://github.com/PyCQA/pylint
# rev: v2.14.0-b1
# hooks:
# - id: pylint
# additional_dependencies:
# - toml
# - pylint-pytest
- repo: https://github.com/PyCQA/pylint
rev: v2.14.4
hooks:
- id: pylint
args:
['--disable=import-error', '-rn', '-sn', '--ignore-paths', 'tests']
additional_dependencies:
- toml
- pylint-pytest
- pylint-flask-sqlalchemy
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
Expand Down Expand Up @@ -151,14 +155,14 @@ repos:
- id: no-commit-to-branch
- id: trailing-whitespace
args: ['--markdown-linebreak-ext=md']
# Enable after auditing existing templates
# - repo: https://github.com/thibaudcolas/curlylint
# rev: v0.13.0
# hooks:
# - id: curlylint
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
args: ['--single-quote', '--trailing-comma', 'es5']
exclude: funnel/templates/js/
- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.3.0
hooks:
- id: djlint-jinja
files: \.(jinja2|j2)$
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ babel:
pybabel update -N -i funnel/translations/messages.pot -d funnel/translations
pybabel compile -f -d funnel/translations
cd funnel/assets; make babel

deps: deps-main deps-dev deps-test

deps-main:
pip-compile --upgrade requirements.in

deps-dev:
pip-compile --upgrade requirements_dev.in

deps-test:
pip-compile --upgrade requirements_test.in
6 changes: 0 additions & 6 deletions fabfile.py

This file was deleted.

2 changes: 2 additions & 0 deletions funnel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Hasgeek website app bootstrap."""

from __future__ import annotations

from datetime import timedelta
Expand Down
2 changes: 2 additions & 0 deletions funnel/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""App version number (unused)."""

from __future__ import annotations

__all__ = ['__version__', '__version_info__']
Expand Down
2 changes: 2 additions & 0 deletions funnel/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Command line interface."""
# flake8: noqa

from __future__ import annotations

from . import geodata, misc, periodic
2 changes: 2 additions & 0 deletions funnel/cli/misc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Miscellaneous CLI commands."""

from __future__ import annotations

from baseframe import baseframe_translations
Expand Down
2 changes: 2 additions & 0 deletions funnel/cli/periodic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Periodic maintenance actions."""

from __future__ import annotations

from dataclasses import dataclass
Expand Down
6 changes: 1 addition & 5 deletions funnel/extapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# flake8: noqa

from __future__ import annotations

from .explara import *
"""External API support."""
2 changes: 2 additions & 0 deletions funnel/extapi/boxoffice.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""External API support for Boxoffice."""

from __future__ import annotations

from urllib.parse import urljoin
Expand Down
2 changes: 2 additions & 0 deletions funnel/extapi/explara.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""External API support for Explara."""

from __future__ import annotations

import requests
Expand Down
1 change: 1 addition & 0 deletions funnel/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Forms provide an interface between views and models, validating data before save."""
# flake8: noqa

from __future__ import annotations
Expand Down
2 changes: 2 additions & 0 deletions funnel/forms/comment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Forms for comments."""

from __future__ import annotations

from baseframe import __, forms
Expand Down
2 changes: 2 additions & 0 deletions funnel/forms/label.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Forms for workflow labels."""

from __future__ import annotations

from baseframe import __, forms
Expand Down
2 changes: 2 additions & 0 deletions funnel/forms/membership.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Forms for organization admin and project crew memberships."""

from __future__ import annotations

from baseframe import _, __, forms
Expand Down
1 change: 1 addition & 0 deletions funnel/loginproviders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Login provider implementations."""
# flake8: noqa

from __future__ import annotations
Expand Down
2 changes: 2 additions & 0 deletions funnel/loginproviders/github.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""GitHub OAuth2 client."""

from __future__ import annotations

from flask import current_app, redirect, request
Expand Down
2 changes: 2 additions & 0 deletions funnel/loginproviders/google.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Google OAuth2 client."""

from __future__ import annotations

from flask import current_app, redirect, request, session
Expand Down
2 changes: 2 additions & 0 deletions funnel/loginproviders/init_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Configure login provider OAuth clients."""

from __future__ import annotations

from baseframe import __
Expand Down
2 changes: 2 additions & 0 deletions funnel/loginproviders/linkedin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""LinkedIn OAuth2 client."""

from __future__ import annotations

from secrets import token_urlsafe
Expand Down
2 changes: 2 additions & 0 deletions funnel/loginproviders/twitter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Twitter OAuth1a client."""

from __future__ import annotations

from flask import redirect, request
Expand Down
1 change: 1 addition & 0 deletions funnel/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Provide configuration for models and import all into a common `models` namespace."""
# flake8: noqa

from __future__ import annotations
Expand Down
12 changes: 9 additions & 3 deletions funnel/models/comment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Comment and Commentset models."""

from __future__ import annotations

from typing import Iterable, List, Optional, Set, Union
Expand All @@ -6,7 +8,7 @@
from werkzeug.utils import cached_property

from baseframe import _, __
from coaster.sqlalchemy import RoleAccessProxy, StateManager, with_roles
from coaster.sqlalchemy import LazyRoleSet, RoleAccessProxy, StateManager, with_roles
from coaster.utils import LabeledEnum

from . import BaseMixin, MarkdownColumn, TSVectorType, UuidMixin, db, hybrid_property
Expand Down Expand Up @@ -133,7 +135,9 @@ def last_comment(self):

with_roles(last_comment, read={'all'}, datasets={'primary'})

def roles_for(self, actor: Optional[User] = None, anchors: Iterable = ()) -> Set:
def roles_for(
self, actor: Optional[User] = None, anchors: Iterable = ()
) -> LazyRoleSet:
roles = super().roles_for(actor, anchors)
parent_roles = self.parent.roles_for(actor, anchors)
if 'participant' in parent_roles or 'commenter' in parent_roles:
Expand Down Expand Up @@ -365,7 +369,9 @@ def mark_spam(self) -> None:
def mark_not_spam(self) -> None:
"""Mark this comment as not spam."""

def roles_for(self, actor: Optional[User] = None, anchors: Iterable = ()) -> Set:
def roles_for(
self, actor: Optional[User] = None, anchors: Iterable = ()
) -> LazyRoleSet:
roles = super().roles_for(actor, anchors)
roles.add('reader')
return roles
Expand Down
2 changes: 2 additions & 0 deletions funnel/models/commentset_membership.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Model for membership to a commentset for new comment notifications."""

from __future__ import annotations

from typing import Set
Expand Down
12 changes: 9 additions & 3 deletions funnel/models/contact_exchange.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""Model for contacts scanned from badges at in-person events."""

from __future__ import annotations

from dataclasses import dataclass
from datetime import date as date_type
from datetime import datetime
from itertools import groupby
from typing import Collection, Iterable, Optional, Set
from typing import Collection, Iterable, Optional
from uuid import UUID

from sqlalchemy.ext.associationproxy import association_proxy

from coaster.sqlalchemy import LazyRoleSet
from coaster.utils import uuid_to_base58

from ..typing import OptionalMigratedTables
Expand Down Expand Up @@ -90,7 +94,9 @@ class ContactExchange(TimestampMixin, RoleMixin, db.Model):
'subject': {'read': {'user', 'ticket_participant', 'scanned_at'}},
}

def roles_for(self, actor: Optional[User] = None, anchors: Iterable = ()) -> Set:
def roles_for(
self, actor: Optional[User] = None, anchors: Iterable = ()
) -> LazyRoleSet:
roles = super().roles_for(actor, anchors)
if actor is not None:
if actor == self.user:
Expand Down Expand Up @@ -227,7 +233,7 @@ def grouped_counts_for(cls, user, archived=False):

@classmethod
def contacts_for_project_and_date(
cls, user: User, project: Project, date: datetime, archived=False
cls, user: User, project: Project, date: date_type, archived=False
):
"""Return contacts for a given user, project and date."""
query = cls.query.join(TicketParticipant).filter(
Expand Down
2 changes: 2 additions & 0 deletions funnel/models/draft.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Model for unvalidated drafts for web forms."""

from __future__ import annotations

from werkzeug.datastructures import MultiDict
Expand Down
2 changes: 2 additions & 0 deletions funnel/models/label.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Workflow label models."""

from __future__ import annotations

from typing import Union
Expand Down
2 changes: 2 additions & 0 deletions funnel/models/moderation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Site moderator models."""

from __future__ import annotations

from baseframe import __
Expand Down
2 changes: 2 additions & 0 deletions funnel/models/organization_membership.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Membership model for admins of an organization."""

from __future__ import annotations

from typing import Set
Expand Down
10 changes: 6 additions & 4 deletions funnel/models/profile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Profile model."""
"""Profile model, linked to a User or Organization model."""

from __future__ import annotations

from typing import Iterable, List, Optional, Set, Union
from typing import Iterable, List, Optional, Union

from sqlalchemy.sql import expression

from baseframe import __
from coaster.sqlalchemy import Query, StateManager, immutable, with_roles
from coaster.sqlalchemy import LazyRoleSet, Query, StateManager, immutable, with_roles
from coaster.utils import LabeledEnum

from ..typing import OptionalMigratedTables
Expand Down Expand Up @@ -337,7 +337,9 @@ def pickername(self) -> str:
return self.organization.pickername
return self.title

def roles_for(self, actor: Optional[User] = None, anchors: Iterable = ()) -> Set:
def roles_for(
self, actor: Optional[User] = None, anchors: Iterable = ()
) -> LazyRoleSet:
if self.owner:
roles = self.owner.roles_for(actor, anchors)
else:
Expand Down
Loading

0 comments on commit f34657c

Please sign in to comment.