Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Data folders
input/
output/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion bpm_novariant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from os.path import join, splitext, dirname, realpath
import shutil

def get_folders_to_delete():
def get_folders_to_delete() -> list[str]:
to_delete = []
dir_path = dirname(realpath(__file__))
print(dir_path)
Expand Down
4 changes: 2 additions & 2 deletions smdatatools/common/cli_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def read_TXTtoData(filepath: str) -> DataHandler:
data.note_data = InputProcessor.parse_txt_input(istr)
return data

def write_DatatoSM(data: DataHandler, filepath: str):
def write_DatatoSM(data: DataHandler, filepath: str) -> None:
filename = strip_filename(filepath)
ostr = OutputProcessor.pregenerate_sm_output(filename, data.processed_data)
write_file(ostr, filepath)

def write_DatatoTXT(data: DataHandler, filepath: str):
def write_DatatoTXT(data: DataHandler, filepath: str) -> None:
ostr = OutputProcessor.pregenerate_txt_output(data.note_data)
write_file(ostr, filepath)
12 changes: 6 additions & 6 deletions smdatatools/common/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
from os.path import join, split, splitext
from re import sub

def read_file(filename):
def read_file(filename: str) -> list[str]:
file_data = []
with open(filename, encoding='ascii', errors='ignore') as f:
file_data = f.read().splitlines()
return file_data

def write_file(output_data, filename):
def write_file(output_data: str, filename: str) -> None:
with open(filename, 'w') as f:
f.write(output_data)

def strip_filename(filename):
def strip_filename(filename: str) -> str:
'''
Strips file path
Strips file extension
Expand All @@ -23,7 +23,7 @@ def strip_filename(filename):
tail = splitext(tail)[0]
return sub(' ', '_', sub('[^a-z0-9-_ ]', '', tail.lower()))

def collect_filenames(input_dir: str, extensions: list):
def collect_filenames(input_dir: str, extensions: list[str]) -> list[str]:
filenames = []
for root, dirs, files in walk(input_dir):
for filename in files:
Expand All @@ -32,15 +32,15 @@ def collect_filenames(input_dir: str, extensions: list):
filenames.append(join(root, filename).replace("\\","/"))
return filenames

def getFilePaths(input_dir: list, extensions: list):
def getFilePaths(input_dir: list[str], extensions: list[str]) -> list[str]:
filepaths = collect_filenames(input_dir, extensions)

if '.sm' in extensions:
checkFilePaths(filepaths)

return filepaths

def checkFilePaths(sm_filepaths):
def checkFilePaths(sm_filepaths: list[str]) -> None:
# checks for static bpm in the .sm file
# and removes filepath from list if not
for sm_file in sm_filepaths:
Expand Down
8 changes: 4 additions & 4 deletions smdatatools/components/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Measure:

def calculate_timing(measure, measure_index, bpm, offset):
def calculate_timing(measure: list[str], measure_index: int, bpm: float, offset: float) -> str:
# calculate time in seconds for each line in the measure:
# BPM = beats/minute -> BPS = beats/second = BPM/60
# measure = 4 beats = 4 * 1/4th notes = 1 note
Expand All @@ -30,7 +30,7 @@ def find_gcd(note_positions) -> int:

return int(gcd_gap)

def generate_measure(notes, note_positions) -> list[str]:
def generate_measure(notes: list[str], note_positions: list[int]) -> list[str]:

# we'll want to trim as much output as possible
# by reducing the measure size
Expand All @@ -46,7 +46,7 @@ def generate_measure(notes, note_positions) -> list[str]:

return generated_measure

def fit_notes_to_measure(notes, timings, seconds_1_256) -> list[str]:
def fit_notes_to_measure(notes: list[str], timings: list[float], seconds_1_256: float) -> list[str]:
# if no data is passed, generate current measure
# as "empty" with the smallest size
if not notes or not timings:
Expand Down Expand Up @@ -78,7 +78,7 @@ def fit_notes_to_measure(notes, timings, seconds_1_256) -> list[str]:

return measure

def place_notes(notes_and_timings, bpm) -> list:
def place_notes(notes_and_timings: list[str], bpm: float) -> list[str]:
placed_notes = []
if not notes_and_timings:
return placed_notes
Expand Down
2 changes: 1 addition & 1 deletion smdatatools/data_processing/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, filepath):
self.processed_data = defaultdict(list)
self.valid = True

def process_data_to_sm_format(self):
def process_data_to_sm_format(self) -> None:

self.processed_data['title'] = self.note_data['title']
self.processed_data['bpm'] = float(self.note_data['bpm'])
Expand Down
6 changes: 3 additions & 3 deletions smdatatools/data_processing/input_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

class InputProcessor:

def convert_note(line):
def convert_note(line: str) -> str:
return sub('4', '1', sub('[MKLF]', '0', line)) #replaces extra notes: M, K, L, F; replaces 4 note

def parse_sm_input(sm_file):
def parse_sm_input(sm_file: list[str]) -> tuple[dict[str, dict[str or list[str]] or float or int ], bool]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check my commit message. For Python version <3.10, I have to use OR instead of a Union operator. If you can test it from your end with a Python version 3.10+ and it still works then there shouldn't be any problem.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then Union[x, y, z] from typing should be used instead. As is, I don't think this PR passes pytype checks.

IMO the code base can be upgraded to Python 3.10+. 3.10 has been out for 2 years and it's worth using more modern features.

note_data = defaultdict(list)
note_data['notes'] = defaultdict(list) # notes are paired with each difficulty
current_difficulty = ''
Expand Down Expand Up @@ -75,7 +75,7 @@ def parse_sm_input(sm_file):

return note_data, valid

def parse_txt_input(txt_file):
def parse_txt_input(txt_file: list[str]) -> dict[str, dict[str or list[str]] or float or int ]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typing uses the Union operator |

https://peps.python.org/pep-0604/

note_data = defaultdict(list)
note_data['notes'] = defaultdict(list)
current_difficulty = ''
Expand Down