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

@ -45,6 +45,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12
- name: "Install Rustfmt"
run: rustup component add rustfmt
@ -60,6 +64,9 @@ jobs:
- name: "Ruff check"
run: pipx run ruff check .
- name: "README check"
run: python scripts/transform_readme.py --target pypi
cargo-clippy:
needs: determine_changes
if: ${{ github.repository == 'astral-sh/uv' && (needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main') }}

View file

@ -197,7 +197,7 @@ Although we generally recommend using virtual environments for dependency manage
`--system` is appropriate in continuous integration and containerized environments.
The `--system` flag is also used to opt in to mutating system environments. For example, the
the `--python` argument can be used to request a Python version (e.g., `--python 3.12`), and uv will
`--python` argument can be used to request a Python version (e.g., `--python 3.12`), and uv will
search for an interpreter that meets the request. If uv finds a system interpreter (e.g., `/usr/lib/python3.12`),
then the `--system` flag is required to allow modification of this non-virtual Python environment.
Without the `--system` flag, uv will ignore any interpreters that are not in virtual environments.
@ -282,7 +282,7 @@ Using a password or token:
When using a GitHub personal access token, the username is arbitrary. GitHub does not support logging in with password directly, although other hosts may. If a username is provided without credentials, you will be prompted to enter them.
If there are no credentials present in the URL and authentication is needed, the [Git credential helper](https://git-scm.com/doc/credential-helpers) will be queried.
If there are no credentials present in the URL and authentication is needed, uv will query the [Git credential helper](https://git-scm.com/doc/credential-helpers).
### HTTP authentication

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(