Skip to content

Commit

Permalink
Adding missing docstrings and typehints, adding pydocstyles to make test
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertohasnofb committed Jan 10, 2024
1 parent 3e96b8b commit bd53c2e
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 38 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: build clean docs-html docs-release flake8 release-webpage isort-check \
isort-reformat pytest reformat release check test
.PHONY: build clean docs-html docs-release flake8 pydoctsyle release-webpage \
isort-check isort-reformat pytest reformat release check test

build:
python3.9 setup.py sdist
Expand All @@ -24,6 +24,11 @@ flake_exclude = --exclude=./sandbox.py,./docs/conf.py
flake8:
python3.9 -m flake8 ${flake_ignore} ${flake_exclude}

pydocstyle_select = --select=D101,D102,D103,D105,D107

pydoctsyle:
python3.9 -m pydocstyle ${pydocstyle_select}

release-webpage:
rm -Rf auxjad-docs/
git clone https://github.com/gilbertohasnofb/auxjad-docs auxjad-docs
Expand Down Expand Up @@ -83,5 +88,6 @@ check:

test:
make flake8
make pydoctsyle
make isort-check
make pytest
8 changes: 5 additions & 3 deletions auxjad/core/Echoer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,8 @@ def _soften_dynamic(item: Union[int, None],
return item

@staticmethod
def _convert_pitched_logical_tie_to_rest(logical_tie) -> None:
def _convert_pitched_logical_tie_to_rest(logical_tie: abjad.LogicalTie,
) -> None:
r'Converts all leaves of a pitched logical tie into rests.'
indicators_tuple = (abjad.BarLine,
abjad.Clef,
Expand Down Expand Up @@ -1735,7 +1736,8 @@ def _convert_pitched_logical_tie_to_rest(logical_tie) -> None:
abjad.mutate.replace(leaf, rest)

@staticmethod
def _remove_all_time_signatures(container) -> None:
def _remove_all_time_signatures(container: abjad.Container,
) -> None:
r'Removes all time signatures of an |abjad.Container|.'
for leaf in abjad.select(container).leaves():
if abjad.get.effective(leaf, abjad.TimeSignature):
Expand Down Expand Up @@ -1783,7 +1785,7 @@ def current_window(self) -> abjad.Selection:
return current_window

@property
def min_dynamic(self) -> Union[abjad.Dynamic, str]:
def min_dynamic(self) -> str:
r'The minimum dynamic below which notes are removed.'
return self._min_dynamic

Expand Down
6 changes: 4 additions & 2 deletions auxjad/core/Fader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,8 @@ def _get_lilypond_format(self) -> str:
return self.__repr__()

@staticmethod
def _convert_pitched_logical_tie_to_rest(logical_tie) -> None:
def _convert_pitched_logical_tie_to_rest(logical_tie: abjad.LogicalTie,
) -> None:
r'Converts all leaves of a pitched logical tie into rests.'
indicators_tuple = (abjad.BarLine,
abjad.Clef,
Expand Down Expand Up @@ -1708,7 +1709,8 @@ def _convert_pitched_logical_tie_to_rest(logical_tie) -> None:
abjad.mutate.replace(leaf, rest)

@staticmethod
def _remove_all_time_signatures(container) -> None:
def _remove_all_time_signatures(container: abjad.Container,
) -> None:
r'Removes all time signatures of an |abjad.Container|.'
for leaf in abjad.select(container).leaves():
if abjad.get.effective(leaf, abjad.TimeSignature):
Expand Down
4 changes: 3 additions & 1 deletion auxjad/core/Hocketer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,7 @@ def _get_pitch_from_logical_tie(logical_tie: abjad.LogicalTie,
abjad.PitchSegment,
None,
]:
r'Gets the pitch of the first leaf of a logical tie.'
if isinstance(logical_tie.head, abjad.Note):
return logical_tie.head.written_pitch
elif isinstance(logical_tie.head, abjad.Chord):
Expand All @@ -1637,7 +1638,8 @@ def _get_pitch_from_logical_tie(logical_tie: abjad.LogicalTie,
return None

@staticmethod
def _remove_all_time_signatures(container) -> None:
def _remove_all_time_signatures(container: abjad.Container,
) -> None:
r'Removes all time signatures of an |abjad.Container|.'
for leaf in abjad.select(container).leaves():
if abjad.get.effective(leaf, abjad.TimeSignature):
Expand Down
15 changes: 9 additions & 6 deletions auxjad/core/Phaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,8 +1498,8 @@ def _get_lilypond_format(self) -> str:
return self.__repr__()

@staticmethod
def _tie_identical_pitches(currrent_selection,
previous_container,
def _tie_identical_pitches(currrent_selection: abjad.Selection,
previous_container: abjad.Container,
) -> None:
r'Ties identical pitches when joining windows.'
if len(previous_container) == 0:
Expand All @@ -1511,12 +1511,15 @@ def _tie_identical_pitches(currrent_selection,
abjad.attach(abjad.Tie(), last_leaf)

@staticmethod
def _biased_choice(bias) -> None:
r'Returns either +1 or -1 according to a bias value.'
return random.choices([1, -1], weights=[bias, 1.0 - bias])[0]
def _biased_choice(forward_bias: float,
) -> None:
r'Returns either +1 or -1 according to a forward bias value.'
weights = [forward_bias, 1.0 - forward_bias]
return random.choices([1, -1], weights=weights)[0]

@staticmethod
def _remove_all_time_signatures(container) -> None:
def _remove_all_time_signatures(container: abjad.Container,
) -> None:
r'Removes all time signatures of an |abjad.Container|.'
for leaf in abjad.select(container).leaves():
if abjad.get.effective(leaf, abjad.TimeSignature):
Expand Down
3 changes: 2 additions & 1 deletion auxjad/core/PitchRandomiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,8 @@ def _pick_random_pitch(self) -> abjad.Pitch:
return self._tenney_selector()

@staticmethod
def _remove_all_time_signatures(container) -> None:
def _remove_all_time_signatures(container: abjad.Container,
) -> None:
r'Removes all time signatures of an |abjad.Container|.'
for leaf in abjad.select(container).leaves():
if abjad.get.effective(leaf, abjad.TimeSignature):
Expand Down
3 changes: 2 additions & 1 deletion auxjad/core/Repeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,8 @@ def _get_lilypond_format(self) -> str:
return self.__repr__()

@staticmethod
def _remove_all_time_signatures(container) -> None:
def _remove_all_time_signatures(container: abjad.Container,
) -> None:
r'Removes all time signatures of an |abjad.Container|.'
for leaf in abjad.select(container).leaves():
if abjad.get.effective(leaf, abjad.TimeSignature):
Expand Down
9 changes: 7 additions & 2 deletions auxjad/core/Shuffler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,14 +1449,19 @@ def _get_lilypond_format(self) -> str:
return self.__repr__()

@staticmethod
def _remove_all_time_signatures(container) -> None:
def _remove_all_time_signatures(container: abjad.Container,
) -> None:
r'Removes all time signatures of an |abjad.Container|.'
for leaf in abjad.select(container).leaves():
if abjad.get.effective(leaf, abjad.TimeSignature):
abjad.detach(abjad.TimeSignature, leaf)

@staticmethod
def _force_dynamics(container) -> None:
def _force_dynamics(container: abjad.Container,
) -> None:
r"""Enforces the current dynamic level to every logical tie without a
dynamic marking.
"""
logical_ties = abjad.select(container).logical_ties()
for logical_tie in logical_ties[1:]:
if abjad.get.indicator(logical_tie[0], abjad.Dynamic) is None:
Expand Down
3 changes: 2 additions & 1 deletion auxjad/core/WindowLooper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,8 @@ def __repr__(self) -> str:

def __len__(self) -> int:
r"""Returns the length of :attr:`contents` in terms of
:attr:`step_size`."""
:attr:`step_size`.
"""
return ceil(self._contents_length / self._step_size)

def __call__(self) -> abjad.Selection:
Expand Down
27 changes: 15 additions & 12 deletions auxjad/core/_LooperParent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from typing import Union
from typing import Any, Union

import abjad

Expand Down Expand Up @@ -30,13 +30,13 @@ class _LooperParent():

def __init__(self,
*,
head_position,
window_size,
step_size,
max_steps,
repetition_chance,
forward_bias,
process_on_first_call,
head_position: Any,
window_size: Any,
step_size: Any,
max_steps: int = 1,
repetition_chance: float = 0.0,
forward_bias: float = 1.0,
process_on_first_call: bool = False,
) -> None:
r'Initialises self.'
if not isinstance(process_on_first_call, bool):
Expand Down Expand Up @@ -161,12 +161,15 @@ def _slice_contents(self) -> None:
pass

@staticmethod
def _biased_choice(bias) -> None:
r'Returns either +1 or -1 according to a bias value.'
return random.choices([1, -1], weights=[bias, 1.0 - bias])[0]
def _biased_choice(forward_bias: float,
) -> None:
r'Returns either +1 or -1 according to a forward bias value.'
weights = [forward_bias, 1.0 - forward_bias]
return random.choices([1, -1], weights=weights)[0]

@staticmethod
def _remove_all_time_signatures(container) -> None:
def _remove_all_time_signatures(container: abjad.Container,
) -> None:
r'Removes all time signatures of an |abjad.Container|.'
for leaf in abjad.select(container).leaves():
if abjad.get.effective(leaf, abjad.TimeSignature):
Expand Down
9 changes: 6 additions & 3 deletions auxjad/makers/GeneticAlgorithmMusicMaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,8 @@ class GeneticAlgorithmMusicMaker():
None
>>> maker.fittest_individual_score
None
"""
"""

### CLASS VARIABLES ###

__slots__ = ('_pitch_target',
Expand Down Expand Up @@ -1226,7 +1227,8 @@ def units_per_window(self,
@property
def omit_time_signature(self) -> bool:
r"""When ``True``, a time signature won't be added to the first leaf of
the output."""
the output.
"""
return self._omit_time_signature

@omit_time_signature.setter
Expand Down Expand Up @@ -1264,7 +1266,8 @@ def time_signatures(self,
@property
def attack_points_mode(self) -> bool:
r"""When ``True``, each note will last only for the duration of the
unit, instead of extending it to the next attack point."""
unit, instead of extending it to the next attack point.
"""
return self._attack_points_mode

@attack_points_mode.setter
Expand Down
3 changes: 2 additions & 1 deletion auxjad/makers/LeafDynMaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ def _add_dynamics_and_articulations(self,
abjad.attach(articulation, logical_tie.head)

@staticmethod
def _listify(argument) -> list[Any]:
def _listify(argument: Any,
) -> list[Any]:
r'Returns a :obj:`list` if argument is not a :obj:`list`.'
if argument:
if isinstance(argument, list):
Expand Down
6 changes: 4 additions & 2 deletions auxjad/score/Score.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,11 @@ def add_double_bar_lines_before_time_signatures(
self._double_bar_line_adder(voice)

@staticmethod
def _double_bar_line_adder(container: abjad.Container) -> None:
def _double_bar_line_adder(container: abjad.Container,
) -> None:
r"""Goes through a container and adds double bar lines before each and
every time signature change."""
every time signature change.
"""
leaves = abjad.select(container).leaves()
for i, leaf in enumerate(leaves[1:], 1):
time_signature = abjad.get.indicator(leaf, abjad.TimeSignature)
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,13 @@ class HiddenDoctestDirective(Directive):
### PUBLIC METHODS ###

def run(self):
'Executes the directive.'
r'Executes the directive.'
self.assert_has_content()
return []


def setup(app):
r'Adds directives.'
app.add_directive('docs', HiddenDoctestDirective)
# replacing abjad's todo custom directive with a regular warning
app.add_directive('todo', directives.admonitions.Warning)

0 comments on commit bd53c2e

Please sign in to comment.