Skip to content

Commit

Permalink
Merge pull request #1723 from cuthbertLab/up_with_jones
Browse files Browse the repository at this point in the history
Respond to Changing Dev systems; Pin Numpy to <2.0
  • Loading branch information
mscuthbert authored Sep 17, 2024
2 parents 204e9d0 + 5303e53 commit 2c346ec
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 53 deletions.
2 changes: 1 addition & 1 deletion music21/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def style(self) -> Style:
return self._style

@style.setter
def style(self, newStyle: Style|None):
def style(self, newStyle: Style):
self._style = newStyle

# convenience.
Expand Down
4 changes: 2 additions & 2 deletions music21/braille/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def chordToBraille(music21Chord, descending=True, showOctave=True):
music21Chord.editorial.brailleEnglish.append(f'{music21Chord} None')
return symbols['basic_exception']
chordTrans.append(brailleNote)
englishJoined = '\n'.join(initNote.editorial.brailleEnglish)
englishJoined = '\n'.join(initNote.editorial.get('brailleEnglish', []))
music21Chord.editorial.brailleEnglish.append(
f'{direction} Chord:\n{englishJoined}'
)
Expand Down Expand Up @@ -531,7 +531,7 @@ def metronomeMarkToBraille(music21MetronomeMark):
metroNote = note.Note('C4', quarterLength=music21MetronomeMark.referent.quarterLength)
brailleNote = noteToBraille(metroNote, showOctave=False)
metroTrans.append(brailleNote)
englishJoined = ' '.join(metroNote.editorial.brailleEnglish)
englishJoined = ' '.join(metroNote.editorial.get('brailleEnglish', []))
music21MetronomeMark.editorial.brailleEnglish.append(
f'Metronome Note {englishJoined}'
)
Expand Down
12 changes: 6 additions & 6 deletions music21/chord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

if t.TYPE_CHECKING:
from music21 import stream

from music21.style import Style

environLocal = environment.Environment('chord')

Expand Down Expand Up @@ -3684,7 +3684,7 @@ def removeRedundantPitches(self, *, inPlace=False):
note name in two different octaves is retained.
If `inPlace` is True, a copy is not made and a list of deleted pitches is returned;
otherwise a copy is made and that copy is returned.
otherwise make and return a copy.
>>> c1 = chord.Chord(['c2', 'e3', 'g4', 'e3'])
>>> c1
Expand Down Expand Up @@ -4194,10 +4194,10 @@ def setColor(self, value, pitchTarget=None):
'''
# assign to base
if pitchTarget is None and self._notes:
self.style.color = value
# Pylint going crazy here
self.style.color = value # pylint: disable=attribute-defined-outside-init
for n in self._notes:
n.style.color = value

n.style.color = value # pylint: disable=attribute-defined-outside-init
return
elif isinstance(pitchTarget, str):
pitchTarget = pitch.Pitch(pitchTarget)
Expand Down Expand Up @@ -4347,7 +4347,7 @@ def setNoteheadFill(self, nh, pitchTarget):
None
False
By default assigns to first pitch:
By default, assigns to first pitch:
>>> c3 = chord.Chord('C3 F4')
>>> c3.setNoteheadFill(False, None)
Expand Down
8 changes: 4 additions & 4 deletions music21/derivation.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ def chain(self) -> Generator[base.Music21Object, None, None]:
>>> list(s3.derivation.chain()) == [s2, s1]
True
'''
origin = self.origin
while origin is not None:
yield origin
origin = origin.derivation.origin
orig: base.Music21Object | None = self.origin
while orig is not None:
yield orig
orig = orig.derivation.origin # pylint: disable=no-member

@property
def method(self) -> str|None:
Expand Down
1 change: 0 additions & 1 deletion music21/meter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1840,4 +1840,3 @@ def offsetToDepth(self, qLenPos, align='quantize', index: int|None = None):
if __name__ == '__main__':
import music21
music21.mainTest()

5 changes: 4 additions & 1 deletion music21/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
from music21 import chord
from music21 import instrument
from music21 import percussion
from music21.style import Style

_NotRestType = t.TypeVar('_NotRestType', bound='NotRest')

environLocal = environment.Environment('note')
Expand Down Expand Up @@ -2095,7 +2097,8 @@ def testBasic(self):
b = note.Note()
b.quarterLength = qLen
b.name = pitchName
b.style.color = '#FF00FF'
# Pylint going crazy here
b.style.color = '#FF00FF' # pylint: disable=attribute-defined-outside-init
a.append(b)

if self.show:
Expand Down
9 changes: 6 additions & 3 deletions music21/stream/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7982,9 +7982,12 @@ def flatten(self: StreamType, retainContainers=False) -> StreamType:
newId = str(sOldId) + '_' + method
sNew.id = newId

sNew._derivation = derivation.Derivation(sNew)
sNew._derivation.origin = self
sNew.derivation.method = method
sNew_derivation = derivation.Derivation(sNew)
sNew_derivation.origin = self
sNew_derivation.method = method

sNew.derivation = sNew_derivation

# storing .elements in here necessitates
# create a new, independent cache instance in the flat representation
sNew._cache = {}
Expand Down
68 changes: 34 additions & 34 deletions music21/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,45 +102,25 @@ def __init__(self) -> None:
self.dashLength: float|int|None = None
self.spaceLength: float|int|None = None

def _getEnclosure(self) -> Enclosure|None:
return self._enclosure

def _setEnclosure(self, value: Enclosure|None):
if value is None:
self._enclosure = value
elif value == Enclosure.NONE:
self._enclosure = None
elif isinstance(value, Enclosure):
self._enclosure = value
elif isinstance(value, str):
try:
enc_value = Enclosure(value.lower())
except ValueError as ve:
raise TextFormatException(f'Not a supported enclosure: {value!r}') from ve

self._enclosure = enc_value

else:
raise TextFormatException(f'Not a supported enclosure: {value!r}')

enclosure = property(_getEnclosure,
_setEnclosure,
doc='''
@property
def enclosure(self) -> Enclosure|None:
'''
Get or set the enclosure as a style.Enclosure enum or None.
Valid names are
"rectangle"/style.Enclosure.RECTANGLE,
"square"/style.Enclosure.SQUARE,
"oval"/style.Enclosure.OVAL,
"circle"/style.Enclosure.CIRCLE,
"bracket"/style.Enclosure.BRACKET,
"inverted-bracket"/style.Enclosure.INVERTED_BRACKET (output in musicxml 4 only)
None/"none"/style.Enclosure.NONE (returns Python None object)
Valid names are:
* "rectangle"/style.Enclosure.RECTANGLE,
* "square"/style.Enclosure.SQUARE,
* "oval"/style.Enclosure.OVAL,
* "circle"/style.Enclosure.CIRCLE,
* "bracket"/style.Enclosure.BRACKET,
* "inverted-bracket"/style.Enclosure.INVERTED_BRACKET (output in musicxml 4 only)
* None/"none"/style.Enclosure.NONE (returns Python None object)
or the following other shapes with their ALLCAPS Enclosure equivalents:
triangle, diamond,
pentagon, hexagon, heptagon, octagon,
triangle, diamond, pentagon, hexagon, heptagon, octagon,
nonagon, or decagon.
>>> tst = style.TextStyle()
Expand Down Expand Up @@ -172,7 +152,27 @@ def _setEnclosure(self, value: Enclosure|None):
Traceback (most recent call last):
music21.style.TextFormatException:
Not a supported enclosure: 4
''')
'''
return self._enclosure

@enclosure.setter
def enclosure(self, value: Enclosure|None):
if value is None:
self._enclosure = value
elif value == Enclosure.NONE:
self._enclosure = None
elif isinstance(value, Enclosure):
self._enclosure = value
elif isinstance(value, str):
try:
enc_value = Enclosure(value.lower())
except ValueError as ve:
raise TextFormatException(f'Not a supported enclosure: {value!r}') from ve

self._enclosure = enc_value

else:
raise TextFormatException(f'Not a supported enclosure: {value!r}')

def _getAbsoluteY(self):
return self._absoluteY
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ joblib
jsonpickle
matplotlib
more_itertools
numpy
numpy<2.0.0
webcolors>=1.5
requests

0 comments on commit 2c346ec

Please sign in to comment.