@@ -28,25 +28,34 @@ def list_changed_files(from_ref: str, to_ref: str) -> list[str]:
28
28
return files
29
29
30
30
31
- def get_build_directory (make_target ) -> str :
32
- directories = []
31
+ def _query_build (make_target : str , query : str ) -> str :
32
+ results = []
33
33
34
- pattern = re .compile (r"#\*# Image build directory : <(?P<dir >[^>]+)> #\(MACHINE-PARSED LINE\)#\*#\.\.\." )
34
+ pattern = re .compile (r"#\*# " + query + r" : <(?P<result >[^>]+)> #\(MACHINE-PARSED LINE\)#\*#\.\.\." )
35
35
try :
36
36
logging .debug (f"Running make in --just-print mode for target { make_target } " )
37
37
for line in subprocess .check_output ([MAKE , make_target , "--just-print" ], encoding = "utf-8" ,
38
38
cwd = PROJECT_ROOT ).splitlines ():
39
39
if m := pattern .match (line ):
40
- directories .append (m ["dir " ])
40
+ results .append (m ["result " ])
41
41
except subprocess .CalledProcessError as e :
42
42
print (e .stderr , e .stdout )
43
43
raise
44
44
45
- if len (directories ) != 1 :
46
- raise Exception (f"Expected a single build directory for target '{ make_target } ': { directories } " )
45
+ if len (results ) != 1 :
46
+ raise Exception (f"Expected a single query result for target '{ make_target } ': { results } " )
47
+
48
+ logging .debug (f"Target { make_target } builds from { results [0 ]} " )
49
+ return results [0 ]
50
+
51
+
52
+ def get_build_directory (make_target ) -> str :
53
+ return _query_build (make_target , "Image build directory" )
54
+
55
+
56
+ def get_build_dockerfile (make_target ) -> str :
57
+ return _query_build (make_target , "Image build Dockerfile" )
47
58
48
- logging .debug (f"Target { make_target } buildes from { directories [0 ]} " )
49
- return directories [0 ]
50
59
51
60
def find_dockerfiles (directory : str ) -> list :
52
61
"""Finds and returns a list of files matching the pattern 'Dockerfile*' in the specified directory."""
@@ -67,10 +76,9 @@ def should_build_target(changed_files: list[str], target_directory: str) -> str:
67
76
return changed_file
68
77
# detect change in any of the files outside
69
78
dockerfiles = find_dockerfiles (target_directory )
70
- results = ""
71
79
for dockerfile in dockerfiles :
72
80
stdout = subprocess .check_output ([PROJECT_ROOT / "bin/buildinputs" , target_directory + "/" + dockerfile ],
73
- text = True , cwd = PROJECT_ROOT )
81
+ text = True , cwd = PROJECT_ROOT )
74
82
logging .debug (f"{ target_directory = } { dockerfile = } { stdout = } " )
75
83
if stdout == "\n " :
76
84
# no dependencies
@@ -106,5 +114,9 @@ def test_get_build_directory(self):
106
114
directory = get_build_directory ("rocm-jupyter-pytorch-ubi9-python-3.11" )
107
115
assert directory == "jupyter/rocm/pytorch/ubi9-python-3.11"
108
116
117
+ def test_get_build_dockerfile (self ):
118
+ dockerfile = get_build_dockerfile ("rocm-jupyter-pytorch-ubi9-python-3.11" )
119
+ assert dockerfile == "jupyter/rocm/pytorch/ubi9-python-3.11/Dockerfile.rocm"
120
+
109
121
def test_should_build_target (self ):
110
122
assert "" == should_build_target (["README.md" ], "jupyter/datascience/ubi9-python-3.11" )
0 commit comments