Skip to content

Commit 7befd94

Browse files
committed
Move languages and backend to separate submodules
1 parent 4439926 commit 7befd94

File tree

9 files changed

+69
-49
lines changed

9 files changed

+69
-49
lines changed

blobopera/backend/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .backend import Backend

blobopera/command/recording.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import music21
66
import typer
77

8-
from ..language import Generic, Random
8+
from ..languages import Generic, Random
99
from ..phoneme import Phoneme
1010
from ..recording import Recording
1111
from ..theme import Theme

blobopera/languages/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .generic import Generic
2+
from .language import Language
3+
from .random import Random
Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,11 @@
1-
import random
21
import re
32
import unicodedata
4-
from abc import abstractmethod
5-
from typing import List, Optional, Protocol
3+
from typing import List, Optional
64

75
import music21
86

9-
from .phoneme import Phoneme
10-
11-
12-
class Language(Protocol):
13-
@abstractmethod
14-
def __init__(self, part: music21.stream.Part):
15-
pass
16-
17-
@abstractmethod
18-
def parse(
19-
self, time: float, lyrics: Optional[str], index: int
20-
) -> Optional[List[Phoneme]]:
21-
pass
22-
23-
24-
class Random(Language):
25-
"""Generate random phonemes for parts without any lyrics."""
26-
27-
def __init__(self, part: music21.stream.Part, *, strict: bool = False):
28-
"""Initialize the language with the complete stream, so parsers
29-
can look around and take decisions based on the surrounding lyrics.
30-
"""
31-
self.part, self.strict = part, strict
32-
33-
def parse(
34-
self, time: float, lyrics: Optional[str], index: int
35-
) -> Optional[List[Phoneme]]:
36-
"""Parse the given lyrics and return random vowel-consonant pairs.
37-
38-
>>> parse(None)
39-
[<Phoneme.I: 8>, <Phoneme.C: 2>]
40-
"""
41-
if lyrics and self.strict:
42-
raise ValueError("random language doesn't accept lyrics")
43-
44-
random.seed(time)
45-
while not (vowel := random.choice(Phoneme)).vowel():
46-
pass
47-
while not (consonant := random.choice(Phoneme)).consonant():
48-
pass
49-
50-
return [vowel, consonant]
7+
from ..phoneme import Phoneme
8+
from .language import Language
519

5210

5311
class Generic(Language):

blobopera/languages/language.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from abc import abstractmethod
2+
from typing import List, Optional, Protocol
3+
4+
import music21
5+
6+
from ..phoneme import Phoneme
7+
8+
9+
class Language(Protocol):
10+
@abstractmethod
11+
def __init__(self, part: music21.stream.Part):
12+
pass
13+
14+
@abstractmethod
15+
def parse(
16+
self, time: float, lyrics: Optional[str], index: int
17+
) -> Optional[List[Phoneme]]:
18+
pass

blobopera/languages/random.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import random
2+
from typing import List, Optional
3+
4+
import music21
5+
6+
from ..phoneme import Phoneme
7+
from .language import Language
8+
9+
10+
class Random(Language):
11+
"""Generate random phonemes for parts without any lyrics."""
12+
13+
def __init__(self, part: music21.stream.Part, *, strict: bool = False):
14+
"""Initialize the language with the complete stream, so parsers
15+
can look around and take decisions based on the surrounding lyrics.
16+
"""
17+
self.part, self.strict = part, strict
18+
19+
def parse(
20+
self, time: float, lyrics: Optional[str], index: int
21+
) -> Optional[List[Phoneme]]:
22+
"""Parse the given lyrics and return random vowel-consonant pairs.
23+
24+
>>> parse(None)
25+
[<Phoneme.I: 8>, <Phoneme.C: 2>]
26+
"""
27+
if lyrics and self.strict:
28+
raise ValueError("random language doesn't accept lyrics")
29+
30+
random.seed(time)
31+
while not (vowel := random.choice(Phoneme)).vowel():
32+
pass
33+
while not (consonant := random.choice(Phoneme)).consonant():
34+
pass
35+
36+
return [vowel, consonant]

blobopera/recording.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import music21
44
import proto
55

6-
from .language import Generic, Language
6+
from .languages import Generic, Language
77
from .phoneme import Phoneme, Timed
88
from .theme import Theme
99

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ flake8-bandit = ["-S101"]
6666
"flake8-*" = ["-A001"]
6767
pyflakes = ["-F811", "-F401"]
6868

69-
[tool.flakehell.exceptions."blobopera/language.py"]
69+
70+
[tool.flakehell.exceptions."blobopera/**/__init__.py"]
71+
pyflakes = ["-F401"]
72+
73+
[tool.flakehell.exceptions."blobopera/languages/random.py"]
7074
flake8-bandit = ["-S311"]
7175

7276
[tool.flakehell.exceptions."blobopera/command/*.py"]
@@ -85,4 +89,4 @@ lint = "flakehell lint"
8589
test = "pytest"
8690
coverage = {"shell" = "coverage run -m pytest; coverage report -m"}
8791
document = "typer blobopera.command utils docs --output documentation/command/README.md --name blobopera"
88-
all = ["style", "lint", "test", "coverage", "document"]
92+
all = ["style", "lint", "coverage", "document"]

0 commit comments

Comments
 (0)