12
12
EXT_ROOT = pathlib .Path (__file__ ).parent
13
13
14
14
15
+ def delete_dir (path : pathlib .Path , ignore_errors = None ):
16
+ attempt = 0
17
+ known = []
18
+ while attempt < 5 :
19
+ try :
20
+ shutil .rmtree (os .fspath (path ), ignore_errors = ignore_errors )
21
+ return
22
+ except PermissionError as pe :
23
+ if os .fspath (pe .filename ) in known :
24
+ break
25
+ print (f"Changing permissions on { pe .filename } " )
26
+ os .chmod (pe .filename , 0o666 )
27
+
28
+ shutil .rmtree (os .fspath (path ))
29
+
15
30
@nox .session ()
16
31
def install_python_libs (session : nox .Session ):
17
32
requirements = [
@@ -48,6 +63,45 @@ def install_python_libs(session: nox.Session):
48
63
if pathlib .Path ("./python_files/lib/temp" ).exists ():
49
64
shutil .rmtree ("./python_files/lib/temp" )
50
65
66
+ @nox .session ()
67
+ def azure_pet_checkout (session : nox .Session ):
68
+ branch = os .getenv ("PYTHON_ENV_TOOLS_REF" , "main" )
69
+
70
+ # dest dir should be <vscode-python repo root>/python-env-tools
71
+ dest_dir = (pathlib .Path (os .getenv ("PYTHON_ENV_TOOLS_DEST" )) / "python-env-tools" ).resolve ()
72
+
73
+ # temp dir should be <agent temp dir>
74
+ temp_dir = (pathlib .Path (os .getenv ("PYTHON_ENV_TOOLS_TEMP" )) / "python-env-tools" ).resolve ()
75
+ session .log (f"Cloning python-environment-tools to { temp_dir } " )
76
+ temp_dir .mkdir (0o766 , parents = True , exist_ok = True )
77
+
78
+ try :
79
+ with session .cd (temp_dir ):
80
+ session .run ("git" , "init" , external = True )
81
+ session .run (
82
+ "git" ,
83
+ "remote" ,
84
+ "add" ,
85
+ "origin" ,
86
+ "https://github.com/microsoft/python-environment-tools" ,
87
+ external = True ,
88
+ )
89
+ session .run ("git" , "fetch" , "origin" , branch , external = True )
90
+ session .run (
91
+ "git" , "checkout" , "--force" , "-B" , branch , f"origin/{ branch } " , external = True
92
+ )
93
+ delete_dir (temp_dir / ".git" )
94
+ delete_dir (temp_dir / ".github" )
95
+ delete_dir (temp_dir / ".vscode" )
96
+ (temp_dir / "CODE_OF_CONDUCT.md" ).unlink ()
97
+ shutil .move (os .fspath (temp_dir ), os .fspath (dest_dir ))
98
+ except PermissionError as e :
99
+ print (f"Permission error: { e } " )
100
+ if not dest_dir .exists ():
101
+ raise
102
+ finally :
103
+ delete_dir (temp_dir , ignore_errors = True )
104
+
51
105
52
106
@nox .session ()
53
107
def azure_pet_build_before (session : nox .Session ):
@@ -132,37 +186,19 @@ def native_build(session: nox.Session):
132
186
vscode_ignore .write_text ("\n " .join (filtered_lines ) + "\n " , encoding = "utf-8" )
133
187
134
188
135
- def delete_dir (path : pathlib .Path , ignore_errors = None ):
136
- attempt = 0
137
- known = []
138
- while attempt < 5 :
139
- try :
140
- shutil .rmtree (os .fspath (path ), ignore_errors = ignore_errors )
141
- return
142
- except PermissionError as pe :
143
- if os .fspath (pe .filename ) in known :
144
- break
145
- print (f"Changing permissions on { pe .filename } " )
146
- os .chmod (pe .filename , 0o666 )
147
-
148
- shutil .rmtree (os .fspath (path ))
149
-
150
-
151
189
@nox .session ()
152
190
def checkout_native (session : nox .Session ):
153
191
dest = (pathlib .Path .cwd () / "python-env-tools" ).resolve ()
154
192
if dest .exists ():
155
193
shutil .rmtree (os .fspath (dest ))
156
194
157
- tempdir = os .getenv ("TEMP" ) or os .getenv ("TMP" ) or "/tmp"
158
- tempdir = pathlib .Path (tempdir ) / str (uuid .uuid4 ()) / "python-env-tools"
159
- tempdir .mkdir (0o666 , parents = True )
160
-
161
- session .log (f"Temp dir: { tempdir } " )
195
+ temp_dir = os .getenv ("TEMP" ) or os .getenv ("TMP" ) or "/tmp"
196
+ temp_dir = pathlib .Path (temp_dir ) / str (uuid .uuid4 ()) / "python-env-tools"
197
+ temp_dir .mkdir (0o766 , parents = True )
162
198
163
- session .log (f"Cloning python-environment-tools to { tempdir } " )
199
+ session .log (f"Cloning python-environment-tools to { temp_dir } " )
164
200
try :
165
- with session .cd (tempdir ):
201
+ with session .cd (temp_dir ):
166
202
session .run ("git" , "init" , external = True )
167
203
session .run (
168
204
"git" ,
@@ -176,17 +212,17 @@ def checkout_native(session: nox.Session):
176
212
session .run (
177
213
"git" , "checkout" , "--force" , "-B" , "main" , "origin/main" , external = True
178
214
)
179
- delete_dir (tempdir / ".git" )
180
- delete_dir (tempdir / ".github" )
181
- delete_dir (tempdir / ".vscode" )
182
- (tempdir / "CODE_OF_CONDUCT.md" ).unlink ()
183
- shutil .move (os .fspath (tempdir ), os .fspath (dest ))
215
+ delete_dir (temp_dir / ".git" )
216
+ delete_dir (temp_dir / ".github" )
217
+ delete_dir (temp_dir / ".vscode" )
218
+ (temp_dir / "CODE_OF_CONDUCT.md" ).unlink ()
219
+ shutil .move (os .fspath (temp_dir ), os .fspath (dest ))
184
220
except PermissionError as e :
185
221
print (f"Permission error: { e } " )
186
222
if not dest .exists ():
187
223
raise
188
224
finally :
189
- delete_dir (tempdir .parent , ignore_errors = True )
225
+ delete_dir (temp_dir .parent , ignore_errors = True )
190
226
191
227
192
228
@nox .session ()
0 commit comments