Skip to content

Commit

Permalink
feat: use uv build directly
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Oct 8, 2024
1 parent 6ca3376 commit cef541d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
17 changes: 8 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v4.0.0-alpha.8"
- repo: https://github.com/rbubley/mirrors-prettier
rev: "v3.3.3"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
Expand All @@ -47,13 +47,12 @@ repos:
files: src|tests
args: []
additional_dependencies:
[
"tomli",
"pathspec",
"importlib-resources",
"pytest",
"validate-pyproject",
]
- tomli
- pathspec
- importlib-resources
- pytest
- validate-pyproject
- uv

- repo: https://github.com/henryiii/check-sdist
rev: "v1.0.0"
Expand Down
9 changes: 2 additions & 7 deletions src/check_sdist/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import argparse
import contextlib
import importlib.util
import shutil
from collections.abc import Sequence
from pathlib import Path
from typing import Literal
Expand All @@ -15,7 +13,7 @@
from .git import git_files
from .inject import inject_junk_files
from .resources import resources
from .sdist import sdist_files
from .sdist import get_uv, sdist_files


def select_installer(
Expand All @@ -26,10 +24,7 @@ def select_installer(
or throws an error if uv was required and not available.
"""
if "uv" in installer:
if importlib.util.find_spec("uv") is not None:
return "uv"

if shutil.which("uv") is not None:
if get_uv() is not None:
return "uv"

if installer == "uv":
Expand Down
48 changes: 39 additions & 9 deletions src/check_sdist/sdist.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,58 @@
from __future__ import annotations

import shutil
import subprocess
import sys
import tarfile
import tempfile
from pathlib import Path
from typing import Literal

__all__ = ["get_uv", "sdist_files"]


def get_uv() -> str | None:
"""
Find uv and return the arguments to use it.
"""
try:
# pylint: disable-next=import-outside-toplevel
import uv

return uv.find_uv_bin()
except ModuleNotFoundError:
return shutil.which("uv")


def sdist_files(
source_dir: Path, *, isolated: bool, installer: Literal["uv", "pip"]
) -> frozenset[str]:
"""Return the files that would be (are) placed in the SDist."""

with tempfile.TemporaryDirectory() as outdir:
cmd = [
sys.executable,
"-m",
"build",
"--sdist",
"--outdir",
outdir,
f"--installer={installer}" if isolated else "--no-isolation",
]
if installer == "pip":
cmd = [
sys.executable,
"-m",
"build",
"--sdist",
"--outdir",
outdir,
f"--installer={installer}" if isolated else "--no-isolation",
]
else:
uv = get_uv()
assert uv is not None, "uv must be found to reach this point!"
cmd = [
uv,
"build",
"--sdist",
"--python",
sys.executable,
"--out-dir",
outdir,
]

subprocess.run(cmd, check=True, cwd=source_dir)

(outpath,) = Path(outdir).glob("*.tar.gz")
Expand Down

0 comments on commit cef541d

Please sign in to comment.