raylu 5 months ago
parent
commit
e1c2f47a1d
2 changed files with 29 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 27 0
      install_extras.py

+ 2 - 0
.gitignore

@@ -9,5 +9,7 @@
 /lazygit
 /oh-my-posh
 /starship
+/uv
+/uvx
 /ya
 /yazi

+ 27 - 0
install_extras.py

@@ -25,6 +25,7 @@ def main():
 	lazygit()
 	oh_my_posh()
 	#starship()
+	uv()
 	yazi()
 
 def bat():
@@ -267,6 +268,32 @@ def starship():
 		tar.extract('starship', CURRENT_DIR)
 	tarball_path.unlink()
 
+def uv():
+	if (CURRENT_DIR / 'uv').exists():
+		print_gray('uv already downloaded')
+		return
+	if which := shutil.which('uv'):
+		print_gray('uv already at ' + which)
+		return
+
+	client = httpx.Client()
+	os = platform.system().lower()
+	arch = platform.machine()
+	if arch == 'darwin':
+		prefix = f'uv-{arch}-apple-darwin'
+	else:
+		prefix = f'uv-{arch}-unknown-linux-gnu'
+	url = f'https://github.com/astral-sh/uv/releases/latest/download/{prefix}.tar.gz'
+	tarball_path = CURRENT_DIR / 'uv.tar.gz'
+	download(client, url, tarball_path)
+	with tarfile.open(tarball_path, 'r:gz') as tar:
+		for filename in ['uv', 'uvx']:
+			target_path = CURRENT_DIR / filename
+			with tar.extractfile(f'{prefix}/{filename}') as binary, target_path.open('wb') as f: # pyright: ignore[reportOptionalContextManager]
+				shutil.copyfileobj(binary, f)
+			target_path.chmod(0o755)
+	tarball_path.unlink()
+
 def yazi():
 	if platform.system() == 'Darwin':
 		print('$ brew install yazi')