Make the pip cache work with djangopypi2
Also add a test function that allows messing with the cache-creating
regex with some assurance that you're not trampling other people's
index-parsing.
Diff
1diff --git a/plugins/pip/pip.plugin.zsh b/plugins/pip/pip.plugin.zsh
2index 78532a6d3ca9513d6c4334ceda1265825ffd4094..71f977bbfcc810306adf7e04438424e191b3c9e1 100644
3--- a/plugins/pip/pip.plugin.zsh
4+++ b/plugins/pip/pip.plugin.zsh
5@@ -17,6 +17,10 @@ zsh-pip-clear-cache() {
6 unset piplist
7 }
8 9+zsh-pip-clean-packages() {
10+ sed -nr '/<a href/ s/.*>([^<]+).*/\1/p'
11+}
12+
13 zsh-pip-cache-packages() {
14 if [[ ! -d ${PIP_CACHE_FILE:h} ]]; then
15 mkdir -p ${PIP_CACHE_FILE:h}
16@@ -28,10 +32,47 @@ zsh-pip-cache-packages() {
17 for index in $ZSH_PIP_INDEXES ; do
18 # well... I've already got two problems
19 curl $index 2>/dev/null | \
20- sed -nr '/^<a href/ s/.*>([^<]+).*/\1/p' \
21+ zsh-pip-clean-packages \
22 >> $tmp_cache
23 done
24 sort $tmp_cache | uniq | tr '\n' ' ' > $ZSH_PIP_CACHE_FILE
25 rm $tmp_cache
26 fi
27 }
28+
29+# A test function that validates the regex against known forms of the simple
30+# index. If you modify the regex to make it work for you, you should add a test
31+# case in here and make sure that your changes don't break things for someone
32+# else.
33+zsh-pip-test-clean-packages() {
34+ local expected
35+ local actual
36+ expected="0x10c-asm
37+1009558_nester"
38+
39+ actual=$(echo -n "<html><head><title>Simple Index</title><meta name=\"api-version\" value=\"2\" /></head><body>
40+<a href='0x10c-asm'>0x10c-asm</a><br/>
41+<a href='1009558_nester'>1009558_nester</a><br/>
42+</body></html>" | zsh-pip-clean-packages)
43+
44+ if [[ $actual != $expected ]] ; then
45+ echo -e "python's simple index is broken:\n$actual\n !=\n$expected"
46+ else
47+ echo "python's simple index is fine"
48+ fi
49+
50+ actual=$(echo -n '<html>
51+ <head>
52+ <title>Simple Package Index</title>
53+ </head>
54+ <body>
55+ <a href="0x10c-asm">0x10c-asm</a><br/>
56+ <a href="1009558_nester">1009558_nester</a><br/>
57+</body></html>' | zsh-pip-clean-packages)
58+
59+ if [[ $actual != $expected ]] ; then
60+ echo -e "the djangopypi2 index is broken:\n$actual\n !=\n$expected"
61+ else
62+ echo "the djangopypi2 index is fine"
63+ fi
64+}