From 469092002b7f1e1657468941bd86ccd3738baac3 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 1 Dec 2022 09:36:18 +0100 Subject: Added pre-commit --- aoc/__init__.py | 14 ++++++++------ aoc/__main__.py | 32 +++++++++++++++++++------------- aoc/test_init.py | 6 +++++- aoc/utils.py | 3 ++- 4 files changed, 34 insertions(+), 21 deletions(-) (limited to 'aoc') diff --git a/aoc/__init__.py b/aoc/__init__.py index b13489c..5fce415 100644 --- a/aoc/__init__.py +++ b/aoc/__init__.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import os from abc import ABC from typing import Generator, Any, Iterator @@ -5,23 +6,24 @@ from typing import Generator, Any, Iterator class BaseAssignment(ABC): example_result = NotImplemented + def __init__(self, path): self.path = path def __str__(self): - return f'{self.__module__}.{self.__class__.__name__}' + return f"{self.__module__}.{self.__class__.__name__}" def parse_item(self, item: str) -> Any: return item - def read_input(self, example = False) -> Generator: - file = f'{self.path}/input.txt' + def read_input(self, example=False) -> Generator: + file = f"{self.path}/input.txt" if example or not os.path.isfile(file): - file = f'{self.path}/example.txt' + file = f"{self.path}/example.txt" - with open(file, 'r') as input_file: + with open(file, "r") as input_file: for line in input_file.readlines(): yield self.parse_item(line.strip()) def run(self, input: Iterator) -> Any: - raise NotImplementedError('Please implement run') \ No newline at end of file + raise NotImplementedError("Please implement run") diff --git a/aoc/__main__.py b/aoc/__main__.py index 25a7026..337bdfe 100644 --- a/aoc/__main__.py +++ b/aoc/__main__.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import argparse import importlib import os @@ -7,32 +8,37 @@ from typing import List def day(assignment_part: str) -> str: return { - '1': 'One', - '2': 'Two', + "1": "One", + "2": "Two", }[assignment_part] + def kwargs(kwarg: str) -> List: - return kwarg.split('=') + return kwarg.split("=") + -parser = argparse.ArgumentParser(description='Advent of Code') +parser = argparse.ArgumentParser(description="Advent of Code") -parser.add_argument('day', type=str, help='Assignment day') +parser.add_argument("day", type=str, help="Assignment day") parser.add_argument( - '-p', '--part', type=day, nargs='?', default='1', - help='Assingment part. Defaults to one.' + "-p", + "--part", + type=day, + nargs="?", + default="1", + help="Assingment part. Defaults to one.", ) -parser.add_argument('--example', default=False, action='store_true') -parser.add_argument('kwargs', type=kwargs, nargs='*') +parser.add_argument("--example", default=False, action="store_true") +parser.add_argument("kwargs", type=kwargs, nargs="*") -if __name__ == '__main__': +if __name__ == "__main__": args = parser.parse_args() assignment_day = importlib.import_module(args.day) - Assignment = getattr(assignment_day, f'Assignment{args.part}') + Assignment = getattr(assignment_day, f"Assignment{args.part}") assignment = Assignment( - path=os.path.dirname(assignment_day.__file__), - **dict(args.kwargs) + path=os.path.dirname(assignment_day.__file__), **dict(args.kwargs) ) start = perf_counter() diff --git a/aoc/test_init.py b/aoc/test_init.py index a9155cc..f804c41 100644 --- a/aoc/test_init.py +++ b/aoc/test_init.py @@ -1,2 +1,6 @@ +# -*- coding: utf-8 -*- def test_assignment_examples(assignment): - assert assignment.run(input=assignment.read_input(example=True)) == assignment.example_result + assert ( + assignment.run(input=assignment.read_input(example=True)) + == assignment.example_result + ) diff --git a/aoc/utils.py b/aoc/utils.py index 6d794f4..a5de050 100644 --- a/aoc/utils.py +++ b/aoc/utils.py @@ -1,5 +1,6 @@ +# -*- coding: utf-8 -*- from typing import Callable def bold(item: str, condition: Callable[[], bool]): - return f'\033[36m{item}\033[0m' if condition() else item + return f"\033[36m{item}\033[0m" if condition() else item -- cgit v1.2.3