-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Use tabulate in wiki to create better tables #2241
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,11 @@ | |
import datetime | ||
import logging | ||
import shutil | ||
import textwrap | ||
from pathlib import Path | ||
|
||
import plumbum | ||
import tabulate | ||
from dateutil import relativedelta | ||
|
||
git = plumbum.local["git"] | ||
|
@@ -48,7 +50,7 @@ def calculate_monthly_stat( | |
|
||
|
||
def generate_home_wiki_page(wiki_dir: Path, repository: str) -> None: | ||
YEAR_MONTHLY_TABLES = "<!-- YEAR_MONTHLY_TABLES -->\n" | ||
YEAR_MONTHLY_TABLES = "<!-- YEAR_MONTHLY_TABLES -->" | ||
|
||
wiki_home_content = (THIS_DIR / "Home.md").read_text() | ||
|
||
|
@@ -58,25 +60,21 @@ def generate_home_wiki_page(wiki_dir: Path, repository: str) -> None: | |
] | ||
wiki_home_content = wiki_home_content.format(REPOSITORY=repository) | ||
|
||
YEAR_TABLE_HEADER = """\ | ||
## {year} | ||
|
||
| Month | Builds | Images | Commits | | ||
| ---------------------- | ------ | ------ | ----------------------------------------------------------------------------------------------- | | ||
""" | ||
|
||
GITHUB_COMMITS_URL = ( | ||
f"[{{}}](https://github.com/{repository}/commits/main/?since={{}}&until={{}})" | ||
) | ||
|
||
YEAR_TABLE_HEADERS = ["Month", "Builds", "Images", "Commits"] | ||
|
||
for year_dir in sorted((wiki_dir / "monthly-files").glob("*"), reverse=True): | ||
wiki_home_content += "\n" + YEAR_TABLE_HEADER.format(year=year_dir.name) | ||
year = int(year_dir.name) | ||
wiki_home_content += f"\n\n## {year}\n\n" | ||
year_table_rows = [] | ||
|
||
year_builds, year_images, year_commits = 0, 0, 0 | ||
for year_month_file in sorted(year_dir.glob("*.md"), reverse=True): | ||
year_month = year_month_file.stem | ||
year_month_date = datetime.date( | ||
year=int(year_month[:4]), month=int(year_month[5:]), day=1 | ||
) | ||
year_month_date = datetime.date(year=year, month=int(year_month[5:]), day=1) | ||
builds, images, commits = calculate_monthly_stat( | ||
year_month_file, year_month_date | ||
) | ||
|
@@ -88,13 +86,21 @@ def generate_home_wiki_page(wiki_dir: Path, repository: str) -> None: | |
year_month_date, | ||
year_month_date + relativedelta.relativedelta(day=31), | ||
) | ||
monthly_line = f"| [`{year_month}`](./{year_month}) | {builds: <6} | {images: <6} | {commits_url: <95} |\n" | ||
wiki_home_content += monthly_line | ||
year_table_rows.append( | ||
[f"[`{year_month}`](./{year_month})", builds, images, commits_url] | ||
) | ||
|
||
year_commits_url = GITHUB_COMMITS_URL.format( | ||
year_commits, f"{year_dir.name}-01-01", f"{year_dir.name}-12-31" | ||
year_commits, f"{year}-01-01", f"{year}-12-31" | ||
) | ||
year_table_rows.append( | ||
["**Total**", year_builds, year_images, year_commits_url] | ||
) | ||
year_total_line = f"| **Total** | {year_builds: <6} | {year_images: <6} | {year_commits_url: <95} |\n" | ||
wiki_home_content += year_total_line | ||
|
||
wiki_home_content += tabulate.tabulate( | ||
year_table_rows, YEAR_TABLE_HEADERS, tablefmt="github" | ||
) | ||
wiki_home_content += "\n" | ||
|
||
(wiki_dir / "Home.md").write_text(wiki_home_content) | ||
LOGGER.info("Updated Home page") | ||
|
@@ -103,12 +109,14 @@ def generate_home_wiki_page(wiki_dir: Path, repository: str) -> None: | |
def update_monthly_wiki_page( | ||
wiki_dir: Path, year_month: str, build_history_line: str | ||
) -> None: | ||
MONTHLY_PAGE_HEADER = f"""\ | ||
# Images built during {year_month} | ||
MONTHLY_PAGE_HEADER = textwrap.dedent( | ||
f"""\ | ||
# Images built during {year_month} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This table didn't and won't look nice, because we're appending lines to the existing file and the length is variable |
||
|
||
| Date | Image | Links | | ||
| - | - | - | | ||
""" | ||
| Date | Image | Links | | ||
| - | - | - | | ||
""" | ||
) | ||
year = year_month[:4] | ||
monthly_page = wiki_dir / "monthly-files" / year / (year_month + ".md") | ||
if not monthly_page.exists(): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hardcode won't look good in forks