Skip to content

Instantly share code, notes, and snippets.

@astrofrog
Created July 6, 2022 12:31
Show Gist options
  • Save astrofrog/868f8fa81182a69b3bbb677ce0e01c82 to your computer and use it in GitHub Desktop.
Save astrofrog/868f8fa81182a69b3bbb677ce0e01c82 to your computer and use it in GitHub Desktop.
# Remove all but the latest N versions from wheels on Anaconda.org
# Usefult to avoid building up too many files when uploading
# developer wheels.
from binstar_client.utils import get_server_api
KEEP_N_LATEST = 10
api = get_server_api(token=<TOKEN>)
package = api.package("astropy", "astropy")
# Find versions for which wheels are available
pypi_versions = set()
for file_info in package["files"]:
if file_info["type"] == "pypi":
pypi_versions.add(file_info["version"])
pypi_versions = sorted(pypi_versions)
# Determine versions to remove
versions_to_remove = pypi_versions[:-KEEP_N_LATEST]
# Remove the files
for file_info in package["files"]:
if file_info["version"] in versions_to_remove:
print(f"Removing {file_info['basename']}")
api.remove_dist(
"astropy",
"astropy",
file_info["version"],
basename=file_info["basename"]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment