Skip to content

Commit

Permalink
Open topics index for pep topic or pep topics (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Apr 14, 2023
2 parents adee440 + c81af9c commit 73a07a7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,42 @@ https://peps.python.org/topic/governance/

<!-- [[[end]]] -->

<!-- [[[cog run("pep packaging") ]]] -->

```console
$ pep packaging
https://peps.python.org/topic/packaging/
```

<!-- [[[end]]] -->

<!-- [[[cog run("pep release") ]]] -->

```console
$ pep release
https://peps.python.org/topic/release/
```

<!-- [[[end]]] -->

<!-- [[[cog run("pep typing") ]]] -->

```console
$ pep typing
https://peps.python.org/topic/typing/
```

<!-- [[[end]]] -->

<!-- [[[cog run("pep topics") ]]] -->

```console
$ pep topics
https://peps.python.org/topic/
```

<!-- [[[end]]] -->

### Open a build preview of a python/peps PR

<!-- [[[cog run("pep 594 --pr 2440") ]]] -->
Expand Down
36 changes: 19 additions & 17 deletions src/pepotron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,27 @@ def pep_url(search: str | None, base_url: str = BASE_URL, pr: int | None = None)

result = base_url.rstrip("/")

if search:
if search.lower() in TOPICS:
result += f"/topic/{search}/"
return result
if not search:
return result

if search.lower() in ("topic", "topics"):
return result + "/topic/"

if search.lower() in TOPICS:
return result + f"/topic/{search}/"

try:
# pep 8
number = int(search)
except ValueError:
try:
# pep 8
number = int(search)
except ValueError:
try:
# pep 3.11
number = VERSION_TO_PEP[search]
except KeyError:
# pep "dead batteries"
number = word_search(search)

result += f"/pep-{number:0>4}/"

return result
# pep 3.11
number = VERSION_TO_PEP[search]
except KeyError:
# pep "dead batteries"
number = word_search(search)

return result + f"/pep-{number:0>4}/"


def open_pep(
Expand Down
2 changes: 2 additions & 0 deletions tests/test_pepotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
("dead batteries", "https://peps.python.org/pep-0594/"),
("release", "https://peps.python.org/topic/release/"),
("typing", "https://peps.python.org/topic/typing/"),
("topics", "https://peps.python.org/topic/"),
("topic", "https://peps.python.org/topic/"),
],
)
def test_url(search: str, expected_url: str) -> None:
Expand Down

0 comments on commit 73a07a7

Please sign in to comment.