From 9a851832af3f46be1aacc5534018264ac0803a9d Mon Sep 17 00:00:00 2001 From: Dheeraj-Nalapat Date: Tue, 1 Oct 2024 16:49:42 +0530 Subject: [PATCH 1/6] Add Decorators to repo --- decorators/__init__.py | 0 decorators/log_entry_and_exit.py | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 decorators/__init__.py create mode 100644 decorators/log_entry_and_exit.py diff --git a/decorators/__init__.py b/decorators/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/decorators/log_entry_and_exit.py b/decorators/log_entry_and_exit.py new file mode 100644 index 000000000000..9fda43d4a5cd --- /dev/null +++ b/decorators/log_entry_and_exit.py @@ -0,0 +1,34 @@ +from functools import wraps +import logging +from datetime import datetime + +def log_entry_and_exit(func): + '''Log starting time and finish time of funciton''' + + # Configure logging + logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') + + @wraps(func) + def wrapper(*args,**kwargs): + start_time = datetime.now() + logging.info(f"Function '{func.__name__}' started at {start_time}") + return_value = func(*args,*kwargs) + end_time = datetime.now() + logging.info(f"Function '{func.__name__}' ended at {end_time}") + return return_value + + return wrapper + + +""" +Example usage: +""" + +#Function declaration +@log_entry_and_exit +def my_func(name): + print(f"My name is {name}") + + +#Fucntion call +my_func("John Doe") \ No newline at end of file From 2221fec80957a62491bc676867275cff24410ab1 Mon Sep 17 00:00:00 2001 From: Dheeraj-Nalapat Date: Tue, 1 Oct 2024 17:06:24 +0530 Subject: [PATCH 2/6] Move decorators to utils --- {decorators => utils}/__init__.py | 0 utils/decorators/__init__.py | 0 {decorators => utils/decorators}/log_entry_and_exit.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {decorators => utils}/__init__.py (100%) create mode 100644 utils/decorators/__init__.py rename {decorators => utils/decorators}/log_entry_and_exit.py (100%) diff --git a/decorators/__init__.py b/utils/__init__.py similarity index 100% rename from decorators/__init__.py rename to utils/__init__.py diff --git a/utils/decorators/__init__.py b/utils/decorators/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/decorators/log_entry_and_exit.py b/utils/decorators/log_entry_and_exit.py similarity index 100% rename from decorators/log_entry_and_exit.py rename to utils/decorators/log_entry_and_exit.py From 2f5739e2c6621c461c45be42cdb55188acd11e61 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:44:56 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- utils/decorators/log_entry_and_exit.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/utils/decorators/log_entry_and_exit.py b/utils/decorators/log_entry_and_exit.py index 9fda43d4a5cd..e86306e2d0da 100644 --- a/utils/decorators/log_entry_and_exit.py +++ b/utils/decorators/log_entry_and_exit.py @@ -2,17 +2,20 @@ import logging from datetime import datetime + def log_entry_and_exit(func): - '''Log starting time and finish time of funciton''' - + """Log starting time and finish time of funciton""" + # Configure logging - logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') + logging.basicConfig( + level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" + ) @wraps(func) - def wrapper(*args,**kwargs): + def wrapper(*args, **kwargs): start_time = datetime.now() logging.info(f"Function '{func.__name__}' started at {start_time}") - return_value = func(*args,*kwargs) + return_value = func(*args, *kwargs) end_time = datetime.now() logging.info(f"Function '{func.__name__}' ended at {end_time}") return return_value @@ -24,11 +27,12 @@ def wrapper(*args,**kwargs): Example usage: """ -#Function declaration + +# Function declaration @log_entry_and_exit def my_func(name): print(f"My name is {name}") -#Fucntion call -my_func("John Doe") \ No newline at end of file +# Fucntion call +my_func("John Doe") From 33f23e5fc777cff9b018b171ea21330db5ce9017 Mon Sep 17 00:00:00 2001 From: Dheeraj-Nalapat Date: Tue, 1 Oct 2024 17:25:16 +0530 Subject: [PATCH 4/6] Added fixes according to ruff --- utils/decorators/log_entry_and_exit.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/utils/decorators/log_entry_and_exit.py b/utils/decorators/log_entry_and_exit.py index e86306e2d0da..b06106f5677a 100644 --- a/utils/decorators/log_entry_and_exit.py +++ b/utils/decorators/log_entry_and_exit.py @@ -1,28 +1,30 @@ -from functools import wraps import logging +import tzlocal +from functools import wraps from datetime import datetime def log_entry_and_exit(func): - """Log starting time and finish time of funciton""" + '''Log starting time and finish time of funciton''' + # Setiing local timezone + local_tz = tzlocal.get_localzone() # Configure logging logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" ) @wraps(func) - def wrapper(*args, **kwargs): - start_time = datetime.now() + def wrapper(*args,**kwargs): + start_time = datetime.now(tz=local_tz) logging.info(f"Function '{func.__name__}' started at {start_time}") - return_value = func(*args, *kwargs) - end_time = datetime.now() + return_value = func(*args,*kwargs) + end_time = datetime.now(tz=local_tz) logging.info(f"Function '{func.__name__}' ended at {end_time}") return return_value return wrapper - """ Example usage: """ @@ -33,6 +35,5 @@ def wrapper(*args, **kwargs): def my_func(name): print(f"My name is {name}") - -# Fucntion call +#Fucntion call my_func("John Doe") From 6679f4ca6d1b9bf3f3d42279f3841aa3cd2eedcc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:57:54 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- utils/decorators/log_entry_and_exit.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/utils/decorators/log_entry_and_exit.py b/utils/decorators/log_entry_and_exit.py index b06106f5677a..b31cddc15db1 100644 --- a/utils/decorators/log_entry_and_exit.py +++ b/utils/decorators/log_entry_and_exit.py @@ -5,7 +5,7 @@ def log_entry_and_exit(func): - '''Log starting time and finish time of funciton''' + """Log starting time and finish time of funciton""" # Setiing local timezone local_tz = tzlocal.get_localzone() @@ -15,16 +15,17 @@ def log_entry_and_exit(func): ) @wraps(func) - def wrapper(*args,**kwargs): + def wrapper(*args, **kwargs): start_time = datetime.now(tz=local_tz) logging.info(f"Function '{func.__name__}' started at {start_time}") - return_value = func(*args,*kwargs) + return_value = func(*args, *kwargs) end_time = datetime.now(tz=local_tz) logging.info(f"Function '{func.__name__}' ended at {end_time}") return return_value return wrapper + """ Example usage: """ @@ -35,5 +36,6 @@ def wrapper(*args,**kwargs): def my_func(name): print(f"My name is {name}") -#Fucntion call + +# Fucntion call my_func("John Doe") From fd7b88271f17b43caa6e1b2facfc6c238dc92ecd Mon Sep 17 00:00:00 2001 From: Dheeraj-Nalapat Date: Tue, 1 Oct 2024 17:31:34 +0530 Subject: [PATCH 6/6] Sorting imports according to ruff --- utils/decorators/log_entry_and_exit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/decorators/log_entry_and_exit.py b/utils/decorators/log_entry_and_exit.py index b31cddc15db1..7244b6b087fb 100644 --- a/utils/decorators/log_entry_and_exit.py +++ b/utils/decorators/log_entry_and_exit.py @@ -1,7 +1,8 @@ +from datetime import datetime +from functools import wraps import logging + import tzlocal -from functools import wraps -from datetime import datetime def log_entry_and_exit(func):