Skip to content

Commit

Permalink
Test out uv
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Jul 1, 2024
1 parent 24aa7d8 commit 4f3bbad
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 45 deletions.
5 changes: 5 additions & 0 deletions komodo/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ def make(
fakeroot=".",
):
pkgorder = list(pkgs.keys())
# We only need to ensure that python is 'installed' first
pkgorder.remove("python")
pkgorder.insert(0, "python")
assert pkgorder[0] == "python"

fakeprefix = fakeroot + prefix
shell(["mkdir -p", fakeprefix])
prefix = os.path.abspath(prefix)
Expand Down
53 changes: 17 additions & 36 deletions komodo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def download_packages(
repository_file_content: Mapping[str, Mapping[str, Union[str, Sequence[str]]]],
download_destination: str,
pip_executable: str = "pip",
) -> Dict[str, str]:
):
"""Downloads all PyPI packages to destination. Tries to download other
packages to destination too.
Git packages are collected, and a dict of all git hashes is returned.
Expand All @@ -151,14 +151,14 @@ def download_packages(
--
Dict of git hashes found
"""
git_hashes = fetch(
git_hashes, pypi_packages = fetch(
release_file_content,
repository_file_content,
outdir=download_destination,
pip=pip_executable,
)

return git_hashes
return git_hashes, pypi_packages


@profile_time("Building non-pip part of komodo in workspace")
Expand Down Expand Up @@ -270,36 +270,20 @@ def apply_fallback_tmpdir_for_pip_if_set(tmp_dir: Optional[str] = None):

@profile_time("pip install to final destination")
def install_previously_downloaded_pip_packages(
release_file_content: Mapping[str, str],
repository_file_content: Mapping[str, Mapping[str, Union[str, Sequence[str]]]],
downloads_directory: str,
pip_executable: str,
pypi_packages: list[str],
release_root: Path,
) -> None:
for pkg, ver in release_file_content.items():
current = repository_file_content[pkg][ver]
if current["make"] != "pip":
continue

package_name = current.get("pypi_package_name", pkg)
if ver == LATEST_PACKAGE_ALIAS:
ver = latest_pypi_version(package_name)
shell_input = [
pip_executable,
f"install {package_name}=={strip_version(ver)}",
"--prefix",
str(release_root),
"--no-index",
"--no-deps",
"--ignore-installed",
"--no-compile",
# assuming fetch.py has done "pip download" to this directory:
f"--cache-dir {downloads_directory}",
f"--find-links {downloads_directory}",
]
shell_input.append(current.get("makeopts"))

print(shell(shell_input))
shell_input = [
"uv pip",
"install",
f"--python {str(release_root / 'bin' / 'python')}",
"--no-deps",
"--no-cache",
"--reinstall",
" ".join(pypi_packages),
]

print(shell(shell_input))


def run_post_installation_scripts_if_set(
Expand Down Expand Up @@ -349,7 +333,7 @@ def _main(args: KomodoNamespace) -> None:
data = Data(extra_data_dirs=args.extra_data_dirs)
git_hashes = None
if args.download or (not args.build and not args.install):
git_hashes = download_packages(
git_hashes, pypi_packages = download_packages(
args.pkgs.content,
args.repo.content,
download_destination=args.downloads,
Expand Down Expand Up @@ -391,10 +375,7 @@ def _main(args: KomodoNamespace) -> None:
apply_fallback_tmpdir_for_pip_if_set(args.tmp)

install_previously_downloaded_pip_packages(
args.pkgs.content,
args.repo.content,
downloads_directory=args.downloads,
pip_executable=args.pip,
pypi_packages,
release_root=release_root,
)
fixup_python_shebangs(args.prefix, args.release)
Expand Down
12 changes: 5 additions & 7 deletions komodo/data/setup-py.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ while test $# -gt 0; do
done

unset DESTDIR
$PIP install $OPTS . \
--ignore-installed \
--root $FAKEROOT \
--no-deps \
--no-cache-dir \
--no-compile \
--prefix $PREFIX 1>&2
uv pip install \
--python $FAKEROOT/$PREFIX/bin/python \
--no-deps \
--no-cache \
--reinstall . \
4 changes: 2 additions & 2 deletions komodo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ def fetch(pkgs, repo, outdir, pip="pip") -> dict:
os.symlink(normalised_dir, pkgname)

print(f"Downloading {len(pypi_packages)} pypi packages")
shell([pip, "download", "--no-deps", "--dest .", " ".join(pypi_packages)])
# shell([pip, "download", "--no-deps", "--dest .", " ".join(pypi_packages)])

return git_hashes
return git_hashes, pypi_packages


if __name__ == "__main__":
Expand Down

0 comments on commit 4f3bbad

Please sign in to comment.