Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
Empty file added utils/__init__.py
Empty file.
Empty file added utils/decorators/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions utils/decorators/log_entry_and_exit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from functools import wraps
import logging
from datetime import datetime

def log_entry_and_exit(func):

Check failure on line 5 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

utils/decorators/log_entry_and_exit.py:1:1: I001 Import block is un-sorted or un-formatted

Check failure on line 5 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

utils/decorators/log_entry_and_exit.py:1:1: I001 Import block is un-sorted or un-formatted

Choose a reason for hiding this comment

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

Please provide return type hint for the function: log_entry_and_exit. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file utils/decorators/log_entry_and_exit.py, please provide doctest for the function log_entry_and_exit

Please provide type hint for the parameter: func

Choose a reason for hiding this comment

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

Please provide return type hint for the function: log_entry_and_exit. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file utils/decorators/log_entry_and_exit.py, please provide doctest for the function log_entry_and_exit

Please provide type hint for the parameter: func

'''Log starting time and finish time of funciton'''

Check failure on line 7 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

utils/decorators/log_entry_and_exit.py:7:1: W293 Blank line contains whitespace

Check failure on line 7 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

utils/decorators/log_entry_and_exit.py:7:1: W293 Blank line contains whitespace
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

Check failure on line 9 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

utils/decorators/log_entry_and_exit.py:9:89: E501 Line too long (95 > 88)

Check failure on line 9 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

utils/decorators/log_entry_and_exit.py:9:89: E501 Line too long (95 > 88)

@wraps(func)
def wrapper(*args,**kwargs):

Check failure on line 12 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W291)

utils/decorators/log_entry_and_exit.py:12:33: W291 Trailing whitespace

Check failure on line 12 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W291)

utils/decorators/log_entry_and_exit.py:12:33: W291 Trailing whitespace

Choose a reason for hiding this comment

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

Please provide return type hint for the function: wrapper. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file utils/decorators/log_entry_and_exit.py, please provide doctest for the function wrapper

Please provide type hint for the parameter: args

Please provide type hint for the parameter: kwargs

start_time = datetime.now()

Check failure on line 13 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (DTZ005)

utils/decorators/log_entry_and_exit.py:13:22: DTZ005 `datetime.datetime.now()` called without a `tz` argument

Check failure on line 13 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (DTZ005)

utils/decorators/log_entry_and_exit.py:13:22: DTZ005 `datetime.datetime.now()` called without a `tz` argument
logging.info(f"Function '{func.__name__}' started at {start_time}")
return_value = func(*args,*kwargs)
end_time = datetime.now()

Check failure on line 16 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (DTZ005)

utils/decorators/log_entry_and_exit.py:16:20: DTZ005 `datetime.datetime.now()` called without a `tz` argument

Check failure on line 16 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (DTZ005)

utils/decorators/log_entry_and_exit.py:16:20: DTZ005 `datetime.datetime.now()` called without a `tz` argument
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):

Choose a reason for hiding this comment

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

Please provide return type hint for the function: my_func. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file utils/decorators/log_entry_and_exit.py, please provide doctest for the function my_func

Please provide type hint for the parameter: name

Choose a reason for hiding this comment

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

Please provide return type hint for the function: my_func. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file utils/decorators/log_entry_and_exit.py, please provide doctest for the function my_func

Please provide type hint for the parameter: name

print(f"My name is {name}")


#Fucntion call
my_func("John Doe")

Check failure on line 34 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W292)

utils/decorators/log_entry_and_exit.py:34:20: W292 No newline at end of file

Check failure on line 34 in utils/decorators/log_entry_and_exit.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W292)

utils/decorators/log_entry_and_exit.py:34:20: W292 No newline at end of file
Loading