mirror of
https://github.com/vinta/awesome-python.git
synced 2026-08-03 22:40:46 +00:00
feat: use explicit Projects section in README
This commit is contained in:
parent
921d47b455
commit
6c18b6447e
5 changed files with 190 additions and 178 deletions
|
|
@ -81,35 +81,35 @@ MINIMAL_README = textwrap.dedent("""\
|
|||
|
||||
Some intro text.
|
||||
|
||||
---
|
||||
## Projects
|
||||
|
||||
## Alpha
|
||||
### Alpha
|
||||
|
||||
_Libraries for alpha stuff._
|
||||
|
||||
- [lib-a](https://example.com/a) - Does A.
|
||||
- [lib-b](https://example.com/b) - Does B.
|
||||
|
||||
## Beta
|
||||
### Beta
|
||||
|
||||
_Tools for beta._
|
||||
|
||||
- [lib-c](https://example.com/c) - Does C.
|
||||
|
||||
# Resources
|
||||
## Resources
|
||||
|
||||
Where to discover resources.
|
||||
|
||||
## Newsletters
|
||||
### Newsletters
|
||||
|
||||
- [News One](https://example.com/n1)
|
||||
- [News Two](https://example.com/n2)
|
||||
|
||||
## Podcasts
|
||||
### Podcasts
|
||||
|
||||
- [Pod One](https://example.com/p1)
|
||||
|
||||
# Contributing
|
||||
## Contributing
|
||||
|
||||
Please contribute!
|
||||
""")
|
||||
|
|
@ -120,11 +120,11 @@ GROUPED_README = textwrap.dedent("""\
|
|||
|
||||
Some intro text.
|
||||
|
||||
---
|
||||
## Projects
|
||||
|
||||
**Group One**
|
||||
|
||||
## Alpha
|
||||
### Alpha
|
||||
|
||||
_Libraries for alpha stuff._
|
||||
|
||||
|
|
@ -133,25 +133,25 @@ GROUPED_README = textwrap.dedent("""\
|
|||
|
||||
**Group Two**
|
||||
|
||||
## Beta
|
||||
### Beta
|
||||
|
||||
_Tools for beta._
|
||||
|
||||
- [lib-c](https://example.com/c) - Does C.
|
||||
|
||||
## Gamma
|
||||
### Gamma
|
||||
|
||||
- [lib-d](https://example.com/d) - Does D.
|
||||
|
||||
# Resources
|
||||
## Resources
|
||||
|
||||
Where to discover resources.
|
||||
|
||||
## Newsletters
|
||||
### Newsletters
|
||||
|
||||
- [News One](https://example.com/n1)
|
||||
|
||||
# Contributing
|
||||
## Contributing
|
||||
|
||||
Please contribute!
|
||||
""")
|
||||
|
|
@ -191,7 +191,7 @@ class TestParseReadmeSections:
|
|||
all_names.extend(c["name"] for c in g["categories"])
|
||||
assert "Contributing" not in all_names
|
||||
|
||||
def test_no_separator(self):
|
||||
def test_no_projects_heading(self):
|
||||
groups = parse_readme("# Just a heading\n\nSome text.\n")
|
||||
assert groups == []
|
||||
|
||||
|
|
@ -199,19 +199,19 @@ class TestParseReadmeSections:
|
|||
readme = textwrap.dedent("""\
|
||||
# Title
|
||||
|
||||
---
|
||||
## Projects
|
||||
|
||||
## NullDesc
|
||||
### NullDesc
|
||||
|
||||
- [item](https://x.com) - Thing.
|
||||
|
||||
# Resources
|
||||
## Resources
|
||||
|
||||
## Tips
|
||||
### Tips
|
||||
|
||||
- [tip](https://x.com)
|
||||
|
||||
# Contributing
|
||||
## Contributing
|
||||
|
||||
Done.
|
||||
""")
|
||||
|
|
@ -225,15 +225,15 @@ class TestParseReadmeSections:
|
|||
readme = textwrap.dedent("""\
|
||||
# T
|
||||
|
||||
---
|
||||
## Projects
|
||||
|
||||
## Algos
|
||||
### Algos
|
||||
|
||||
_Algorithms. Also see [awesome-algos](https://example.com)._
|
||||
|
||||
- [lib](https://x.com) - Lib.
|
||||
|
||||
# Contributing
|
||||
## Contributing
|
||||
|
||||
Done.
|
||||
""")
|
||||
|
|
@ -273,17 +273,17 @@ class TestParseGroupedReadme:
|
|||
readme = textwrap.dedent("""\
|
||||
# T
|
||||
|
||||
---
|
||||
## Projects
|
||||
|
||||
**Empty**
|
||||
|
||||
**HasCats**
|
||||
|
||||
## Cat
|
||||
### Cat
|
||||
|
||||
- [x](https://x.com) - X.
|
||||
|
||||
# Contributing
|
||||
## Contributing
|
||||
|
||||
Done.
|
||||
""")
|
||||
|
|
@ -295,15 +295,15 @@ class TestParseGroupedReadme:
|
|||
readme = textwrap.dedent("""\
|
||||
# T
|
||||
|
||||
---
|
||||
## Projects
|
||||
|
||||
**Note:** This is not a group marker.
|
||||
|
||||
## Cat
|
||||
### Cat
|
||||
|
||||
- [x](https://x.com) - X.
|
||||
|
||||
# Contributing
|
||||
## Contributing
|
||||
|
||||
Done.
|
||||
""")
|
||||
|
|
@ -317,19 +317,19 @@ class TestParseGroupedReadme:
|
|||
readme = textwrap.dedent("""\
|
||||
# T
|
||||
|
||||
---
|
||||
## Projects
|
||||
|
||||
## Orphan
|
||||
### Orphan
|
||||
|
||||
- [x](https://x.com) - X.
|
||||
|
||||
**A Group**
|
||||
|
||||
## Grouped
|
||||
### Grouped
|
||||
|
||||
- [y](https://x.com) - Y.
|
||||
|
||||
# Contributing
|
||||
## Contributing
|
||||
|
||||
Done.
|
||||
""")
|
||||
|
|
@ -405,15 +405,15 @@ class TestParseSectionEntries:
|
|||
readme = textwrap.dedent("""\
|
||||
# T
|
||||
|
||||
---
|
||||
## Projects
|
||||
|
||||
## Async
|
||||
### Async
|
||||
|
||||
- [asyncio](https://x.com) - Async I/O.
|
||||
- [awesome-asyncio](https://y.com)
|
||||
- [trio](https://z.com) - Friendly async.
|
||||
|
||||
# Contributing
|
||||
## Contributing
|
||||
|
||||
Done.
|
||||
""")
|
||||
|
|
@ -480,21 +480,21 @@ class TestParseRealReadme:
|
|||
md = MarkdownIt("commonmark")
|
||||
root = SyntaxTreeNode(md.parse(self.readme_text))
|
||||
|
||||
# Find category section boundaries (between --- and # Resources/Contributing)
|
||||
hr_idx = None
|
||||
# Find category section boundaries (between Projects and Resources/Contributing)
|
||||
projects_idx = None
|
||||
end_idx = None
|
||||
for i, node in enumerate(root.children):
|
||||
if hr_idx is None and node.type == "hr":
|
||||
hr_idx = i
|
||||
elif node.type == "heading" and node.tag == "h1":
|
||||
if node.type == "heading" and node.tag in ("h1", "h2"):
|
||||
text = render_inline_text(node.children[0].children) if node.children else ""
|
||||
if end_idx is None and text in ("Resources", "Contributing"):
|
||||
if projects_idx is None and text == "Projects":
|
||||
projects_idx = i
|
||||
elif end_idx is None and text in ("Resources", "Contributing"):
|
||||
end_idx = i
|
||||
if hr_idx is None:
|
||||
if projects_idx is None:
|
||||
return
|
||||
|
||||
bad = []
|
||||
cat_nodes = root.children[hr_idx + 1 : end_idx or len(root.children)]
|
||||
cat_nodes = root.children[projects_idx + 1 : end_idx or len(root.children)]
|
||||
for node in cat_nodes:
|
||||
if node.type != "bullet_list":
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue