Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Replace pendulum by home-made duration-to-words function #1452

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

dbaty
Copy link
Member

@dbaty dbaty commented Feb 19, 2024

pgcli uses Pendulum to display the query execution time in words:

> select pg_sleep(62)
+----------+
| pg_sleep |
|----------|
|          |
+----------+
SELECT 1
Time: 62.066s (1 minute 2 seconds), executed in: 62.063s (1 minute 2 seconds)

Pendulum 3 (which has been released in December 2023 and is now
written in Rust) does not build on 32-bit architectures [1]. As such,
installing pgcli on such architectures fails. We could pin Pendulum
to version 2 (which was written in Python and builds "everywhere"),
but requiring a whole library and its own dependencies for such a
small feature seems unwarranted.

This commit thus removes the requirement on Pendulum and replaces it
by a simple "duration-to-words" function.

Fixes #1451.

[1] Upstream issue: sdispater/pendulum#784

Checklist

  • I've added this contribution to the changelog.rst
  • I've added my name to the AUTHORS file (it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install), and ran black on my code.
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

@dbaty
Copy link
Member Author

dbaty commented Feb 19, 2024

I tried to be consistent with what Pendulum, except:

  1. The function uses units up to hours, while Pendulum uses days and weeks, too. For example, we'll show "25 hours 10 second", while Pendulum would have shown "1 day 1 hour 10 seconds". I don't think we care and the code is (slightly) simpler this way.

  2. The function handles sub-second durations slightly differently (see unit tests), but pgcli does not use the function for such small durations anyway. So there is no change in behaviour, here.

  3. The function is not written in Rust. We probably could save a few microseconds by writing a Rust extension. And we would look way more cool... Yeah, well, too bad. 😉

@codecov-commenter
Copy link

codecov-commenter commented Feb 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (96eb37f) 79.88% compared to head (da189aa) 80.04%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1452      +/-   ##
==========================================
+ Coverage   79.88%   80.04%   +0.16%     
==========================================
  Files          25       25              
  Lines        3047     3067      +20     
==========================================
+ Hits         2434     2455      +21     
+ Misses        613      612       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@j-bennet
Copy link
Contributor

The function is not written in Rust. We probably could save a few microseconds by writing a Rust extension. And we would look way more cool... Yeah, well, too bad.

😂

Maybe one day, we'll rewrite pgcli in Rust to be cool. But not today.

Copy link
Contributor

@j-bennet j-bennet left a comment

Choose a reason for hiding this comment

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

LGTM. Feel free to merge, once the changelog is updated.

pgcli/main.py Fixed Show fixed Hide fixed
`pgcli` uses Pendulum to display the query execution time in words:

    > select pg_sleep(62)
    +----------+
    | pg_sleep |
    |----------|
    |          |
    +----------+
    SELECT 1
    Time: 62.066s (1 minute 2 seconds), executed in: 62.063s (1 minute 2 seconds)

Pendulum 3 (which has been released in December 2023 and is now
written in Rust) does not build on 32-bit architectures [1]. As such,
installing `pgcli` on such architectures fails. We could pin Pendulum
to version 2 (which was written in Python and builds "everywhere"),
but requiring a whole library and its own dependencies for such a
small feature seems unwarranted.

This commit thus removes the requirement on Pendulum and replaces it
by a simple "duration-to-words" function.

Fixes #1451.

[1] Upstream issue: sdispater/pendulum#784
@dbaty dbaty merged commit 9f114c4 into main Feb 20, 2024
@dbaty dbaty deleted the dbaty/replace_pendulum branch February 20, 2024 11:51
gentoo-bot pushed a commit to gentoo/gentoo that referenced this pull request Feb 20, 2024
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.

pendulum dependency cannot be installed on 32-bit arches
3 participants