Skip to content

Add option to change print function#145

Open
barabum0 wants to merge 3 commits into
samuelcolvin:mainfrom
barabum0:main
Open

Add option to change print function#145
barabum0 wants to merge 3 commits into
samuelcolvin:mainfrom
barabum0:main

Conversation

@barabum0

Copy link
Copy Markdown

I added logger_function parameter to Debug() class that replaces print if set. Here is an example of usage with loguru:

from devtools import Debug
from loguru import logger

debug = Debug(logger_function=logger.debug)

test_object = {
    "string": "test",
    "integer": 123,
    "nested": {
        "key": "value"
    }
}
debug(test_object)
# 2023-10-29 18:38:45.211 | DEBUG    | devtools.debug:__call__:127 - logger_func_test.py:13 <module>
#     test_object: {
#         'string': 'test',
#         'integer': 123,
#         'nested': {
#             'key': 'value',
#         },
#     } (dict) len=3

@codecov

codecov Bot commented Oct 29, 2023

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.03%. Comparing base (ec406ff) to head (fb8c506).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
devtools/debug.py 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #145      +/-   ##
==========================================
- Coverage   96.29%   96.03%   -0.26%     
==========================================
  Files           8        8              
  Lines         729      732       +3     
  Branches      111      112       +1     
==========================================
+ Hits          702      703       +1     
- Misses         21       22       +1     
- Partials        6        7       +1     
Files with missing lines Coverage Δ
devtools/debug.py 98.48% <60.00%> (-1.52%) ⬇️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec406ff...fb8c506. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@barabum0

barabum0 commented Oct 29, 2023

Copy link
Copy Markdown
Author

added some commits to please lint checker

@barabum0 barabum0 changed the title Add logging_function parameter Add option to change print function Oct 29, 2023
@barabum0

Copy link
Copy Markdown
Author

CI / lint (pull_request) Failing after 1m

I actually don't know whats wrong with my code (if so). But my feature is working correctly, so please review and merge it

Comment thread devtools/debug.py
*,
warnings: 'Optional[bool]' = None,
highlight: 'Optional[bool]' = None,
logger_function: 'Optional[Callable[[str], None]]' = None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If logger_function would have the same signature as print, you could initialize it to print per default.
That way you can get rid of the conditional code in __call__. One might have to wrap a logger into a lambda to ignore the additonal file/flush arguments.

@maltevesper

Copy link
Copy Markdown

CI / lint (pull_request) Failing after 1m

I actually don't know whats wrong with my code (if so). But my feature is working correctly, so please review and merge it

While I am not involved with the project, you might be able to fix your issue: apparently you overindented something, try reformatting with black and committing. You can see the ci issue here: https://github.com/samuelcolvin/python-devtools/actions/runs/6684613574/job/18162063139?pr=145#step:6:158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants