diff --git a/src/pymusco/core.py b/src/pymusco/core.py index c3e774a..16c5ec7 100644 --- a/src/pymusco/core.py +++ b/src/pymusco/core.py @@ -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 @@ -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: @@ -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 @@ -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): @@ -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 diff --git a/src/pymusco/piece.py b/src/pymusco/piece.py index 8463207..9ffd95d 100644 --- a/src/pymusco/piece.py +++ b/src/pymusco/piece.py @@ -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 @@ -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(): @@ -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'] @@ -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'], @@ -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 @@ -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): # """ @@ -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 ----------- diff --git a/src/pymusco/tsauto.py b/src/pymusco/tsauto.py index 59a86d0..d2f0cbe 100644 --- a/src/pymusco/tsauto.py +++ b/src/pymusco/tsauto.py @@ -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)