Skip to content

Add --pr to open a python/peps PR preview #1

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 1 commit into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
fail-fast: false
matrix:
python-version: ["pypy-3.8", "3.7", "3.8", "3.9", "3.10", "3.11-dev"]
os: [ubuntu-latest, macos-latest, windows-latest]
os: [windows-latest, macos-latest, ubuntu-latest]
include:
# Include new variables for Codecov
- { codecov-flag: GHA_Ubuntu, os: ubuntu-latest }
- { codecov-flag: GHA_macOS, os: macos-latest }
- { codecov-flag: GHA_Ubuntu, os: ubuntu-latest }
- { codecov-flag: GHA_Windows, os: windows-latest }

steps:
Expand All @@ -39,8 +39,21 @@ jobs:
run: |
tox -e py

- name: Cog
if: matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
run: |
tox -e cog

- name: Upload coverage
uses: codecov/[email protected]
with:
flags: ${{ matrix.codecov-flag }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}

success:
needs: test
runs-on: ubuntu-latest
name: test successful
steps:
- name: Success
run: echo Test successful
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ run("pep --help")

```console
$ pep --help
usage: pep [-h] [-u URL] [-V] search
usage: pep [-h] [-u URL] [--pr PR] [-V] search

CLI to open PEPs in your browser

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

Expand All @@ -65,3 +66,10 @@ https://peps.python.org/pep-0008/
$ pep 3.11
https://peps.python.org/pep-0664/
```

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

```console
$ pep 594 --pr 2440
https://pep-previews--2440.org.readthedocs.build/pep-0594/
```
11 changes: 8 additions & 3 deletions src/pepotron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"""
CLI to open PEPs in your browser
"""
from __future__ import annotations

import webbrowser

try:
Expand Down Expand Up @@ -38,18 +40,21 @@
}


def url(search: str, base_url: str) -> str:
def url(search: str, base_url: str | None = None, pr: int | None = None) -> str:
"""Get PEP URL"""
try:
number = int(search)
except ValueError:
number = VERSION_TO_PEP[search]

if pr:
base_url = f"https://pep-previews--{pr}.org.readthedocs.build"

return base_url.rstrip("/") + f"/pep-{number:04}" + "/"


def pep(search: str, base_url: str) -> None:
def pep(search: str, base_url: str | None = None, pr: int | None = None) -> None:
"""Open this PEP in the browser"""
pep_url = url(search, base_url)
pep_url = url(search, base_url, pr)
print(pep_url)
webbrowser.open(pep_url, new=2) # 2 = open in a new tab, if possible
8 changes: 3 additions & 5 deletions src/pepotron/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ def main() -> None:
parser = argparse.ArgumentParser(description=__doc__, formatter_class=Formatter)
parser.add_argument("search", help="PEP number, or Python version for its schedule")
parser.add_argument(
"-u",
"--url",
default="https://peps.python.org",
help="Base URL for PEPs",
"-u", "--url", default="https://peps.python.org", help="Base URL for PEPs"
)
parser.add_argument("--pr", type=int, help="Open preview for python/peps PR")
parser.add_argument(
"-V", "--version", action="version", version=f"%(prog)s {pepotron.__version__}"
)
args = parser.parse_args()
pepotron.pep(search=args.search, base_url=args.url)
pepotron.pep(search=args.search, base_url=args.url, pr=args.pr)


if __name__ == "__main__":
Expand Down
10 changes: 10 additions & 0 deletions tests/test_pep.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ def test_url(search: str, base_url: str, expected_url: str) -> None:
pep_url = pepotron.url(search, base_url)
# Assert
assert pep_url == expected_url


def test_url_pr() -> None:
# Arrange
search = "594"
pr = 2440
# Act
pep_url = pepotron.url(search, pr=pr)
# Assert
assert pep_url == "https://pep-previews--2440.org.readthedocs.build/pep-0594/"
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ commands =
pep --help

[testenv:cog]
skip_install = true
deps =
cogapp
commands =
Expand Down