Skip to content

Commit

Permalink
Config from env; pre-commit checks and reformatted files (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
jace authored Aug 8, 2023
1 parent 381d913 commit 1a104b4
Show file tree
Hide file tree
Showing 47 changed files with 371 additions and 174 deletions.
92 changes: 92 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
ci:
skip: ["no-commit-to-branch"]
repos:
- repo: https://github.com/pre-commit-ci/pre-commit-ci-config
rev: v1.5.1
hooks:
- id: check-pre-commit-ci-config
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.282
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix"]
# Extra args, only after removing flake8 and yesqa: '--extend-select', 'RUF100'
- repo: https://github.com/lucasmbrown/mirrors-autoflake
rev: v1.3
hooks:
- id: autoflake
args:
[
"--in-place",
"--remove-all-unused-imports",
"--ignore-init-module-imports",
"--remove-unused-variables",
"--remove-duplicate-keys",
]
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args:
["--keep-runtime-typing", "--py3-plus", "--py36-plus", "--py37-plus"]
- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa
additional_dependencies: &flake8deps
- toml
- tomli
- flake8-assertive
- flake8-blind-except
- flake8-builtins
- flake8-comprehensions
- flake8-isort
- flake8-logging-format
- flake8-mutable
- flake8-print
- pep8-naming
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
additional_dependencies:
- tomli
- toml
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies: *flake8deps
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: detect-aws-credentials
args: ["--allow-missing-credentials"]
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: ["--remove"]
- id: forbid-new-submodules
- id: mixed-line-ending
- id: no-commit-to-branch
- id: requirements-txt-fixer
- id: trailing-whitespace
13 changes: 5 additions & 8 deletions hgtv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# -*- coding: utf-8 -*-

# The imports in this file are order-sensitive

from flask import Flask
from flask_migrate import Migrate

from flask_lastuser import Lastuser
from flask_lastuser.sqlalchemy import UserManager
from pytz import timezone

from baseframe import Version, baseframe
import coaster.app
from baseframe import Version, baseframe
from flask_lastuser import Lastuser
from flask_lastuser.sqlalchemy import UserManager

from ._version import __version__

Expand All @@ -20,10 +17,10 @@


from . import models, uploads, views # NOQA
from .models import db # NOQA
from .models import db

# Configure the app
coaster.app.init_app(app)
coaster.app.init_app(app, ['py', 'env'], env_prefix=['FLASK', 'APP_HGTV'])
db.init_app(app)
db.app = app
migrate = Migrate(app, db)
Expand Down
3 changes: 1 addition & 2 deletions hgtv/assets/src/assets/sass/app.sass
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
100%
transform: rotate(360deg)

.livestream
.livestream
div
width: 100%

Expand All @@ -342,4 +342,3 @@
@media (min-width: 700px)
.livestream .tabs-component-panels
padding: 4em 2em

1 change: 0 additions & 1 deletion hgtv/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# flake8: noqa

from hgtv.forms.channel import *
Expand Down
4 changes: 1 addition & 3 deletions hgtv/forms/channel.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-

from baseframe import forms

__all__ = ['ChannelForm']


class ChannelForm(forms.Form):
type = forms.SelectField(
type = forms.SelectField( # noqa: A003
"Channel type", coerce=int, validators=[forms.validators.DataRequired()]
)
description = forms.TinyMce4Field("Description")
Expand Down
5 changes: 2 additions & 3 deletions hgtv/forms/playlist.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-

import re

from baseframe import forms
from flask import request
from flask_uploads import UploadNotAllowed
from PIL import Image

from baseframe import forms

from hgtv.models import Playlist

__all__ = ['PlaylistForm', 'PlaylistAddForm', 'PlaylistImportForm']
Expand Down
2 changes: 0 additions & 2 deletions hgtv/forms/video.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from baseframe import forms

from .. import lastuser
Expand Down
4 changes: 2 additions & 2 deletions hgtv/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# flake8: noqa

from flask_sqlalchemy import SQLAlchemy

from baseframe import __
from coaster.db import db
from coaster.sqlalchemy import (
Expand All @@ -11,7 +12,6 @@
TimestampMixin,
)
from coaster.utils import LabeledEnum
from flask_sqlalchemy import SQLAlchemy

from hgtv import app

Expand Down
49 changes: 27 additions & 22 deletions hgtv/models/channel.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# -*- coding: utf-8 -*-

from datetime import date

from baseframe import cache
from coaster.utils import LabeledEnum
from flask import url_for
from flask_lastuser.sqlalchemy import ProfileBase
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.ext.orderinglist import ordering_list
from werkzeug.utils import cached_property

from baseframe import cache
from coaster.utils import LabeledEnum
from flask_lastuser.sqlalchemy import ProfileBase

from ..models import PLAYLIST_AUTO_TYPE, BaseMixin, BaseScopedNameMixin, db
from .video import PlaylistVideo, Video

__all__ = ['CHANNEL_TYPE', 'PLAYLIST_TYPE', 'Channel', 'Playlist', 'PlaylistRedirect']


class CHANNEL_TYPE(LabeledEnum):
class CHANNEL_TYPE(LabeledEnum): # noqa: N801
UNDEFINED = (0, "Channel")
PERSON = (1, "Person")
ORGANIZATION = (2, "Organization")
Expand All @@ -25,7 +24,7 @@ class CHANNEL_TYPE(LabeledEnum):
__order__ = (UNDEFINED, PERSON, ORGANIZATION, EVENTSERIES)


class PLAYLIST_TYPE(LabeledEnum):
class PLAYLIST_TYPE(LabeledEnum): # noqa: N801
REGULAR = (0, "Playlist")
EVENT = (1, "Event")

Expand All @@ -35,7 +34,9 @@ class Channel(ProfileBase, db.Model):
description = db.Column(db.UnicodeText, default='', nullable=False)
bio = db.Column(db.Unicode(250), nullable=True)
featured = db.Column(db.Boolean, default=False, nullable=False)
type = db.Column(db.Integer, default=CHANNEL_TYPE.UNDEFINED, nullable=False)
type = db.Column( # noqa: A003
db.Integer, default=CHANNEL_TYPE.UNDEFINED, nullable=False
)
channel_logo_filename = db.Column(db.Unicode(250), nullable=True, default='')
channel_banner_url = db.Column(db.Unicode(250), nullable=True)

Expand All @@ -45,7 +46,7 @@ class Channel(ProfileBase, db.Model):
}

def __repr__(self):
return '<Channel %s "%s">' % (self.name, self.title)
return f'<Channel {self.name} "{self.title}">'

@property
def current_action_permissions(self):
Expand All @@ -69,10 +70,10 @@ def get_featured(cls):
return (
cls.query.join(Playlist)
.join(Video)
.filter(Channel.featured == True)
.filter(Channel.featured.is_(True))
.order_by(Video.created_at.desc())
.all()
) # NOQA
)

@cached_property
def user_playlists(self):
Expand Down Expand Up @@ -117,12 +118,12 @@ def auto_playlists(self):
"""
Returns a dictionary of playlist_code: playlist
"""
return dict(
(playlist.auto_type, playlist)
return {
playlist.auto_type: playlist
for playlist in Playlist.query.filter_by(channel=self).filter(
Playlist.auto_type is not None
)
)
}

def playlist_for_watched(self, create=False):
return self.get_auto_playlist(PLAYLIST_AUTO_TYPE.WATCHED, create, False)
Expand Down Expand Up @@ -152,13 +153,13 @@ def playlist_for_stream(self, create=False):
return self.get_auto_playlist(PLAYLIST_AUTO_TYPE.STREAM, create, True)

def roles_for(self, actor=None, anchors=()):
roles = super(Channel, self).roles_for(actor, anchors)
roles = super().roles_for(actor, anchors)
if actor and self.userid in actor.user_organizations_owned_ids():
roles.add('channel_admin')
return roles

def permissions(self, user, inherited=None):
perms = super(Channel, self).permissions(user, inherited)
perms = super().permissions(user, inherited)
perms.add('view')
if user and self.userid in user.user_organizations_owned_ids():
perms.add('edit')
Expand Down Expand Up @@ -194,7 +195,9 @@ class Playlist(BaseScopedNameMixin, db.Model):
recorded_date = db.Column(db.Date, nullable=True)
published_date = db.Column(db.Date, nullable=False, default=date.today)
featured = db.Column(db.Boolean, default=False, nullable=False)
type = db.Column(db.Integer, default=PLAYLIST_TYPE.REGULAR, nullable=False)
type = db.Column( # noqa: A003
db.Integer, default=PLAYLIST_TYPE.REGULAR, nullable=False
)
auto_type = db.Column(db.Integer, nullable=True)
banner_ad_filename = db.Column(db.Unicode(250), nullable=True, default='')
banner_ad_url = db.Column(db.Unicode(250), nullable=True, default='')
Expand Down Expand Up @@ -234,9 +237,11 @@ class Playlist(BaseScopedNameMixin, db.Model):

def __repr__(self):
if self.auto_type:
return '<AutoPlaylist %s of %s>' % (self.type_label(), self.channel.title)
return '<AutoPlaylist {} of {}>'.format(
self.type_label(), self.channel.title
)
else:
return '<Playlist %s of %s>' % (self.title, self.channel.title)
return f'<Playlist {self.title} of {self.channel.title}>'

@property
def current_action_permissions(self):
Expand Down Expand Up @@ -345,14 +350,14 @@ def type_label(self):
return PLAYLIST_TYPE.get(self.type, PLAYLIST_TYPE[0])

def roles_for(self, actor=None, anchors=()):
roles = super(Playlist, self).roles_for(actor, anchors)
roles = super().roles_for(actor, anchors)
roles.update(self.channel.roles_for(actor, anchors))
if 'channel_admin' in roles:
roles.add('playlist_admin')
return roles

def permissions(self, user, inherited=None):
perms = super(Playlist, self).permissions(user, inherited)
perms = super().permissions(user, inherited)
if self.public:
perms.add('view')
if user and self.channel.userid in user.user_organizations_owned_ids():
Expand Down Expand Up @@ -410,7 +415,7 @@ def url_for(self, action='view', _external=False):
_external=_external,
)

def next(self, video):
def next(self, video): # noqa: A003
for index, _video in enumerate(self.videos):
if video is _video:
try:
Expand Down
2 changes: 0 additions & 2 deletions hgtv/models/tag.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from coaster.utils import make_name

from hgtv.models import BaseMixin, db
Expand Down
5 changes: 2 additions & 3 deletions hgtv/models/user.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-

from flask import url_for
from flask_lastuser.sqlalchemy import UserBase2
from werkzeug.utils import cached_property

from flask_lastuser.sqlalchemy import UserBase2

from hgtv.models import PLAYLIST_AUTO_TYPE, db
from hgtv.models.channel import Channel

Expand Down
Loading

0 comments on commit 1a104b4

Please sign in to comment.