-
Notifications
You must be signed in to change notification settings - Fork 290
docs: table and add stars #474
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
64a0937
docs: repo table with stars
henryiii d1ba5b8
docs: sort by stars
henryiii abbe91c
feat: generator
henryiii bf011b5
feat: CI info
henryiii c166426
chore: update repos to add CI and plat, more
henryiii b3bb527
feat: PyGithub and direct writing
henryiii 3ac943b
chore: run bin/projects.py
henryiii 9bfd0f7
fix: drop stars, fix a few more projects
henryiii 044a5da
docs: pybase64 moved
henryiii f9a5ec8
Update bin/projects.yml
henryiii 677e51d
Use spaces in project names to allow line breaks and keep column narrow
joerick 78b6f86
Add notes to the popular projects
joerick 5dd2f56
Remove the book emoji, seems a little distracting
joerick 6974680
Move projects.yml to docs/data
joerick 4ac5feb
Add note about generated content, update paths
joerick 2e165c3
Add back the options section
joerick dbb65f9
Run script to update readme
joerick 84a4b05
Add our own versions of the icons, generated from script
joerick c217d59
Add working examples and changelog docs pages
joerick c76ee0b
Add symlink to fix image references in the working-examples page
joerick 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,169 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Convert a yaml project list into a nice table. | ||
|
||
Suggested usage: | ||
|
||
./bin/projects.py bin/projects.yml --online --auth $GITHUB_API_TOKEN --readme README.md | ||
git diff | ||
""" | ||
|
||
import builtins | ||
import functools | ||
from datetime import datetime | ||
from io import StringIO | ||
from typing import Dict, Any, List, Optional, TextIO | ||
|
||
import click | ||
import yaml | ||
from github import Github | ||
|
||
|
||
ICONS = ( | ||
"appveyor", | ||
"github", | ||
"azurepipelines", | ||
"circleci", | ||
"gitlab", | ||
"travisci", | ||
"windows", | ||
"apple", | ||
"linux", | ||
) | ||
|
||
|
||
class Project: | ||
NAME: int = 0 | ||
|
||
def __init__(self, config: Dict[str, Any], github: Optional[Github] = None): | ||
try: | ||
self.name: str = config["name"] | ||
self.gh: str = config["gh"] | ||
except KeyError: | ||
print("Invalid config, needs at least gh and name!", config) | ||
raise | ||
|
||
self.stars_repo: str = config.get("stars", self.gh) | ||
self.notes: str = config.get("notes", "") | ||
self.ci: List[str] = config.get("ci", []) | ||
self.os: List[str] = config.get("os", []) | ||
|
||
self.online = github is not None | ||
if github is not None: | ||
repo = github.get_repo(self.stars_repo) | ||
self.num_stars = repo.stargazers_count | ||
self.pushed_at = repo.pushed_at | ||
if not self.notes: | ||
notes = repo.description | ||
if notes: | ||
self.notes = f":closed_book: {notes}" | ||
else: | ||
self.num_stars = 0 | ||
self.pushed_at = datetime.utcnow() | ||
|
||
name_len = len(self.name) + 4 | ||
self.__class__.NAME = max(self.__class__.NAME, name_len) | ||
|
||
def __lt__(self, other: "Project") -> bool: | ||
if self.online: | ||
return self.num_stars < other.num_stars | ||
else: | ||
return self.name < other.name | ||
|
||
@classmethod | ||
def header(cls) -> str: | ||
return ( | ||
f"| {'Name':{cls.NAME}} | CI | OS | Notes |\n" | ||
f"|{'':-^{cls.NAME+2 }}|----|----|:------|" | ||
) | ||
|
||
@property | ||
def namelink(self) -> str: | ||
return f"[{self.name}][]" | ||
|
||
@property | ||
def starslink(self) -> str: | ||
return f"![{self.name} stars][]" | ||
|
||
@property | ||
def url(self) -> str: | ||
return f"https://github.com/{self.gh}" | ||
|
||
@property | ||
def ci_icons(self) -> str: | ||
return " ".join(f"![{icon} icon][]" for icon in self.ci) | ||
|
||
@property | ||
def os_icons(self) -> str: | ||
return " ".join(f"![{icon} icon][]" for icon in self.os) | ||
|
||
def table_row(self) -> str: | ||
return f"| {self.namelink: <{self.NAME}} | {self.ci_icons} | {self.os_icons} | {self.notes} |" | ||
|
||
def links(self) -> str: | ||
return f"[{self.name}]: {self.url}" | ||
|
||
def info(self) -> str: | ||
days = (datetime.utcnow() - self.pushed_at).days | ||
return f"<!-- {self.name}: {self.num_stars}, last pushed {days} days ago -->" | ||
|
||
|
||
def str_projects( | ||
config: List[Dict[str, Any]], *, online: bool = True, auth: Optional[str] = None | ||
) -> str: | ||
io = StringIO() | ||
print = functools.partial(builtins.print, file=io) | ||
|
||
github = Github(auth) if online else None | ||
|
||
projects = sorted((Project(item, github) for item in config), reverse=online) | ||
|
||
print(Project.header()) | ||
for project in projects: | ||
print(project.table_row()) | ||
|
||
print() | ||
for project in projects: | ||
print(project.links()) | ||
|
||
print() | ||
for icon in ICONS: | ||
print( | ||
f"[{icon} icon]: https://cdn.jsdelivr.net/npm/simple-icons@v4/icons/{icon}.svg" | ||
) | ||
|
||
print() | ||
for project in projects: | ||
print(project.info()) | ||
|
||
return io.getvalue() | ||
|
||
|
||
@click.command() | ||
@click.argument("input", type=click.File("r")) | ||
@click.option("--online/--no-online", default=True, help="Get info from GitHub") | ||
@click.option("--auth", help="GitHub authentication token") | ||
@click.option("--readme", type=click.File("r+"), help="Modify a readme file if given") | ||
def projects( | ||
input: TextIO, online: bool, auth: Optional[str], readme: Optional[TextIO] | ||
) -> None: | ||
config = yaml.safe_load(input) | ||
output = str_projects(config, online=online, auth=auth) | ||
|
||
if readme is None: | ||
print(output) | ||
else: | ||
text = readme.read() | ||
start_str = "<!-- START bin/project.py -->\n" | ||
start = text.find(start_str) | ||
end = text.find("<!-- END bin/project.py -->\n") | ||
new_text = f"{text[:start + len(start_str)]}\n{output}\n{text[end:]}" | ||
|
||
readme.seek(0) | ||
readme.write(new_text) | ||
readme.truncate() | ||
|
||
|
||
if __name__ == "__main__": | ||
projects() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.