Skip to content

Commit

Permalink
feat!: Project dust-off
Browse files Browse the repository at this point in the history
  • Loading branch information
janw committed Jan 19, 2024
1 parent 0a4cb03 commit c3f8f68
Show file tree
Hide file tree
Showing 32 changed files with 2,608 additions and 1,269 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
liberapay: janw
ko_fi: janwxyz
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: pip
directory: /
schedule:
interval: weekly
labels:
- dependencies
commit-message:
prefix: "build(deps)"
57 changes: 57 additions & 0 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Docker Build

on:
pull_request:
push:
branches:
- "main"
tags:
- "*"

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get python version from file
run: echo "PYTHON_VERSION=$(cat .python-version)" | tee -a "$GITHUB_ENV"

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: "ghcr.io/${{ github.repository }}"
tags: |
type=ref,event=pr
type=semver,pattern=v{{major}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{version}}
type=raw,value=edge,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Github Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64 # TODO: add `linux/arm64/v8`
build-args: |
PYTHON_VERSION=${{ env.PYTHON_VERSION }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
14 changes: 0 additions & 14 deletions .github/workflows/docker.yaml

This file was deleted.

47 changes: 41 additions & 6 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,45 @@ on:
pull_request:

jobs:
gitlint:
uses: janw/workflows/.github/workflows/gitlint.yaml@main
with:
first-commit: abb56f5
commitizen:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
with:
fetch-depth: 0
sparse-checkout: |
pyproject.toml
sparse-checkout-cone-mode: false

pre-commit:
uses: janw/workflows/.github/workflows/pre-commit.yaml@main
- name: Install commitizen
run: pipx install commitizen

- run: cz check --rev-range origin/main..HEAD
shell: bash

# pre-commit-extras:
# runs-on: ubuntu-latest
# steps:
# - name: Check out
# uses: actions/checkout@v3

# - name: Get python version from file
# run: echo "PYTHON_VERSION=$(cat .python-version)" | tee -a "$GITHUB_ENV"

# - name: Install commitizen
# run: pipx install poetry

# - name: Set up python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ env.PYTHON_VERSION }}
# cache: 'poetry'

# - run: poetry install --with=dev

# - uses: pre-commit/[email protected]
# with:
# extra_args: >
# rich-codex
# --all-files
39 changes: 39 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tests

on:
pull_request:
push:
branches:
- "main"
tags:
- "*"

jobs:
pytest:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3

- name: Get python version from file
run: echo "PYTHON_VERSION=$(cat .python-version)" | tee -a "$GITHUB_ENV"

- name: Install poetry
run: pipx install poetry

- name: Set up python environment
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'poetry'

- run: poetry install --no-root --with=tests --sync

- run: poetry run pytest --cov-report=xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
name: coverage-${{ matrix.python-version }}
41 changes: 14 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
ci:
autofix_prs: false
autoupdate_schedule: quarterly
autoupdate_commit_msg: 'build(deps): [pre-commit.ci] pre-commit autoupdate'

exclude: >
(?x)^(
.+\.svg|
.+/migrations/.+|
.+/fixtures/.+|
.+/cassettes/.+
)$
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.267'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.14'
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/psf/black
rev: "23.3.0"
hooks:
- id: black

- repo: local
hooks:
- id: python-no-print
name: check for print()
description: 'A quick check for the `print()` built-in function'
entry: '\bprint\('
language: pygrep
types: [python]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: 'v1.10.0'
hooks:
- id: python-check-blanket-noqa
- id: python-no-eval
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.4.0'
rev: 'v4.5.0'
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-builtin-literals
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable

- repo: https://github.com/python-poetry/poetry
rev: '1.4.2'
rev: '1.7.1'
hooks:
- id: poetry-check
- id: poetry-lock
- id: poetry-export
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION

FROM node:16 as frontend
LABEL maintainer="Jan Willhaus <[email protected]"

WORKDIR /frontend
COPY package-lock.json package.json ./
Expand All @@ -9,7 +11,7 @@ COPY vite.config.js ./
COPY frontend ./frontend
RUN npm run build

FROM python:3.7-alpine
FROM python:${PYTHON_VERSION}-alpine
ENV PIP_NO_CACHE_DIR off
ENV PYTHONUNBUFFERED 1

Expand Down
73 changes: 20 additions & 53 deletions listeners/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.translation import gettext as _

from podcasts.enums import EpisodeOrder, ImageSecurityPolicy, PodcastOrder
from podcasts.models import IntegerRangeField


Expand All @@ -14,66 +14,33 @@ class User(AbstractUser):
DEFAULT_IMAGE_SECURITY_POLICY = "f"
SEEK_FORWARD_BY = 45
SEEK_BACKWARD_BY = 30
# Playback-related options (maybe in the future)

PODCASTS_ORDER_CHOICES = (
(_("Content"), (("title", _("Title")),)),
(
_("Metadata"),
(
("last_episode_date", _("Last Published Episode")),
("num_episodes", _("Number of Episodes")),
),
),
)

EPISODES_ORDER_CHOICES = (
(_("Content"), (("title", _("Title")),)),
(
_("Metadata"),
(
("downloaded", _("Download Date (Earliest First)")),
("-downloaded", _("Download Date (Latest First)")),
("published", _("Publishing Date (Earliest First)")),
("-published", _("Publishing Date (Latest First)")),
("itunes_duration", _("Duration (Shortest First)")),
("-itunes_duration", _("Duration (Longest First)")),
),
),
)

IMAGE_SECURITY_POLICY_CHOICES = (
("a", _("Allow All")),
("f", _("Allow First-Party")),
("n", _("Allow None")),
)

# Display settings
sort_order_podcasts = models.CharField(
choices=PODCASTS_ORDER_CHOICES,
default=DEFAULT_PODCASTS_ORDER,
max_length=16,
verbose_name=_("Sort Podcasts By"),
help_text=_("Determines the sorting of podcasts in the podcasts list"),
choices=PodcastOrder,
default=PodcastOrder.default(),
max_length=3,
verbose_name="Sort Podcasts By",
help_text="Determines the sorting of podcasts in the podcasts list",
)
sort_order_episodes = models.CharField(
choices=EPISODES_ORDER_CHOICES,
default=DEFAULT_EPISODES_ORDER,
max_length=16,
verbose_name=_("Sort Episodes By"),
help_text=_("Determines the sorting of episodes on podcast detail pages"),
choices=EpisodeOrder,
default=EpisodeOrder.default(),
max_length=4,
verbose_name="Sort Episodes By",
help_text="Determines the sorting of episodes on podcast detail pages",
)
dark_mode = models.BooleanField(
default=False,
verbose_name=_("Dark Mode"),
help_text=_("Reduce eye strain at night, increase awesomeness by day."),
verbose_name="Dark Mode",
help_text="Reduce eye strain at night, increase awesomeness by day.",
)
image_security_policy = models.CharField(
choices=IMAGE_SECURITY_POLICY_CHOICES,
default=DEFAULT_IMAGE_SECURITY_POLICY,
choices=ImageSecurityPolicy,
default=ImageSecurityPolicy.default(),
max_length=1,
verbose_name=_("Image Security Policy"),
help_text=_("How to load external images in show notes, etc."),
verbose_name="Image Security Policy",
help_text="How to load external images in show notes, etc.",
)

# Settings for future playback functionality
Expand All @@ -83,19 +50,19 @@ class User(AbstractUser):
default=SEEK_FORWARD_BY,
min_value=1,
max_value=360,
verbose_name=_("Seek Duration Forward"),
verbose_name="Seek Duration Forward",
)
playback_seek_backward_by = IntegerRangeField(
null=True,
blank=True,
default=SEEK_BACKWARD_BY,
min_value=1,
max_value=360,
verbose_name=_("Seek Duration Backward"),
verbose_name="Seek Duration Backward",
)

def __str__(self):
return _("User %(user)s") % {"user": self.username}
return f"User {self.username}"

def has_played(self, episode):
from podcasts.models.episode import EpisodePlaybackState
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tapedrive",
"version": "0.2.0",
"version": "0.1.0",
"description": "A self-hostable podcast client with built-in archiving features.",
"main": "assets/dist/bundles/main.js",
"repository": "[email protected]:janw/tapedrive.git",
Expand Down
Loading

0 comments on commit c3f8f68

Please sign in to comment.