Skip to content

Commit 6507ef1

Browse files
authored
Merge pull request #1 from hugovk/add-pr-option
2 parents 08fe89e + 40de515 commit 6507ef1

File tree

6 files changed

+45
-12
lines changed

6 files changed

+45
-12
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
python-version: ["pypy-3.8", "3.7", "3.8", "3.9", "3.10", "3.11-dev"]
15-
os: [ubuntu-latest, macos-latest, windows-latest]
15+
os: [windows-latest, macos-latest, ubuntu-latest]
1616
include:
1717
# Include new variables for Codecov
18-
- { codecov-flag: GHA_Ubuntu, os: ubuntu-latest }
1918
- { codecov-flag: GHA_macOS, os: macos-latest }
19+
- { codecov-flag: GHA_Ubuntu, os: ubuntu-latest }
2020
- { codecov-flag: GHA_Windows, os: windows-latest }
2121

2222
steps:
@@ -39,8 +39,21 @@ jobs:
3939
run: |
4040
tox -e py
4141
42+
- name: Cog
43+
if: matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
44+
run: |
45+
tox -e cog
46+
4247
- name: Upload coverage
4348
uses: codecov/[email protected]
4449
with:
4550
flags: ${{ matrix.codecov-flag }}
4651
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
52+
53+
success:
54+
needs: test
55+
runs-on: ubuntu-latest
56+
name: test successful
57+
steps:
58+
- name: Success
59+
run: echo Test successful

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ run("pep --help")
3737

3838
```console
3939
$ pep --help
40-
usage: pep [-h] [-u URL] [-V] search
40+
usage: pep [-h] [-u URL] [--pr PR] [-V] search
4141

4242
CLI to open PEPs in your browser
4343

@@ -47,6 +47,7 @@ positional arguments:
4747
options:
4848
-h, --help show this help message and exit
4949
-u URL, --url URL Base URL for PEPs (default: https://peps.python.org)
50+
--pr PR Open preview for python/peps PR (default: None)
5051
-V, --version show program's version number and exit
5152
```
5253

@@ -65,3 +66,10 @@ https://peps.python.org/pep-0008/
6566
$ pep 3.11
6667
https://peps.python.org/pep-0664/
6768
```
69+
70+
### Open a build preview of a python/peps PR
71+
72+
```console
73+
$ pep 594 --pr 2440
74+
https://pep-previews--2440.org.readthedocs.build/pep-0594/
75+
```

src/pepotron/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"""
33
CLI to open PEPs in your browser
44
"""
5+
from __future__ import annotations
6+
57
import webbrowser
68

79
try:
@@ -38,18 +40,21 @@
3840
}
3941

4042

41-
def url(search: str, base_url: str) -> str:
43+
def url(search: str, base_url: str | None = None, pr: int | None = None) -> str:
4244
"""Get PEP URL"""
4345
try:
4446
number = int(search)
4547
except ValueError:
4648
number = VERSION_TO_PEP[search]
4749

50+
if pr:
51+
base_url = f"https://pep-previews--{pr}.org.readthedocs.build"
52+
4853
return base_url.rstrip("/") + f"/pep-{number:04}" + "/"
4954

5055

51-
def pep(search: str, base_url: str) -> None:
56+
def pep(search: str, base_url: str | None = None, pr: int | None = None) -> None:
5257
"""Open this PEP in the browser"""
53-
pep_url = url(search, base_url)
58+
pep_url = url(search, base_url, pr)
5459
print(pep_url)
5560
webbrowser.open(pep_url, new=2) # 2 = open in a new tab, if possible

src/pepotron/cli.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ def main() -> None:
1818
parser = argparse.ArgumentParser(description=__doc__, formatter_class=Formatter)
1919
parser.add_argument("search", help="PEP number, or Python version for its schedule")
2020
parser.add_argument(
21-
"-u",
22-
"--url",
23-
default="https://peps.python.org",
24-
help="Base URL for PEPs",
21+
"-u", "--url", default="https://peps.python.org", help="Base URL for PEPs"
2522
)
23+
parser.add_argument("--pr", type=int, help="Open preview for python/peps PR")
2624
parser.add_argument(
2725
"-V", "--version", action="version", version=f"%(prog)s {pepotron.__version__}"
2826
)
2927
args = parser.parse_args()
30-
pepotron.pep(search=args.search, base_url=args.url)
28+
pepotron.pep(search=args.search, base_url=args.url, pr=args.pr)
3129

3230

3331
if __name__ == "__main__":

tests/test_pep.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ def test_url(search: str, base_url: str, expected_url: str) -> None:
3636
pep_url = pepotron.url(search, base_url)
3737
# Assert
3838
assert pep_url == expected_url
39+
40+
41+
def test_url_pr() -> None:
42+
# Arrange
43+
search = "594"
44+
pr = 2440
45+
# Act
46+
pep_url = pepotron.url(search, pr=pr)
47+
# Assert
48+
assert pep_url == "https://pep-previews--2440.org.readthedocs.build/pep-0594/"

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ commands =
1313
pep --help
1414

1515
[testenv:cog]
16-
skip_install = true
1716
deps =
1817
cogapp
1918
commands =

0 commit comments

Comments
 (0)