pyutils / line_profiler

Line-by-line profiling for Python
Other
2.57k stars 118 forks source link

Rich output #225

Closed Erotemic closed 11 months ago

Erotemic commented 11 months ago

Factored the rich output features out of https://github.com/pyutils/line_profiler/pull/222 into its own PR.

Adds several options to show_text to control:

These options can also be controlled from the CLI using new arguments:

    parser.add_argument(
        '-r',
        '--rich',
        action='store_true',
        help='Use rich formatting',
    )
    parser.add_argument(
        '-t',
        '--sort',
        action='store_true',
        help='Sort by ascending total time',
    )
    parser.add_argument(
        '-m',
        '--summarize',
        action='store_true',
        help='Print a summary of total function time',
    )

The output is pretty:

image

This builds on an older PR: https://github.com/pyutils/line_profiler/pull/221 I ninja merged that adds the summary and sorting features to the show_text function (and also fixes column formatting issues), but this PR exposes them to the user. As such - because this hasn't been released, new code introduced in that PR is subject to discussion and change here.

Looking for feedback on the UX here:

Notes:

codecov[bot] commented 11 months ago

Codecov Report

Merging #225 (7f49c54) into main (c5b635d) will increase coverage by 4.70%. The diff coverage is 93.75%.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/pyutils/line_profiler/pull/225/graphs/tree.svg?width=650&height=150&src=pr&token=xIK8nFU3K5&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyutils)](https://app.codecov.io/gh/pyutils/line_profiler/pull/225?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyutils) ```diff @@ Coverage Diff @@ ## main #225 +/- ## ========================================== + Coverage 52.88% 57.58% +4.70% ========================================== Files 4 4 Lines 295 323 +28 Branches 50 53 +3 ========================================== + Hits 156 186 +30 + Misses 121 118 -3 - Partials 18 19 +1 ``` | [Files Changed](https://app.codecov.io/gh/pyutils/line_profiler/pull/225?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyutils) | Coverage Δ | | |---|---|---| | [line\_profiler/line\_profiler.py](https://app.codecov.io/gh/pyutils/line_profiler/pull/225?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyutils#diff-bGluZV9wcm9maWxlci9saW5lX3Byb2ZpbGVyLnB5) | `60.88% <93.75%> (+5.88%)` | :arrow_up: | ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/pyutils/line_profiler/pull/225?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyutils). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyutils) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/pyutils/line_profiler/pull/225?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyutils). Last update [c5b635d...7f49c54](https://app.codecov.io/gh/pyutils/line_profiler/pull/225?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyutils). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyutils).