diff --git a/Taskfile.yml b/Taskfile.yml index 2b5f0b6..fe982d0 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -2,7 +2,6 @@ version: "3" vars: RUN_DEBUGPY: '/tmp/debugpy --listen 0.0.0.0:5673 --wait-for-client' - SH_ENTRYPOINT: '/bin/sh' tasks: # ------------------------------------------------------------------------------------------------ @@ -30,14 +29,15 @@ tasks: desc: ups main app (USE_DEBUGPY=true for debug) env: BASE_COMMAND: '{{if eq .USE_DEBUGPY "true"}}{{.RUN_DEBUGPY}} -m app.main{{else}}{{end}}' + BASE_ARGS: '{{.CLI_ARGS}}' cmd: docker-compose -f docker-compose.yml up up-test: desc: ups coverage and unit-testing (USE_DEBUGPY=true for unit-testing only) env: - BASE_ENTRYPOINT: '{{.SH_ENTRYPOINT}}' + BASE_ENTRYPOINT: '/bin/sh' BASE_COMMAND: '{{if eq .USE_DEBUGPY "true"}}-c "python {{.RUN_DEBUGPY}} -m pytest"{{else}}-c "coverage run -m pytest && coverage report && coverage html"{{end}}' - cmd: docker-compose -f docker-compose.yml -f docker-compose.test.yml up + cmd: docker-compose -f docker-compose.yml up # ------------------------------------------------------------------------------------------------ # -Pre-Commit------------------------------------------------------------------------------------- diff --git a/app/data.py b/app/data.py index 0fd3a99..2306f9e 100644 --- a/app/data.py +++ b/app/data.py @@ -13,11 +13,15 @@ class Data: array (list): An array of integers. """ - def __init__(self): + def __init__(self, integer_array=None): """ - Initializes the Data object with a predefined array of integers. + Initializes the Data object with a predefined array of integers + or an empty array if none is provided. """ - self.__integer_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + if integer_array is None: + self.__integer_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + else: + self.__integer_array = integer_array def print_array(self): """ diff --git a/app/input/integers.txt b/app/input/integers.txt new file mode 100644 index 0000000..db5114f --- /dev/null +++ b/app/input/integers.txt @@ -0,0 +1 @@ +1 2 3 4 5 6 7 8 9 10 diff --git a/app/main.py b/app/main.py index 28ed10e..d8d802d 100644 --- a/app/main.py +++ b/app/main.py @@ -3,19 +3,38 @@ and uses it to print an array of integers to the console. """ +import argparse + from app.data import Data -def main(): +def read_file(file_path): + """ + Reads a file and returns an array of integers. + """ + with open(file_path, "r", encoding="utf-8") as file: + return [int(x) for x in file.read().split()] + + +def main(file_path): """ Main function for creating a Data instance and printing the array. This function demonstrates the basic usage of the Data class by creating an instance, - initializing it with a predefined array of integers, and then printing this array. + initializing it with the contents of a file, and then printing this array. """ - data = Data() + integer_array = read_file(file_path) + data = Data(integer_array) data.print_array() if __name__ == "__main__": - main() + parser = argparse.ArgumentParser(description="Process a file containing integers.") + parser.add_argument( + "--file_path", + default="app/input/integers.txt", + type=str, + help="Path to the file containing integers", + ) + args = parser.parse_args() + main(args.file_path) diff --git a/docker-compose.yml b/docker-compose.yml index 7da9d4d..b2c527e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,4 +12,4 @@ services: volumes: - ./app:/pythonExercise1/app - ./tests:/pythonExercise1/tests - command: ${BASE_COMMAND} + command: ${BASE_COMMAND} ${BASE_ARGS}