Created
April 24, 2025 06:31
-
-
Save ruben-arts/dd8960eb6ee59562212f17179cee26aa to your computer and use it in GitHub Desktop.
Delete package variant using Prefix.dev api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S pixi exec --spec python==3.13 --spec requests -- python | |
import sys | |
import requests | |
# Prefix api token. | |
# Go to https://prefix.dev/settings/api_keys to generate one. | |
token = "pfx-BLABLABLA" | |
def delete(package_url: str): | |
""" | |
Delete a package by package_url e.g.:https://repo.prefix.dev/robostack-humble/linux-64/cartographer-2.0.0-lua54h1d18f75_8.tar.bz2 | |
REST API: DELETE /api/v1/delete/:channel/:subdir/:package_file_name | |
""" | |
# Strip host channel subdir and package | |
# e.g. https://repo.prefix.dev/robostack-humble/linux-64/cartographer-2.0.0-lua54h1d18f75_8.tar.bz2 | |
# host = https://prefix.dev | |
# channel = robostack-humble | |
# subdir = linux-64 | |
# package = cartographer-2.0.0-lua54h1d18f75_8.tar.bz2 | |
(host, rest)= package_url.split("prefix.dev") | |
host = host.replace("repo.", "") | |
host = host + "prefix.dev" | |
(channel, subdir, package) = rest.split("/")[1:4] | |
print("host: " + host) | |
# Error if it doesn't contain package style url | |
if not ".tar.bz2" in package_url and not ".conda" in package_url: | |
print(f"Invalid package url: {package_url} should contain .tar.bz2 or .conda") | |
return | |
url = f"{host}/api/v1/delete/{channel}/{subdir}/{package}" | |
headers = { | |
"Authorization": f"Bearer {token}", | |
} | |
print(f"Deleting package with url {url}") | |
r = requests.delete(url, headers=headers) | |
print(f"Deleted package with status code: '{r.status_code}' and response: '{r.text}'") | |
if __name__ == "__main__": | |
if len(sys.argv) > 1: | |
delete(sys.argv[1]) | |
else: | |
print("No package url found as argument, give a url e.g.: https://repo.prefix.dev/robostack-humble/linux-64/cartographer-2.0.0-lua54h1d18f75_8.tar.bz2") | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment