-
-
Notifications
You must be signed in to change notification settings - Fork 174
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
Add header alignment attribute #183
Add header alignment attribute #183
Conversation
for more information, see https://pre-commit.ci
Codecov Report
@@ Coverage Diff @@
## master #183 +/- ##
==========================================
+ Coverage 94.03% 94.11% +0.08%
==========================================
Files 5 5
Lines 2245 2295 +50
==========================================
+ Hits 2111 2160 +49
- Misses 134 135 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Thank you! |
I only just released this in 3.4.0 and noticed a possible bug: With this code: from prettytable import PrettyTable
headers = [
"cycle",
"release",
"latest",
"latest release",
"support",
"eol",
"codename",
"link",
]
data = [
{
"cycle": "22.04 LTS",
"codename": "Jammy Jellyfish",
"support": "2027-04-02",
"eol": "2032-04-01",
"latest": "22.04.1",
"link": "https://wiki.ubuntu.com/JammyJellyfish/ReleaseNotes/",
"release": "2022-04-21",
"latest release": "2022-08-11",
},
{
"cycle": "21.10",
"codename": "Impish Indri",
"support": "2022-07-31",
"eol": "2022-07-31",
"latest": "21.10",
"link": "https://wiki.ubuntu.com/ImpishIndri/ReleaseNotes/",
"release": "2021-10-14",
"latest release": "2021-10-14",
},
{
"cycle": "21.04",
"codename": "Hirsute Hippo",
"support": "2022-01-20",
"eol": "2022-01-20",
"latest": "21.04",
"link": "https://wiki.ubuntu.com/HirsuteHippo/ReleaseNotes/",
"release": "2021-04-22",
"latest release": "2021-04-22",
},
{
"cycle": "20.10",
"codename": "Groovy Gorilla",
"support": "2021-07-22",
"eol": "2021-07-22",
"latest": "20.10",
"release": "2020-10-22",
"latest release": "2020-10-22",
},
{
"cycle": "20.04 LTS",
"codename": "Focal Fossa",
"support": "2025-04-02",
"eol": "2030-04-01",
"latest": "20.04.4",
"release": "2020-04-23",
"latest release": "2022-02-25",
},
{
"cycle": "19.10",
"codename": "Karmic Koala",
"support": "2020-07-06",
"eol": "2020-07-06",
"latest": "19.10",
"release": "2019-10-17",
"latest release": "2019-10-17",
},
{
"cycle": "18.04 LTS",
"codename": "Bionic Beaver",
"support": "2023-04-02",
"eol": "2028-04-01",
"latest": "18.04.6",
"link": "https://wiki.ubuntu.com/BionicBeaver/ReleaseNotes",
"release": "2018-04-26",
"latest release": "2021-09-17",
},
{
"cycle": "16.04 LTS",
"codename": "Xenial Xerus",
"support": "2021-04-02",
"eol": "2026-04-01",
"latest": "16.04.7",
"release": "2016-04-21",
"latest release": "2020-08-13",
},
{
"cycle": "14.04 LTS",
"codename": "Trusty Tahr",
"support": "2019-04-02",
"eol": "2024-04-01",
"latest": "14.04.6",
"release": "2014-04-17",
"latest release": "2019-03-07",
},
]
x = PrettyTable()
for header in headers:
col_data = [row[header] if header in row else "" for row in data]
x.add_column(header, col_data)
if header in ("cycle", "latest", "link"):
x.align[header] = "l"
print(x) Run with 3.3.0: $ pip install --quiet prettytable==3.3.0 && python 1.py
+-----------+------------+---------+----------------+------------+------------+-----------------+------------------------------------------------------+
| cycle | release | latest | latest release | support | eol | codename | link |
+-----------+------------+---------+----------------+------------+------------+-----------------+------------------------------------------------------+
| 22.04 LTS | 2022-04-21 | 22.04.1 | 2022-08-11 | 2027-04-02 | 2032-04-01 | Jammy Jellyfish | https://wiki.ubuntu.com/JammyJellyfish/ReleaseNotes/ |
| 21.10 | 2021-10-14 | 21.10 | 2021-10-14 | 2022-07-31 | 2022-07-31 | Impish Indri | https://wiki.ubuntu.com/ImpishIndri/ReleaseNotes/ |
| 21.04 | 2021-04-22 | 21.04 | 2021-04-22 | 2022-01-20 | 2022-01-20 | Hirsute Hippo | https://wiki.ubuntu.com/HirsuteHippo/ReleaseNotes/ |
| 20.10 | 2020-10-22 | 20.10 | 2020-10-22 | 2021-07-22 | 2021-07-22 | Groovy Gorilla | |
| 20.04 LTS | 2020-04-23 | 20.04.4 | 2022-02-25 | 2025-04-02 | 2030-04-01 | Focal Fossa | |
| 19.10 | 2019-10-17 | 19.10 | 2019-10-17 | 2020-07-06 | 2020-07-06 | Karmic Koala | |
| 18.04 LTS | 2018-04-26 | 18.04.6 | 2021-09-17 | 2023-04-02 | 2028-04-01 | Bionic Beaver | https://wiki.ubuntu.com/BionicBeaver/ReleaseNotes |
| 16.04 LTS | 2016-04-21 | 16.04.7 | 2020-08-13 | 2021-04-02 | 2026-04-01 | Xenial Xerus | |
| 14.04 LTS | 2014-04-17 | 14.04.6 | 2019-03-07 | 2019-04-02 | 2024-04-01 | Trusty Tahr | |
+-----------+------------+---------+----------------+------------+------------+-----------------+------------------------------------------------------+ And with 3.4.0: pip install --quiet prettytable==3.4.0 && python 1.py
+-----------+------------+---------+----------------+------------+------------+-----------------+------------------------------------------------------+
| cycle | release | latest | latest release | support | eol | codename | link |
+-----------+------------+---------+----------------+------------+------------+-----------------+------------------------------------------------------+
| 22.04 LTS | 2022-04-21 | 22.04.1 | 2022-08-11 | 2027-04-02 | 2032-04-01 | Jammy Jellyfish | https://wiki.ubuntu.com/JammyJellyfish/ReleaseNotes/ |
| 21.10 | 2021-10-14 | 21.10 | 2021-10-14 | 2022-07-31 | 2022-07-31 | Impish Indri | https://wiki.ubuntu.com/ImpishIndri/ReleaseNotes/ |
| 21.04 | 2021-04-22 | 21.04 | 2021-04-22 | 2022-01-20 | 2022-01-20 | Hirsute Hippo | https://wiki.ubuntu.com/HirsuteHippo/ReleaseNotes/ |
| 20.10 | 2020-10-22 | 20.10 | 2020-10-22 | 2021-07-22 | 2021-07-22 | Groovy Gorilla | |
| 20.04 LTS | 2020-04-23 | 20.04.4 | 2022-02-25 | 2025-04-02 | 2030-04-01 | Focal Fossa | |
| 19.10 | 2019-10-17 | 19.10 | 2019-10-17 | 2020-07-06 | 2020-07-06 | Karmic Koala | |
| 18.04 LTS | 2018-04-26 | 18.04.6 | 2021-09-17 | 2023-04-02 | 2028-04-01 | Bionic Beaver | https://wiki.ubuntu.com/BionicBeaver/ReleaseNotes |
| 16.04 LTS | 2016-04-21 | 16.04.7 | 2020-08-13 | 2021-04-02 | 2026-04-01 | Xenial Xerus | |
| 14.04 LTS | 2014-04-17 | 14.04.6 | 2019-03-07 | 2019-04-02 | 2024-04-01 | Trusty Tahr | |
+-----------+------------+---------+----------------+------------+------------+-----------------+------------------------------------------------------+ Notice the different header alignment: < | cycle | release | latest | latest release | support | eol | codename | link |
---
> | cycle | release | latest | latest release | support | eol | codename | link | So the code had set: if header in ("cycle", "latest", "link"):
x.align[header] = "l" In 3.3.0, the data and header were left-aligned. In 3.4.0, only the data was left-aligned, the header was centre-aligned. Is this a bug? Should But if there's no |
We noticed this change in OpenStack testing, too, and I think that default behavior should not change in a minor release, so I'd prefer this to be treated as a bug and get fixed. |
this is the openstack nova bug https://bugs.launchpad.net/nova/+bug/1988482 currently, it's blocking our stable branch for the last release. currently I'm not sure how else we could "fix" this in oepnstack as we cannot raise minium on already released branches and see cant simply update the test as that would then fail with the older release of prettytable. |
actully i think i understand how to work around this in OpenStack so i have proposed we can backport that as a workaround. this is still likely a bug but we can maintain the old behavior by just setting both align and header_align |
I'll revert this and make a bug fix release. Then this PR can be re-submitted, and we'll need extra tests to make sure things work with both Also the default def add_column(self, fieldname, column, align="c", valign="t", header_align="c"): |
3.4.1 released: |
Thx for the fast update, 3.4.1 works without failure for us |
That release contains a formatting change that causes nova tests to fail[0]. The change has been reverted [1], so using 3.4.1 instead works fine. [0] https://bugs.launchpad.net/nova/+bug/1988482 [1] prettytable/prettytable#183 Change-Id: I979320cef3ed8c8bee75061b4fcb4c1323cc83a9
* Update requirements from branch 'master' to efffcd29d4d59a953e99963c402cbe956018d4ec - Merge "Block prettytable 3.4.0" - Block prettytable 3.4.0 That release contains a formatting change that causes nova tests to fail[0]. The change has been reverted [1], so using 3.4.1 instead works fine. [0] https://bugs.launchpad.net/nova/+bug/1988482 [1] prettytable/prettytable#183 Change-Id: I979320cef3ed8c8bee75061b4fcb4c1323cc83a9
Fixes #102