-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpip_install.ado
183 lines (147 loc) · 4.31 KB
/
pip_install.ado
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*==================================================
project: utility to install pip easily
Author: R.Andres Castaneda
E-email: [email protected]
url:
Dependencies: The World Bank
----------------------------------------------------
Creation Date: 6 Oct 2022 - 18:43:11
Modification Date:
Do-file version: 01
References:
Output:
==================================================*/
/*==================================================
0: Program set up
==================================================*/
program define pip_install, rclass
version 16.1
syntax [anything(name=src)] ///
[, ///
username(string) ///
cmd(string) ///
version(string) ///
pause ///
replace ///
path(string) ///
]
if ("`pause'" == "pause") pause on
else pause off
if ("`cmd'" == "") {
local cmd pip
}
if ("`username'" == "") {
local username "worldbank"
}
/*==================================================
1: Search source
==================================================*/
qui pip_find_src, path(`path')
local osrc = "`r(src)'" // original or installed source
if ("`src'" == "") {
local src = "`osrc'"
}
//========================================================
// Uninstall
//========================================================
// number of pip versions installed
local trk_codes = "`r(trk_code)'"
local trk_srcs = `"`r(trk_sources)'"'
local path = "`r(path)'"
local ncodes: list sizeof trk_codes
if ("`src'" == "uninstall" | `ncodes' > 1) {
if (`ncodes' > 1) {
noi disp as err "There is more than one version of PIP installed" ///
" in the same search path, `path'." _n ///
"You need to uninstall {cmd:pip} in `path' or change installation path" ///
" with option {it:path()}" _n ///
"Type {it:yes} in the console and hit enter to confirm you agree to uninstall {cmd:pip}" _request(_confirm)
if ("`confirm'" != "yes") {
error
}
}
mata: pip_reverse_macro("trk_srcs")
mata: pip_reverse_macro("trk_codes")
gettoken sour trk_srcs: trk_srcs
gettoken code trk_codes: trk_codes
while ("`sour'" != "") {
if regexm(`"`sour'"', "repec") {
ado uninstall [`code']
}
else {
github uninstall [`code']
}
gettoken sour trk_srcs: trk_srcs
gettoken code trk_codes: trk_codes
}
if ("`sour'" == "") {
noi disp as text "{cmd:pip} was successfully uninstalled"
if ("`src'" == "uninstall") exit
}
else {
error
}
}
/*==================================================
Install
==================================================*/
if (inlist(lower("`src'"), "github", "gh")) {
local src "gh"
local source "GitHub"
local alt_src "ssc"
local alt_source "SSC"
}
else if (lower("`src'") == "ssc") {
local src "ssc"
local source "SSC"
local alt_src "gh"
local alt_source "GitHub"
}
else {
noi disp as error "source `src' is not available. Use either {it:gh} or {it:ssc}"
error
}
if ("`osrc'" == "ssc") {
cap ado uninstall pip
}
else {
cap github uninstall pip
}
if (_rc) {
if (_rc == 111) {
noi disp "package pip does not seems to be installed" // this should not ever happen
}
else {
error _rc
}
}
if ("`src'" == "gh") {
cap which github
if (_rc) {
net install github, from("https://haghish.github.io/github/")
}
cap noi github install `username'/`cmd', `replace' version(`version')
}
else {
cap noi ssc install pip, `replace'
}
if (_rc) {
noi disp as error _n "Something went wrong with the installation from `source'."
if ("`src'" == "gh") {
noi disp `"For troubleshooting, you can follow the instructions {browse "https://github.com/worldbank/pip#from-github":here}"'
}
noi disp "Alternatively, you could install {cmd:pip} from `alt_source'. Just type {stata pip_install `alt_src', replace}"
error
}
global pip_source = "`src'"
noi disp "You have successfully installed {cmd:pip} from `source'. " ///
"Please type {stata discard} to load the recently installed version"
end
exit
/* End of do-file */
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
Notes:
1.
2.
3.
Version Control: