Skip to content

Commit

Permalink
wip: attempt to handle github PR builds
Browse files Browse the repository at this point in the history
  • Loading branch information
russellb committed Nov 26, 2024
1 parent 30d33fa commit 393473a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ def setup(app):
generate_examples()


def get_repo_base_and_branch(pr_number):
url = f"https://api.github.com/repos/vllm-project/vllm/pulls/{pr_number}"
response = requests.get(url)

Check failure on line 101 in docs/source/conf.py

View workflow job for this annotation

GitHub Actions / ruff (3.12)

Ruff (F821)

docs/source/conf.py:101:16: F821 Undefined name `requests`
if response.status_code == 200:
data = response.json()
base = data['base']['repo']['full_name']
branch = data['base']['ref']
return base, branch
else:
logger.error(f"Failed to fetch PR details: {response.status_code}")

Check failure on line 108 in docs/source/conf.py

View workflow job for this annotation

GitHub Actions / ruff (3.12)

Ruff (G004)

docs/source/conf.py:108:22: G004 Logging statement uses f-string
return None, None


def linkcode_resolve(domain, info):
if domain != 'py':
return None
Expand All @@ -104,14 +117,26 @@ def linkcode_resolve(domain, info):
filename = info['module'].replace('.', '/')
module = info['module']
try:
# try to determine the correct file and line number to link to
obj = sys.modules[module]
for part in info['fullname'].split('.'):
obj = getattr(obj, part)
lineno = inspect.getsourcelines(obj)[1]
filename = (inspect.getsourcefile(obj)
or f"{filename}.py").split("vllm/", 1)[1]

if filename.startswith("checkouts/"):
# a PR build on readthedocs
pr_number = filename.split("/")[1]
filename = filename.split("/", 2)[2]
base, branch = get_repo_base_and_branch(pr_number)
if base and branch:
return f"https://github.com/{base}/blob/{branch}/{filename}#L{lineno}"

# Otherwise, link to the source file on the main branch
return f"https://github.com/vllm-project/vllm/blob/main/{filename}#L{lineno}"
except Exception:
# last resort fallback, just try to point to the correct file on main
return f"https://github.com/vllm-project/vllm/blob/main/{filename}.py"


Expand Down

0 comments on commit 393473a

Please sign in to comment.