Skip to content

Commit

Permalink
Migrate to ruff and pre-commit (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored Feb 6, 2025
1 parent 4ed7301 commit 7aa1c09
Show file tree
Hide file tree
Showing 28 changed files with 838 additions and 1,441 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
python-version: '3.10'
- run: poetry install
- uses: tschm/token-mint-action@v1.0.3
id: mint
id: mint
- run: poetry publish --build -u __token__ -p $PYPI_TOKEN
env:
PYPI_TOKEN: ${{ steps.mint.outputs.api-token }}
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:
strategy:
matrix:
action:
- style
- lint
- test
- coverage
steps:
Expand All @@ -23,3 +21,10 @@ jobs:
python-version: '3.10'
- run: poetry install
- run: poetry run poe ${{ matrix.action }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pre-commit/action@v3.0.1
env:
SKIP: poetry-lock
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-json
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
exclude: ^tests/.*\.data/
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/python-poetry/poetry
rev: 2.0.1
hooks:
- id: poetry-check
- id: poetry-lock
- repo: https://github.com/python-poetry/poetry
rev: 2.0.1
hooks:
- id: poetry-install
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<a href="https://www.gnu.org/licenses/gpl-3.0">
<img alt="license" src="https://img.shields.io/badge/license-GPL3-blue.svg">
</a>
<a href="https://github.com/psf/black">
<img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg">
</a>
</p>

## Description
Expand Down
2 changes: 2 additions & 0 deletions blobopera/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
"""

from .backend import Backend

__all__ = ["Backend"]
5 changes: 3 additions & 2 deletions blobopera/command/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This file provides data import functions and some shared defaults and
enumerations used by choice-like subcommand options.
"""

from enum import Enum
from typing import Type

Expand Down Expand Up @@ -73,8 +74,8 @@ class FillPhoneme(str, Enum):
SILENCE = "SILENCE"
A = "A"
E = "E"
I = "I"
O = "O"
I = "I" # noqa: E741
O = "O" # noqa: E741
U = "U"


Expand Down
1 change: 1 addition & 0 deletions blobopera/command/libretto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Inspect the default corpus of libretto texts."""

import requests
import typer

Expand Down
3 changes: 2 additions & 1 deletion blobopera/command/recording.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Operate with recording files and scores."""

import tempfile
from pathlib import Path

Expand Down Expand Up @@ -149,7 +150,7 @@ def _import( # Prepend an underscore because import is a reserved keyword.
tempo=tempo,
parts=parts,
fill=Phoneme[fill.value],
location=Location[location.value]
location=Location[location.value],
)

output.write(
Expand Down
2 changes: 1 addition & 1 deletion blobopera/jitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
be used to serialize and deserialize the ``jittertemplates.proto`` file from
the original Blob Opera application.
"""

from functools import partial
from random import Random
from typing import Any, Callable, Iterator
Expand Down Expand Up @@ -90,7 +91,6 @@ def __iter__(self) -> Iterator[float]:

# Iterate over randomly chosen templates with (previous, current) pairs
for previous, current in pairwise(random): # (0, 1), (1, 2), (2, 3)...

# Get the tail (last values) of the previous template and the head
# (first values) of the current template. Due to an off-by-one
# error in the original code, the tail from the previous template
Expand Down
3 changes: 3 additions & 0 deletions blobopera/languages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
These modules provide parsers for converting lyrics from different languages
into sequences of phonemes following the Blob Opera phoneme format.
"""

from .generic import GenericLanguage
from .language import Language
from .random import RandomLanguage

__all__ = ["GenericLanguage", "Language", "RandomLanguage"]
1 change: 1 addition & 0 deletions blobopera/languages/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This language module aims to achieve a good enough universal phoneme conversion
if there isn't a better alternative.
"""

import re
import unicodedata
from typing import List
Expand Down
1 change: 1 addition & 0 deletions blobopera/languages/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This file describes a protocol for the interaction between the recording
importer and the different language classes.
"""

from abc import abstractmethod
from typing import List, Protocol

Expand Down
1 change: 1 addition & 0 deletions blobopera/languages/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This language module provides random lyrics as seen in the default Blob Opera
carols. It should be avoided, whenever desirable, in favor of actual lyrics.
"""

import random
from typing import Callable, List

Expand Down
1 change: 1 addition & 0 deletions blobopera/libretto.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
a good reference for translating Italian lyrics to phonemes with the
:py:class:`Phoneme` syntax.
"""

import proto # type: ignore

from .phoneme import Phoneme
Expand Down
1 change: 1 addition & 0 deletions blobopera/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module describes the location pictures that can be used in
the Blob Opera application user interface.
"""

import proto # type: ignore

__protobuf__ = proto.module(package=__name__)
Expand Down
5 changes: 3 additions & 2 deletions blobopera/phoneme.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Eclesiastical Latin in mind, so it's quite hard to describe certain sounds
from other languages, like the German vowels ü, ö and ä.
"""

import proto # type: ignore

__protobuf__ = proto.module(package=__name__)
Expand All @@ -18,10 +19,10 @@ class Phoneme(proto.Enum):
the total absence of sound.
"""

I = 0
I = 0 # noqa: E741
A = 1
E = 2
O = 3
O = 3 # noqa: E741
SILENCE = 4
R = 5
N = 6
Expand Down
1 change: 1 addition & 0 deletions blobopera/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module describes the themes that can be used in the Blob Opera application
user interface.
"""

import proto # type: ignore

__protobuf__ = proto.module(package=__name__)
Expand Down
4 changes: 2 additions & 2 deletions documentation/steganography/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Users that are in the know can build an extended descriptor in order to retrieve
```
00000000: 0a0d 4865 6c6c 6f2c 2077 6f72 6c64 21 ..Hello, world!
```
2. Bob uploads a crafted message, which includes a valid greeting along with a hidden string, by using the following descriptor:
```proto
syntax = "proto2";
Expand All @@ -40,7 +40,7 @@ Users that are in the know can build an extended descriptor in order to retrieve
00000010: 134a 6f68 616e 6e65 7320 5472 6974 6865 .Johannes Trithe
00000020: 6d69 7573 mius
```
3. Alice stores the uploaded message as-is on her public server because she's able to parse it without noticing any difference.
4. Charles downloads the message and parses it with the extended descriptor in order to recover the hidden text.
Expand Down
7 changes: 7 additions & 0 deletions documentation/steganography/example.ipynb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata" : {},
"cells": [
{
"cell_type": "code",
"metadata" : {},
"source": [
"%%bash\n",
"cat > alice.proto <<-END\n",
Expand All @@ -19,6 +21,7 @@
},
{
"cell_type": "code",
"metadata" : {},
"source": [
"%%bash\n",
"cat > bob.proto <<-END\n",
Expand All @@ -35,6 +38,7 @@
},
{
"cell_type": "code",
"metadata" : {},
"source": [
"%%bash\n",
"protoc --encode InconspicuousMessage bob.proto > message.bin <<-END\n",
Expand All @@ -47,6 +51,7 @@
},
{
"cell_type": "code",
"metadata" : {},
"source": [
"%%bash\n",
"protoc --decode InconspicuousMessage alice.proto < message.bin"
Expand All @@ -65,6 +70,7 @@
},
{
"cell_type": "code",
"metadata" : {},
"source": [
"%%bash\n",
"protoc --decode InconspicuousMessage bob.proto < message.bin"
Expand All @@ -83,6 +89,7 @@
},
{
"cell_type": "code",
"metadata" : {},
"source": [
"%%bash\n",
"protoc --decode_raw < message.bin"
Expand Down
Loading

0 comments on commit 7aa1c09

Please sign in to comment.