Skip to content

Commit

Permalink
some more lint errors fixing
Browse files Browse the repository at this point in the history
- also fixes formatted strings syntax errors introduced in my last commit
  • Loading branch information
g-raffy committed Nov 9, 2023
1 parent 5d660aa commit bf933e8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
17 changes: 9 additions & 8 deletions src/pymusco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import abc
import json
import re
from pathlib import Path
import PyPDF2 # sudo port install py27-pypdf2
from PIL import Image

Expand All @@ -19,13 +20,13 @@ def dict_raise_on_duplicates(ordered_pairs):
d = {}
for k, v in ordered_pairs:
if k in d:
raise ValueError(f"duplicate key: {k:%r}")
raise ValueError(f"duplicate key: {k!r}")
else:
d[k] = v
return d


def load_commented_json(commented_json_file_path):
def load_commented_json(commented_json_file_path: Path):
uncommented_json_contents = ''
with open(commented_json_file_path, 'rt', encoding='utf-8') as file:

Expand Down Expand Up @@ -211,7 +212,7 @@ def get_instrument(self, instrument_id):
raise InstrumentNotFound(instrument_id)


def load_orchestra(orchestra_file_path):
def load_orchestra(orchestra_file_path: Path):
"""
Parameters
Expand Down Expand Up @@ -302,13 +303,13 @@ def get_id(self):
"""
uid = self.instrument.get_id()
if self.is_solo:
uid = f'{uid:%s} solo'
uid = f'{uid:s} solo'
if self.voice is not None:
uid = f'{uid:%s} {self.voice:%d}'
uid = f'{uid:s} {self.voice:d}'
if self.clef is not None:
uid = f'{uid:%s} {self.clef:%s}'
uid = f'{uid:s} {self.clef:s}'
if self.is_disabled:
uid = f'{uid:%s} disabled'
uid = f'{uid:s} disabled'
return uid

def __lt__(self, other):
Expand Down Expand Up @@ -371,7 +372,7 @@ def __init__(self, orchestra, track_id_to_page=None):
self.track_to_page[track] = page

def __repr__(self):
return "{%s}" % ', '.join([f"{str(key)}: {value:%d}" for key, value in self.track_to_page.items()])
return "{%s}" % ', '.join([f"{str(key)}: {value:d}" for key, value in self.track_to_page.items()])

def __str__(self):
return "[%s]" % ', '.join([f'"{str(key)}"' for key in self.track_to_page.keys()]) # pylint: disable=consider-iterating-dictionary, consider-using-f-string
Expand Down
22 changes: 13 additions & 9 deletions src/pymusco/piece.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from .main import stub_to_print
from .core import TableOfContents
from .core import load_commented_json
from .core import Orchestra
from .tssingle import SingleTrackSelector


def dict_to_toc(toc_as_dict, orchestra):
"""
Parameters
Expand All @@ -20,7 +20,7 @@ def dict_to_toc(toc_as_dict, orchestra):
# check that the keys used in this dictionary are known
for key in toc_as_dict.keys():
if key not in ['format', 'track_id_to_page']:
raise KeyError('unexpected key in toc dictionary : %s' % (key))
raise KeyError(f'unexpected key in toc dictionary : {key:s}')

toc = TableOfContents(orchestra=orchestra, track_id_to_page=None)
for track_id, page_index in toc_as_dict['track_id_to_page'].items():
Expand All @@ -44,8 +44,6 @@ def toc_to_dict(toc):


def dict_to_stamp_desc(stamp_desc_as_dict, piece_desc_file_path):
"""
"""
abs_stamp_file_path = None
stamp_file_path = Path(stamp_desc_as_dict['stamp_image_path'])
allowed_image_suffixes = ['.pdf', '.png']
Expand All @@ -54,9 +52,9 @@ def dict_to_stamp_desc(stamp_desc_as_dict, piece_desc_file_path):
else:
abs_stamp_file_path = piece_desc_file_path.parent.resolve() / stamp_file_path
if not abs_stamp_file_path.exists():
raise FileNotFoundError("The stamp file '%s' is missing (file not found)." % (abs_stamp_file_path))
raise FileNotFoundError(f"The stamp file '{abs_stamp_file_path:s}' is missing (file not found).")
if abs_stamp_file_path.suffix not in allowed_image_suffixes:
raise TypeError("Unsupported image format for stamp '%s' (allowed formats : %s) " % (abs_stamp_file_path, str(allowed_image_suffixes)))
raise TypeError(f"Unsupported image format for stamp '{abs_stamp_file_path}' (allowed formats : {str(allowed_image_suffixes)}) ")
return StampDesc(file_path=abs_stamp_file_path,
scale=stamp_desc_as_dict['scale'],
tx=stamp_desc_as_dict['tx'],
Expand Down Expand Up @@ -107,7 +105,7 @@ def piece_to_dict(piece):
return piece_as_dict


def load_piece_description(piece_desc_file_path, orchestra):
def load_piece_description(piece_desc_file_path: Path, orchestra):
"""
Parameters
Expand Down Expand Up @@ -172,7 +170,7 @@ def __init__(self, uid, title, orchestra, scan_toc, missing_tracks=None, stamp_d

@property
def label(self):
return '%03d-%s' % (self.uid, self.title.replace(' ', '-'))
return f"{self.uid:03d}-{self.title.replace(' ', '-')}"

# def get_stub_toc(self):
# """
Expand Down Expand Up @@ -248,7 +246,13 @@ def build_all(self, musician_count):
class Catalog(object):
""" a collection of pieces that share the same locations, same orchestra, etc...
"""
def __init__(self, piece_desc_dir, scans_dir, stubs_dir, prints_dir, orchestra):
piece_desc_dir: Path
scans_dir: Path
stubs_dir: Path
prints_dir: Path
orchestra: Orchestra

def __init__(self, piece_desc_dir: Path, scans_dir: Path, stubs_dir: Path, prints_dir: Path, orchestra: Orchestra):
"""
Parammeters
-----------
Expand Down
3 changes: 2 additions & 1 deletion src/pymusco/tsauto.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
@author: graffy
'''

from pathlib import Path
from .core import ITrackSelector
from .core import Track
from .core import load_commented_json


def load_musician_count(musician_count_file_path):
def load_musician_count(musician_count_file_path: Path):
return load_commented_json(musician_count_file_path)


Expand Down

0 comments on commit bf933e8

Please sign in to comment.