Set absolute URLs prior to uploading to PyPI (#5038)

## Summary

Closes https://github.com/astral-sh/uv/issues/5030.
This commit is contained in:
Charlie Marsh 2024-07-13 13:29:21 -04:00 committed by GitHub
parent e8c16889f1
commit b629ab89c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 43 additions and 10 deletions

View file

@ -1089,9 +1089,9 @@ def main():
else list(Benchmark)
)
logging.info("Reading requirements from: {}".format(requirements_file))
logging.info(f"Reading requirements from: {requirements_file}")
logging.info("```")
with open(args.file, "r") as f:
with open(args.file) as f:
for line in f:
logging.info(line.rstrip())
logging.info("```")

View file

@ -9,8 +9,8 @@ from __future__ import annotations
import argparse
import logging
import os
import sys
import subprocess
import sys
import tempfile
DEFAULT_TEST_PACKAGES = [

View file

@ -9,7 +9,6 @@ import subprocess
import sys
import tempfile
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")

View file

@ -1,6 +1,5 @@
from .deptry_reproducer import *
__doc__ = deptry_reproducer.__doc__
if hasattr(deptry_reproducer, "__all__"):
__all__ = deptry_reproducer.__all__

View file

@ -207,7 +207,7 @@ def main(scenarios: list[Path], snapshot_update: bool = True):
logging.info(
f"Updating test file at `{tests.relative_to(PROJECT_ROOT)}`...",
)
with open(tests, "wt") as test_file:
with open(tests, "w") as test_file:
test_file.write(output)
# Format

View file

@ -8,8 +8,12 @@ adjusts the images in the README.md to support the given target.
from __future__ import annotations
import argparse
import re
import urllib.parse
from pathlib import Path
import tomllib
URL = "https://github.com/astral-sh/uv/assets/1309177/{}"
URL_LIGHT = URL.format("629e59c0-9c6e-4013-9ad4-adb2bcf5080d")
URL_DARK = URL.format("03aa9163-1c79-4a87-a31d-7a9311ed9310")
@ -35,6 +39,8 @@ PYPI = f"""
def main(target: str) -> None:
"""Modify the README.md to support the given target."""
# Replace the benchmark images based on the target.
with Path("README.md").open(encoding="utf8") as fp:
content = fp.read()
if GITHUB not in content:
@ -42,12 +48,34 @@ def main(target: str) -> None:
raise ValueError(msg)
if target == "pypi":
with Path("README.md").open("w", encoding="utf8") as fp:
fp.write(content.replace(GITHUB, PYPI))
content = content.replace(GITHUB, PYPI)
else:
msg = f"Unknown target: {target}"
raise ValueError(msg)
# Read the current version from the `pyproject.toml`.
with Path("pyproject.toml").open(mode="rb") as fp:
# Parse the TOML.
pyproject = tomllib.load(fp)
if "project" in pyproject and "version" in pyproject["project"]:
version = pyproject["project"]["version"]
else:
raise ValueError("Version not found in pyproject.toml")
# Replace any relative URLs with absolute URLs.
def replace(match: re.Match) -> str:
url = match.group(1)
if not url.startswith("http"):
url = urllib.parse.urljoin(
f"https://github.com/astral-sh/uv/blob/{version}/README.md", url
)
return f"]({url})"
content = re.sub(r"]\(([^)]+)\)", replace, content)
with Path("README.md").open("w", encoding="utf8") as fp:
fp.write(content)
if __name__ == "__main__":
parser = argparse.ArgumentParser(