-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathupdate_deps.sh
More file actions
executable file
·125 lines (104 loc) · 3.73 KB
/
update_deps.sh
File metadata and controls
executable file
·125 lines (104 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
# This script updates the panseg-dev conda environment and its yaml file.
# Only pinned packages stay pinned.
# The `environment.yaml` file gets updated from the dev environment.
# Both files can contain non-pinned packages.
# Please don't forget to update the conda-recipe/meta.yaml
ENV_FILE="environment.yaml"
DEV_ENV_FILE="environment-dev.yaml"
conda update -n panseg-dev --all
conda export --from-history --no-builds -n panseg-dev -f $DEV_ENV_FILE
# remove the prefix line
head -n -1 $DEV_ENV_FILE >temp_env.yaml && mv temp_env.yaml $DEV_ENV_FILE
cat >>environment-dev.yaml <<'EOF'
- pip:
- markdown-exec
- -e .
EOF
TEMP_ENV="tmp"
# Create associative arrays to store package information
declare -A dev_packages
# Extract packages from environment-dev.yaml into associative arrays
echo "DEBUG: Reading packages from $DEV_ENV_FILE" >&2
while IFS= read -r line; do
# Check if we've reached the pip section
if [[ "$line" =~ ^[[:space:]]*-[[:space:]]pip: ]]; then
echo "DEBUG: Reached pip section in dev environment" >&2
break
fi
# Check if we're in the dependencies section
if [[ "$line" =~ ^[[:space:]]*dependencies:[[:space:]]*$ ]]; then
echo "DEBUG: Entering dependencies section in dev environment" >&2
in_deps=true
continue
fi
# Skip lines that aren't in dependencies or are pip section
if [[ ! "$line" =~ ^[[:space:]]*- ]] || [[ ! "${in_deps:-false}" == true ]]; then
continue
fi
# Extract package name from line
package_line="${line#*-[[:space:] ]}"
package_line="${package_line%%[[:space:]]*}"
# Extract just the package name part (before =, <, >)
pkg_name=""
if [[ "$package_line" =~ ^([^=<>]+) ]]; then
pkg_name="${BASH_REMATCH[1]}"
fi
# Only process if we have a valid package name
if [[ -n "$pkg_name" ]]; then
# Store the full package line
dev_packages["$pkg_name"]="$line"
echo "DEBUG: Stored package $pkg_name from dev environment" >&2
fi
done <"$DEV_ENV_FILE"
# Process environment.yaml and update matching packages
echo "DEBUG: Processing main environment file $ENV_FILE" >&2
{
in_deps=false
in_pip=false
while IFS= read -r line; do
# Check if we've reached the pip section
if [[ "$line" =~ ^[[:space:]]*-[[:space:]]pip: ]]; then
echo "DEBUG: Reached pip section in main environment" >&2
in_pip=true
echo "$line"
continue
fi
# Check if we're entering dependencies section
if [[ "$line" =~ ^[[:space:]]*dependencies:[[:space:]]*$ ]]; then
echo "DEBUG: Entering dependencies section in main environment" >&2
in_deps=true
echo "$line"
continue
fi
# If we're in pip section, just print the line
if [[ "${in_pip:-false}" == true ]]; then
echo "$line"
continue
fi
# Check if we're in dependencies and have a package line
if [[ "${in_deps:-false}" == true ]] && [[ "$line" =~ ^[[:space:]]*- ]]; then
# Extract package name from line
package_line="${line#*-[[:space:] ]}"
package_line="${package_line%%[[:space:]]*}"
# Extract just the package name part (before =, <, >)
pkg_name=""
if [[ "$package_line" =~ ^([^=<>]+) ]]; then
pkg_name="${BASH_REMATCH[1]}"
fi
# If this matches a package from environment-dev.yaml, use the environment-dev.yaml version
if [[ -n "$pkg_name" ]] && [[ -n "${dev_packages[$pkg_name]}" ]]; then
echo "DEBUG: Updating package $pkg_name from dev version: ${dev_packages[$pkg_name]}" >&2
echo "${dev_packages[$pkg_name]}"
else
echo "$line"
fi
else
echo "$line"
fi
done <"$ENV_FILE"
} >"$TEMP_ENV"
# Replace original file
echo "DEBUG: Replacing original file with updated content" >&2
mv "$TEMP_ENV" "$ENV_FILE"
echo "Sync complete!"