Skip to content

Commit

Permalink
fixed linting errors
Browse files Browse the repository at this point in the history
- unfortunately pylance requires a modification in the workspace settings python.analysis.extraPaths to work on app/pymusco, and this settings is not included in the repository
  • Loading branch information
g-raffy committed Nov 8, 2023
1 parent 0ae55f8 commit db84234
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"--disable=C0114",
"--disable=C0115",
"--disable=C0116",
"--generated-members=cv2.*"
"--disable=W0406", // false positive when importing pymusco module from pymusco app
"--generated-members=cv2.*",
],
"flake8.args": [
"--per-file-ignores=\"__init__.py:F401\""
"--per-file-ignores=\"__init__.py:F401\"",
]
}
11 changes: 6 additions & 5 deletions src/apps/pymusco
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/usr/bin/env python3
import argparse
import sys
from pathlib import Path
from pymusco import Piece, load_piece_description
from pymusco import load_piece_description
from pymusco import load_orchestra
from pymusco import load_musician_count
from pymusco import AutoTrackSelector
from pymusco import SingleTrackSelector
from pymusco import scan_to_stub
from pymusco import stub_to_print
from pymusco import StampDesc


RED = "\033[1;31m" # noqa:E221
Expand All @@ -20,7 +18,7 @@ RESET = "\033[0;0m" # noqa:E221
BOLD = "\033[;1m" # noqa:E221
REVERSE = "\033[;7m" # noqa:E221

if __name__ == '__main__':
def main():
parser = argparse.ArgumentParser(description='python musical score sheet music processor')
subparsers = parser.add_subparsers()
subparsers.required = True
Expand Down Expand Up @@ -69,7 +67,7 @@ if __name__ == '__main__':
stamp_descs=piece.stamp_descs,
page_info_line_y_pos=piece.page_info_line_y_pos)
except Exception as e:
print(RED, "failed to process %s (%s)" % (scan_desc_file_path, str(e)), RESET)
print(RED, f"failed to process {scan_desc_file_path} ({str(e)})", RESET)
# sys.exit(1)
raise

Expand All @@ -91,3 +89,6 @@ if __name__ == '__main__':
print(RED, str(e), RESET)
# sys.exit(1)
raise

if __name__ == '__main__':
main()
5 changes: 3 additions & 2 deletions src/pymusco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ def find_page_number(page_contents_id: int, pdf_reader: PyPDF2.PdfReader):
:param PyPDF2.PdfReader pdf_reader: the input pdf file
"""
# print('looking for page with id %d' % page_contents_id)
for page_index in range(len(pdf_reader.pages)):
page_object = pdf_reader.pages[page_index]
page_index = 0
for page_object in pdf_reader.pages:
assert isinstance(page_object, PyPDF2._page.PageObject) # pylint: disable=protected-access
# at this point, a page_object of the table of contents (with 23 links) looks like :
# {'/Contents': IndirectObject(196, 0), '/Parent': IndirectObject(203, 0), '/Type': '/Page', '/Resources': IndirectObject(195, 0), '/MediaBox': [0, 0, 612, 792], '/Annots': [IndirectObject(171, 0), IndirectObject(172, 0), IndirectObject(173, 0), IndirectObject(174, 0), IndirectObject(175, 0), IndirectObject(176, 0), IndirectObject(177, 0), IndirectObject(178, 0), IndirectObject(179, 0), IndirectObject(180, 0), IndirectObject(181, 0), IndirectObject(182, 0), IndirectObject(183, 0), IndirectObject(184, 0), IndirectObject(185, 0), IndirectObject(186, 0), IndirectObject(187, 0), IndirectObject(188, 0), IndirectObject(189, 0), IndirectObject(190, 0), IndirectObject(191, 0), IndirectObject(192, 0), IndirectObject(193, 0)]}
Expand All @@ -535,6 +535,7 @@ def find_page_number(page_contents_id: int, pdf_reader: PyPDF2.PdfReader):

if page_contents_indirect_obj.idnum == page_contents_id:
return page_index + 1 # converts 0 based index to 1-based index
page_index += 1

assert False, "failed to find in the given input pdf file, a page whose contents id is %s" % page_contents_id

Expand Down
16 changes: 8 additions & 8 deletions src/pymusco/tsauto.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_track_to_copy(self, stub_tracks):
"""
track_to_print_count = {}
for musician_type_id, num_musicians in self.musician_count.items():
print('musician_type_id = %s' % musician_type_id)
print(f'musician_type_id = {musician_type_id}')
# collect the tracks than can be played by these musicians
playable_tracks = []
dispatch_tracks_between_musicians = True
Expand All @@ -59,7 +59,7 @@ def get_track_to_copy(self, stub_tracks):
# print('processing enabled track %s' % track.get_id())

if track.instrument.get_player() == musician_type_id:
print('this is a track for %s' % musician_type_id)
print(f'this is a track for {musician_type_id}')
print('track.instrument', track.instrument.get_id())
if not track.is_rare:
if musician_type_id == 'percussionist':
Expand All @@ -68,25 +68,25 @@ def get_track_to_copy(self, stub_tracks):
track_to_print_count[track.get_id()] = num_musicians + 1
elif track.is_solo:
# solos are always wanted even if the orchestra doesn't have its player
print("info: 2 copies for solo track %s" % track.get_id())
print(f"info: 2 copies for solo track {track.get_id()}")
track_to_print_count[track.get_id()] = 2
elif track.instrument.is_single():
# only print twice for tracks such as 'bb bass clarinet' or 'c piccolo', as they're not supposed to be more than one in an orchestra (one fore the player + 1 extra)
print("info: 2 copies for single instrument %s" % track.get_id())
print(f"info: 2 copies for single instrument {track.get_id()}")
track_to_print_count[track.get_id()] = 2
else:
playable_tracks.append(track)
if dispatch_tracks_between_musicians:
if len(playable_tracks) == 0:
print("warning: no playable tracks found to dispatch for player type %s" % musician_type_id)
print(f"warning: no playable tracks found to dispatch for player type {musician_type_id}")
else:
num_musicians_per_track = num_musicians // len(playable_tracks) + 1
for track in playable_tracks:
print("info: %d copies of %s" % (num_musicians_per_track, track.get_id()))
print(f"info: {num_musicians_per_track} copies of {track.get_id()}")
track_to_print_count[track.get_id()] = num_musicians_per_track
if self.include_tracks_for_external_players:
for track_id in stub_tracks:
if track_id not in track_to_print_count.keys():
if track_id not in track_to_print_count.keys(): # pylint: disable=consider-iterating-dictionary
track = Track(track_id, self.orchestra)
if not track.is_disabled:
count = 0
Expand All @@ -99,7 +99,7 @@ def get_track_to_copy(self, stub_tracks):
if track.instrument.is_single():
if track.get_id() not in track_to_print_count:
# force adding single instrument tracks such as harp or piano even if there's no player in the orchestra because these parts are often played by external musicians
print("info: 2 copies for single instrument %s" % track.get_id())
print(f"info: 2 copies for single instrument {track.get_id()}")
track_to_print_count[track.get_id()] = 2

track_to_print_count[track_id] = count
Expand Down
2 changes: 1 addition & 1 deletion src/pymusco/tssingle.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ def __init__(self, selected_track_id, orchestra):
self.orchestra = orchestra

def get_track_to_copy(self, stub_tracks):
assert self.selected_track.get_id() in stub_tracks, "how can I select a track that is not in the stub : %s" % self.selected_track.get_id()
assert self.selected_track.get_id() in stub_tracks, f"how can I select a track that is not in the stub : {self.selected_track.get_id()}"
track_to_print_count = {self.selected_track.get_id(): 1}
return track_to_print_count

0 comments on commit db84234

Please sign in to comment.