22import logging
33import os
44from shutil import rmtree
5+ from pathlib import Path
56import subprocess
67import sys
7- import time
88import traceback
99from typing import Optional
1010
@@ -174,13 +174,14 @@ async def run_with_schema(self, input: TInputSchema) -> TOutputSchema:
174174
175175
176176def prepare_package (package : str , jira_issue : str , dist_git_branch : str ,
177- input_schema : InputSchema ) -> tuple [str , str ]:
177+ input_schema : InputSchema ) -> tuple [Path , Path ]:
178178 """
179179 Prepare the package for backporting by cloning the dist-git repository, switching to the appropriate branch,
180180 and downloading the sources.
181181 Returns the path to the unpacked sources.
182182 """
183- os .makedirs (input_schema .git_repo_basepath , exist_ok = True )
183+ git_repo = Path (input_schema .git_repo_basepath )
184+ git_repo .mkdir (parents = True , exist_ok = True )
184185 subprocess .check_call (
185186 [
186187 "centpkg" ,
@@ -190,9 +191,9 @@ def prepare_package(package: str, jira_issue: str, dist_git_branch: str,
190191 dist_git_branch ,
191192 package ,
192193 ],
193- cwd = input_schema . git_repo_basepath ,
194+ cwd = git_repo ,
194195 )
195- local_clone = os . path . join ( input_schema . git_repo_basepath , package )
196+ local_clone = git_repo / package
196197 subprocess .check_call (
197198 [
198199 "git" ,
@@ -205,9 +206,7 @@ def prepare_package(package: str, jira_issue: str, dist_git_branch: str,
205206 )
206207 subprocess .check_call (["centpkg" , "sources" ], cwd = local_clone )
207208 subprocess .check_call (["centpkg" , "prep" ], cwd = local_clone )
208- unpacked_sources = glob .glob (
209- os .path .join (local_clone , "*-build" , f"*{ package } *" )
210- )
209+ unpacked_sources = list (local_clone .glob (f"*-build/*{ package } *" ))
211210 if len (unpacked_sources ) != 1 :
212211 raise ValueError (
213212 f"Expected exactly one unpacked source, got { unpacked_sources } "
@@ -234,7 +233,8 @@ async def main() -> None:
234233 jira_issue = jira_issue ,
235234 dist_git_branch = branch ,
236235 )
237- input .unpacked_sources , local_clone = prepare_package (package , jira_issue , branch , input )
236+ unpacked_sources , local_clone = prepare_package (package , jira_issue , branch , input )
237+ input .unpacked_sources = str (unpacked_sources )
238238 try :
239239 output = await agent .run_with_schema (input )
240240 finally :
0 commit comments