Skip to content

Apache DataFusion SQL Query Engine

ARROW-8941: [C++/Python] Add cleanup script for arrow-nightlies conda repository

Uwe L. Korn713e1f46eb59
diff --git a/dev/tasks/conda-recipes/azure.clean.yml b/dev/tasks/conda-recipes/azure.clean.yml
new file mode 100644
index 0000000000..af8262feac
--- /dev/null
+++ b/dev/tasks/conda-recipes/azure.clean.yml
@@ -0,0 +1,28 @@
+jobs:
+- job: linux
+ pool:
+ vmImage: ubuntu-18.04
+ timeoutInMinutes: 360
+
+ steps:
+ - script: |
+ git clone --no-checkout {{ arrow.remote }} arrow
+ git -C arrow fetch -t {{ arrow.remote }} {{ arrow.branch }}
+ git -C arrow checkout FETCH_HEAD
+ git -C arrow submodule update --init --recursive
+ displayName: Clone arrow
+
+ - script: |
+ conda install -y -c conda-forge pandas
+ displayName: Install requirements
+
+ - script: |
+ {% if arrow.branch == 'master' %}
+ mkdir -p $HOME/.continuum/anaconda-client/tokens/
+ echo $(CROSSBOW_ANACONDA_TOKEN) > $HOME/.continuum/anaconda-client/tokens/https%3A%2F%2Fapi.anaconda.org.token
+ {% endif %}
+ eval "$(conda shell.bash hook)"
+ conda activate base
+ python3 arrow/dev/tasks/conda-recipes/clean.py {% if arrow.branch == 'master' %}FORCE{% endif %}
+ displayName: Delete outdated packages
+
diff --git a/dev/tasks/conda-recipes/clean.py b/dev/tasks/conda-recipes/clean.py
new file mode 100644
index 0000000000..3bc007e2a8
--- /dev/null
+++ b/dev/tasks/conda-recipes/clean.py
@@ -0,0 +1,62 @@
+from distutils.version import LooseVersion
+from subprocess import check_output, check_call
+from typing import List
+
+import json
+import os
+import pandas as pd
+import sys
+
+
+VERSIONS_TO_KEEP = 5
+PLATFORMS = ["linux-64", "osx-64", "win-64"]
+PACKAGES = ["pyarrow", "arrow-cpp"]
+
+
+def packages_to_delete(package_name: str, platform: str) -> List[str]:
+ env = os.environ.copy()
+ env["CONDA_SUBDIR"] = platform
+ pkgs_json = check_output(
+ [
+ "conda",
+ "search",
+ "--json",
+ "-c",
+ "arrow-nightlies",
+ "--override-channels",
+ package_name,
+ ],
+ env=env,
+ )
+ pkgs = pd.DataFrame(json.loads(pkgs_json)[package_name])
+ pkgs["version"] = pkgs["version"].map(LooseVersion)
+ pkgs["py_version"] = pkgs["build"].str.slice(0, 4)
+
+ to_delete = []
+
+ for (subdir, python), group in pkgs.groupby(["subdir", "py_version"]):
+ group = group.sort_values(by="version", ascending=False)
+
+ if len(group) > VERSIONS_TO_KEEP:
+ del_candidates = group[VERSIONS_TO_KEEP:]
+ to_delete += (
+ f"arrow-nightlies/{package_name}/"
+ + del_candidates["version"].astype(str)
+ + del_candidates["url"].str.replace(
+ "https://conda.anaconda.org/arrow-nightlies", ""
+ )
+ ).to_list()
+
+ return to_delete
+
+
+if __name__ == "__main__":
+ to_delete = []
+ for platform in PLATFORMS:
+ for package in PACKAGES:
+ to_delete += packages_to_delete(package, platform)
+
+ for name in to_delete:
+ print(f"Deleting {name} …")
+ if "FORCE" in sys.argv:
+ check_call(["anaconda", "remove", name])
diff --git a/dev/tasks/tasks.yml b/dev/tasks/tasks.yml
index 0f91fc7449..f8f5b02044 100644
--- a/dev/tasks/tasks.yml
+++ b/dev/tasks/tasks.yml
@@ -122,6 +122,10 @@ tasks:
############################## Conda Linux ##################################
+ conda-clean:
+ ci: azure
+ template: conda-recipes/azure.clean.yml
+
conda-linux-gcc-py36:
ci: azure
template: conda-recipes/azure.linux.yml