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
6 changes: 3 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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-------------------------------------------------------------------------------------
Expand Down
10 changes: 7 additions & 3 deletions app/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
1 change: 1 addition & 0 deletions app/input/integers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 3 4 5 6 7 8 9 10
27 changes: 23 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ services:
volumes:
- ./app:/pythonExercise1/app
- ./tests:/pythonExercise1/tests
command: ${BASE_COMMAND}
command: ${BASE_COMMAND} ${BASE_ARGS}