1
1
import importlib
2
+ import logging
2
3
import os
3
- import shutil
4
4
import subprocess
5
5
import sys
6
6
import tempfile
@@ -20,7 +20,7 @@ def __init__(self, tmp_dir):
20
20
self .reset ()
21
21
22
22
def tmp_file_path (self , filename ) -> Path :
23
- "Return a Path object pointing to named file in tmp_dir."
23
+ """ Return a Path object pointing to named file in tmp_dir."" "
24
24
return Path (self .tmp_dir ) / filename
25
25
26
26
def tmp_file_content (self , filename ):
@@ -42,7 +42,6 @@ def stub_command(self, cmdname, commands_map: Dict[str, str]):
42
42
{'serverless registry-info --url "url" --api-token "token"':
43
43
'AWS_ECR_USERNAME=username\n AWS_ECR_PASSWORD=password\n '})
44
44
"""
45
-
46
45
command_stub .generate (str (self .tmp_file_path (cmdname )), commands_map )
47
46
48
47
def prepare_run_script (self , command : str , target_tmp_dir = None ) -> Path :
@@ -72,13 +71,11 @@ def prepare_run_script(self, command: str, target_tmp_dir=None) -> Path:
72
71
main_script .write ("export PATH=.:$PATH\n " )
73
72
74
73
# invoke main command
75
- main_script .write (
76
- command + " > ./output-stdout.txt 2> ./output-stderr.txt\n "
77
- )
74
+ main_script .write (command + " > ./output-stdout.txt 2> ./output-stderr.txt\n " )
78
75
79
76
# save returncode and final env vars
80
- main_script .write (f "echo $? > ./output-exitcode.txt\n " )
81
- main_script .write (f "env > ./output-env.txt\n " )
77
+ main_script .write ("echo $? > ./output-exitcode.txt\n " )
78
+ main_script .write ("env > ./output-env.txt\n " )
82
79
83
80
os .chmod (script_path , 0o700 )
84
81
return script_path
@@ -170,10 +167,10 @@ def repo_root():
170
167
171
168
@pytest .fixture (scope = "session" )
172
169
def action_docker_image_id (repo_root ):
173
- "Build a docker image using local source and return the tag"
170
+ """ Build a docker image using local source and return the tag"" "
174
171
_ , iidfile = tempfile .mkstemp ()
175
172
try :
176
- proc = subprocess .run (
173
+ subprocess .run (
177
174
[
178
175
"docker" ,
179
176
"buildx" ,
@@ -187,22 +184,24 @@ def action_docker_image_id(repo_root):
187
184
],
188
185
cwd = repo_root ,
189
186
check = True ,
190
- capture_output = True ,
191
187
)
192
188
return open (iidfile ).read ().strip ()
193
189
finally :
194
- os .remove (iidfile )
190
+ try :
191
+ os .remove (iidfile )
192
+ except OSError :
193
+ logging .exception (f"Failed to remove { iidfile } " )
195
194
196
195
197
196
@pytest .fixture (scope = "session" )
198
197
def dagster_cloud_pex_path (repo_root ):
199
- "Path to generated/gha/dagster-cloud.pex."
198
+ """ Path to generated/gha/dagster-cloud.pex."" "
200
199
yield repo_root / "generated/gha/dagster-cloud.pex"
201
200
202
201
203
202
@pytest .fixture (scope = "session" )
204
203
def builder_module (dagster_cloud_pex_path ):
205
- "Imported builder module object, for in-process testing of builder code."
204
+ """ Imported builder module object, for in-process testing of builder code."" "
206
205
# This contains the same code as the builder.pex, but using it as a module
207
206
# makes patching easier. To make sure we use the same dependencies that are
208
207
# packed in builder.pex, we unpack builder.pex to a venv and add the venv
@@ -234,9 +233,7 @@ def pex_registry_fixture():
234
233
s3_objects = {} # filename -> content
235
234
236
235
def s3_urls_for_get (filenames ):
237
- return [
238
- (filename if filename in s3_objects else None ) for filename in filenames
239
- ]
236
+ return [(filename if filename in s3_objects else None ) for filename in filenames ]
240
237
241
238
def s3_urls_for_put (filenames ):
242
239
return filenames
@@ -263,9 +260,5 @@ def requests_put(url, data):
263
260
) as _ , mock .patch (
264
261
"dagster_cloud_cli.core.pex_builder.pex_registry.get_s3_urls_for_put" ,
265
262
s3_urls_for_put ,
266
- ) as _ , mock .patch (
267
- "requests.get" , requests_get
268
- ) as _ , mock .patch (
269
- "requests.put" , requests_put
270
- ):
263
+ ) as _ , mock .patch ("requests.get" , requests_get ) as _ , mock .patch ("requests.put" , requests_put ):
271
264
yield s3_objects
0 commit comments