Skip to content

Commit fd26801

Browse files
committed
Avoid GitHub API for AlphaMap installer data
1 parent 11e42bb commit fd26801

3 files changed

Lines changed: 37 additions & 53 deletions

File tree

release/common/download_installer_data.sh

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,29 @@ INSTALLER_DATA_DIR=${INSTALLER_DATA_DIR:-build_pyinstaller_data}
55
ALPHAMAP_DATA_DIR="${INSTALLER_DATA_DIR}/alphamap/data"
66
ALPHAQUANT_RESOURCES_DIR="${INSTALLER_DATA_DIR}/alphaquant/resources"
77

8-
curl_github() {
8+
curl_with_retries() {
99
local args=(
1010
-L
1111
-f
1212
--retry 3
1313
--retry-delay 2
14-
-H "Accept: application/vnd.github+json"
1514
-H "User-Agent: alphaquant-release-build"
1615
)
1716

18-
local github_token="${GITHUB_TOKEN:-${GH_TOKEN:-}}"
19-
if [ -n "$github_token" ]; then
20-
args+=(-H "Authorization: Bearer ${github_token}")
21-
fi
22-
2317
curl "${args[@]}" "$@"
2418
}
2519

26-
extract_alphamap_data_urls() {
27-
python -c 'import json, sys
28-
for item in json.load(sys.stdin):
29-
name = item.get("name", "")
30-
url = item.get("download_url")
31-
if url and name.endswith((".fasta", ".csv")):
32-
print(url)'
20+
list_alphamap_data_downloads() {
21+
python -c 'from urllib.parse import quote
22+
from alphamap.organisms_data import all_organisms
23+
base_url = "https://raw.githubusercontent.com/MannLabs/alphamap/main/alphamap/data/"
24+
seen = set()
25+
for organism in all_organisms.values():
26+
for key in ("fasta_name", "uniprot_name"):
27+
name = organism[key]
28+
if name not in seen:
29+
seen.add(name)
30+
print(f"{name}\t{base_url}{quote(name)}")'
3331
}
3432

3533
download_datashare_zip() {
@@ -39,7 +37,7 @@ download_datashare_zip() {
3937

4038
temp_zip=$(mktemp)
4139
echo "Downloading ${label} from datashare..."
42-
if ! curl -L -f --retry 3 --retry-delay 2 "${url}" -o "${temp_zip}"; then
40+
if ! curl_with_retries "${url}" -o "${temp_zip}"; then
4341
echo "Error: Failed to download ${label} from datashare"
4442
rm -f "${temp_zip}"
4543
exit 1
@@ -54,22 +52,15 @@ rm -rf "${INSTALLER_DATA_DIR}"
5452
mkdir -p "${ALPHAMAP_DATA_DIR}" "${ALPHAQUANT_RESOURCES_DIR}"
5553

5654
echo "Downloading AlphaMap FASTA and CSV files..."
57-
if ! DOWNLOAD_LIST=$(curl_github https://api.github.com/repos/MannLabs/alphamap/contents/alphamap/data?ref=main); then
58-
echo "Error: Failed to fetch AlphaMap file list from GitHub API"
59-
exit 1
60-
fi
61-
62-
echo "$DOWNLOAD_LIST" | \
63-
extract_alphamap_data_urls | \
64-
while read url; do
65-
if [ -z "$url" ]; then
55+
list_alphamap_data_downloads | \
56+
while IFS=$'\t' read -r filename url; do
57+
if [ -z "$filename" ] || [ -z "$url" ]; then
6658
echo "Warning: Empty URL detected, skipping..."
6759
continue
6860
fi
6961

70-
filename=$(basename "$url")
7162
echo "Downloading ${filename}..."
72-
if ! curl_github "$url" -o "${ALPHAMAP_DATA_DIR}/${filename}"; then
63+
if ! curl_with_retries "$url" -o "${ALPHAMAP_DATA_DIR}/${filename}"; then
7364
echo "Error: Failed to download ${filename}"
7465
exit 1
7566
fi

release/macos/build_package_macos.sh

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,29 @@ PACKAGE_NAME=alphaquant
88
# BUILD_NAME is taken from environment variables, e.g. alphaquant-1.2.3-macos-darwin-arm64 or alphaquant-1.2.3-macos-darwin-x64
99
rm -rf ${BUILD_NAME}.pkg
1010

11-
curl_github() {
11+
curl_with_retries() {
1212
local args=(
1313
-L
1414
-f
1515
--retry 3
1616
--retry-delay 2
17-
-H "Accept: application/vnd.github+json"
1817
-H "User-Agent: alphaquant-release-build"
1918
)
2019

21-
local github_token="${GITHUB_TOKEN:-${GH_TOKEN:-}}"
22-
if [ -n "$github_token" ]; then
23-
args+=(-H "Authorization: Bearer ${github_token}")
24-
fi
25-
2620
curl "${args[@]}" "$@"
2721
}
2822

29-
extract_alphamap_data_urls() {
30-
python -c 'import json, sys
31-
for item in json.load(sys.stdin):
32-
name = item.get("name", "")
33-
url = item.get("download_url")
34-
if url and name.endswith((".fasta", ".csv")):
35-
print(url)'
23+
list_alphamap_data_downloads() {
24+
python -c 'from urllib.parse import quote
25+
from alphamap.organisms_data import all_organisms
26+
base_url = "https://raw.githubusercontent.com/MannLabs/alphamap/main/alphamap/data/"
27+
seen = set()
28+
for organism in all_organisms.values():
29+
for key in ("fasta_name", "uniprot_name"):
30+
name = organism[key]
31+
if name not in seen:
32+
seen.add(name)
33+
print(f"{name}\t{base_url}{quote(name)}")'
3634
}
3735

3836
# If needed, include additional source such as e.g.:
@@ -63,21 +61,14 @@ mkdir -p ${CONTENTS_FOLDER}/Frameworks/alphamap/data/
6361
####
6462
####Download all AlphaMap FASTA and CSV files from GitHub, which are needed for the further analyses. There is a lot of error checking to ensure that the files get actually added during the build
6563
echo "Starting downloads of FASTA and CSV files..."
66-
if ! DOWNLOAD_LIST=$(curl_github https://api.github.com/repos/MannLabs/alphamap/contents/alphamap/data?ref=main); then
67-
echo "Error: Failed to fetch file list from GitHub API"
68-
exit 1
69-
fi
70-
71-
echo "$DOWNLOAD_LIST" | \
72-
extract_alphamap_data_urls | \
73-
while read url; do
74-
if [ -z "$url" ]; then
64+
list_alphamap_data_downloads | \
65+
while IFS=$'\t' read -r filename url; do
66+
if [ -z "$filename" ] || [ -z "$url" ]; then
7567
echo "Warning: Empty URL detected, skipping..."
7668
continue
7769
fi
78-
filename=$(basename $url)
7970
echo "Downloading $filename..."
80-
if ! curl_github "$url" -o "${CONTENTS_FOLDER}/Frameworks/alphamap/data/$filename"; then
71+
if ! curl_with_retries "$url" -o "${CONTENTS_FOLDER}/Frameworks/alphamap/data/$filename"; then
8172
echo "Error: Failed to download $filename"
8273
exit 1
8374
fi
@@ -101,7 +92,7 @@ mkdir -p ${CONTENTS_FOLDER}/MacOS/_internal/alphaquant/resources/
10192
# Download and extract the first zip file
10293
echo "Downloading and extracting first resource from datashare..."
10394
TEMP_ZIP1=$(mktemp)
104-
if ! curl -L -f "https://datashare.biochem.mpg.de/s/ezPzeqStEgDD8gg/download" -o "$TEMP_ZIP1"; then
95+
if ! curl_with_retries "https://datashare.biochem.mpg.de/s/ezPzeqStEgDD8gg/download" -o "$TEMP_ZIP1"; then
10596
echo "Error: Failed to download first resource from datashare"
10697
exit 1
10798
fi
@@ -112,7 +103,7 @@ rm "$TEMP_ZIP1"
112103
# Download and extract the second zip file
113104
echo "Downloading and extracting second resource from datashare..."
114105
TEMP_ZIP2=$(mktemp)
115-
if ! curl -L -f "https://datashare.biochem.mpg.de/s/stH9pmNe6O9CRHG/download" -o "$TEMP_ZIP2"; then
106+
if ! curl_with_retries "https://datashare.biochem.mpg.de/s/stH9pmNe6O9CRHG/download" -o "$TEMP_ZIP2"; then
116107
echo "Error: Failed to download second resource from datashare"
117108
exit 1
118109
fi

release/pyinstaller/alphaquant.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ hidden_imports = [h for h in hidden_imports if "__pycache__" not in h]
4545
datas = [d for d in datas if ("__pycache__" not in d[0]) and (d[1] not in [".", "Resources", "scripts"])]
4646

4747
installer_data_dir = Path(os.environ.get("INSTALLER_DATA_DIR", "build_pyinstaller_data"))
48+
if not installer_data_dir.is_absolute():
49+
installer_data_dir = Path(location) / installer_data_dir
4850
for source_root, destination_root in (
4951
(installer_data_dir / "alphamap" / "data", Path("alphamap") / "data"),
5052
(installer_data_dir / "alphaquant" / "resources", Path("alphaquant") / "resources"),

0 commit comments

Comments
 (0)