4
4
import logging
5
5
import os
6
6
import random
7
- import shutil
8
7
import textwrap
9
8
import time
10
9
import traceback
30
29
from conda_forge_tick .cli_context import CliContext
31
30
from conda_forge_tick .deploy import deploy
32
31
from conda_forge_tick .contexts import (
33
- GIT_CLONE_DIR ,
32
+ ClonedFeedstockContext ,
34
33
FeedstockContext ,
35
34
MigratorSessionContext ,
36
35
)
@@ -151,7 +150,7 @@ def _get_pre_pr_migrator_attempts(attrs, migrator_name, *, is_version):
151
150
152
151
def _prepare_feedstock_repository (
153
152
backend : GitPlatformBackend ,
154
- context : FeedstockContext ,
153
+ context : ClonedFeedstockContext ,
155
154
branch : str ,
156
155
base_branch : str ,
157
156
) -> bool :
@@ -196,7 +195,7 @@ def _prepare_feedstock_repository(
196
195
197
196
def _commit_migration (
198
197
cli : GitCli ,
199
- context : FeedstockContext ,
198
+ context : ClonedFeedstockContext ,
200
199
commit_message : str ,
201
200
allow_empty_commits : bool = False ,
202
201
raise_commit_errors : bool = True ,
@@ -252,7 +251,7 @@ class _RerenderInfo:
252
251
253
252
254
253
def _run_rerender (
255
- git_cli : GitCli , context : FeedstockContext , suppress_errors : bool = False
254
+ git_cli : GitCli , context : ClonedFeedstockContext , suppress_errors : bool = False
256
255
) -> _RerenderInfo :
257
256
logger .info ("Rerendering the feedstock" )
258
257
@@ -398,7 +397,7 @@ def _handle_solvability_error(
398
397
399
398
400
399
def _check_and_process_solvability (
401
- migrator : Migrator , context : FeedstockContext , base_branch : str
400
+ migrator : Migrator , context : ClonedFeedstockContext , base_branch : str
402
401
) -> bool :
403
402
"""
404
403
If the migration needs a solvability check, perform the check. If the recipe is not solvable, handle the error
@@ -442,20 +441,48 @@ def get_spoofed_closed_pr_info() -> PullRequestInfoSpecial:
442
441
)
443
442
444
443
445
- def run (
444
+ def run_with_tmpdir (
446
445
context : FeedstockContext ,
447
446
migrator : Migrator ,
448
447
rerender : bool = True ,
449
448
base_branch : str = "main" ,
450
449
dry_run : bool = False ,
451
450
** kwargs : typing .Any ,
451
+ ) -> tuple [MigrationUidTypedDict , dict ] | tuple [Literal [False ], Literal [False ]]:
452
+ """
453
+ For a given feedstock and migration run the migration in a temporary directory that will be deleted after the
454
+ migration is complete.
455
+
456
+ The parameters are the same as for the `run` function. The only difference is that you pass a FeedstockContext
457
+ instance instead of a ClonedFeedstockContext instance.
458
+
459
+ The exceptions are the same as for the `run` function.
460
+ """
461
+ with context .reserve_clone_directory () as cloned_context :
462
+ return run (
463
+ context = cloned_context ,
464
+ migrator = migrator ,
465
+ rerender = rerender ,
466
+ base_branch = base_branch ,
467
+ dry_run = dry_run ,
468
+ ** kwargs ,
469
+ )
470
+
471
+
472
+ def run (
473
+ context : ClonedFeedstockContext ,
474
+ migrator : Migrator ,
475
+ rerender : bool = True ,
476
+ base_branch : str = "main" ,
477
+ dry_run : bool = False ,
478
+ ** kwargs : typing .Any ,
452
479
) -> tuple [MigrationUidTypedDict , dict ] | tuple [Literal [False ], Literal [False ]]:
453
480
"""For a given feedstock and migration run the migration
454
481
455
482
Parameters
456
483
----------
457
- context: FeedstockContext
458
- The node attributes
484
+ context: ClonedFeedstockContext
485
+ The current feedstock context, already containing information about a temporary directory for the feedstock.
459
486
migrator: Migrator instance
460
487
The migrator to run on the feedstock
461
488
rerender : bool
@@ -513,7 +540,6 @@ def run(
513
540
logger .critical (
514
541
f"Failed to migrate { context .feedstock_name } , { context .attrs .get ('pr_info' , {}).get ('bad' )} " ,
515
542
)
516
- shutil .rmtree (context .local_clone_dir )
517
543
return False , False
518
544
519
545
# We raise an exception if we don't plan to rerender and wanted an empty commit.
@@ -607,8 +633,6 @@ def run(
607
633
context .attrs , migrator_name , is_version = is_version_migration
608
634
)
609
635
610
- logger .info ("Removing feedstock dir" )
611
- shutil .rmtree (context .local_clone_dir )
612
636
return migration_run_data ["migrate_return_value" ], pr_lazy_json
613
637
614
638
@@ -690,7 +714,7 @@ def _run_migrator_on_feedstock_branch(
690
714
attrs ,
691
715
base_branch ,
692
716
migrator ,
693
- fctx ,
717
+ fctx : FeedstockContext ,
694
718
dry_run ,
695
719
mctx ,
696
720
migrator_name ,
@@ -702,7 +726,7 @@ def _run_migrator_on_feedstock_branch(
702
726
fctx .attrs ["new_version" ] = attrs .get ("version_pr_info" , {}).get (
703
727
"new_version" , None
704
728
)
705
- migrator_uid , pr_json = run (
729
+ migrator_uid , pr_json = run_with_tmpdir (
706
730
context = fctx ,
707
731
migrator = migrator ,
708
732
rerender = migrator .rerender ,
@@ -1013,7 +1037,6 @@ def _run_migrator(migrator, mctx, temp, time_per, dry_run):
1013
1037
dump_graph (mctx .graph )
1014
1038
1015
1039
with filter_reprinted_lines ("rm-tmp" ):
1016
- eval_cmd (["rm" , "-rf" , f"{ GIT_CLONE_DIR } /*" ])
1017
1040
for f in glob .glob ("/tmp/*" ):
1018
1041
if f not in temp :
1019
1042
try :
0 commit comments