@@ -1395,73 +1395,75 @@ def repro_dir(tmp_dir, dvc, run_copy):
1395
1395
}
1396
1396
)
1397
1397
1398
- tmp_dir .origin_copy = "origin_copy"
1399
- assert run_copy ("origin_data" , tmp_dir .origin_copy ) is not None
1400
- assert (tmp_dir / tmp_dir .origin_copy ).read_text () == "origin data content"
1398
+ stages = {}
1399
+
1400
+ origin_copy = "origin_copy"
1401
+ stage = run_copy ("origin_data" , origin_copy )
1402
+ assert stage is not None
1403
+ assert (tmp_dir / origin_copy ).read_text () == "origin data content"
1404
+ stages ["origin_copy" ] = stage
1405
+
1406
+ origin_copy_2 = os .path .join ("dir" , "origin_copy_2" )
1407
+ stage = run_copy (origin_copy , origin_copy_2 , fname = origin_copy_2 + ".dvc" )
1408
+ assert stage is not None
1409
+ assert (tmp_dir / origin_copy_2 ).read_text () == "origin data content"
1410
+ stages ["origin_copy_2" ] = stage
1401
1411
1402
- # Unrelated are to verify that reproducing `dir` will not trigger them too
1403
- assert run_copy (tmp_dir .origin_copy , "unrelated1" ) is not None
1404
1412
dir_file_path = tmp_dir / "data_dir" / "dir_file"
1413
+ dir_file_copy = os .path .join ("dir" , "subdir" , "dir_file_copy" )
1414
+ stage = run_copy (
1415
+ fspath (dir_file_path ), dir_file_copy , fname = dir_file_copy + ".dvc"
1416
+ )
1417
+ assert stage is not None
1418
+ assert (tmp_dir / dir_file_copy ).read_text () == "dir file content"
1419
+ stages ["dir_file_copy" ] = stage
1420
+
1421
+ last_stage = os .path .join ("dir" , "Dvcfile" )
1422
+ stage = dvc .run (fname = last_stage , deps = [origin_copy_2 , dir_file_copy ])
1423
+ assert stage is not None
1424
+ stages ["last_stage" ] = stage
1425
+
1426
+ # Unrelated are to verify that reproducing `dir` will not trigger them too
1427
+ assert run_copy (origin_copy , "unrelated1" ) is not None
1405
1428
assert run_copy (fspath (dir_file_path ), "unrelated2" ) is not None
1406
1429
1407
- tmp_dir .origin_copy_2 = os .path .join ("dir" , "origin_copy_2" )
1408
- assert (
1409
- run_copy (
1410
- tmp_dir .origin_copy ,
1411
- tmp_dir .origin_copy_2 ,
1412
- fname = tmp_dir .origin_copy_2 + ".dvc" ,
1413
- )
1414
- is not None
1415
- )
1416
- assert (
1417
- tmp_dir / tmp_dir .origin_copy_2
1418
- ).read_text () == "origin data content"
1430
+ yield stages
1419
1431
1420
- tmp_dir .dir_file_copy = os .path .join ("dir" , "subdir" , "dir_file_copy" )
1421
- assert (
1422
- run_copy (
1423
- fspath (dir_file_path ),
1424
- tmp_dir .dir_file_copy ,
1425
- fname = tmp_dir .dir_file_copy + ".dvc" ,
1426
- )
1427
- is not None
1428
- )
1429
- assert (tmp_dir / tmp_dir .dir_file_copy ).read_text () == "dir file content"
1430
1432
1431
- tmp_dir .last_stage = os .path .join ("dir" , "Dvcfile" )
1432
- assert (
1433
- dvc .run (
1434
- fname = tmp_dir .last_stage ,
1435
- deps = [tmp_dir .origin_copy_2 , tmp_dir .dir_file_copy ],
1436
- )
1437
- is not None
1438
- )
1433
+ def _rewrite_file (path_elements , new_content ):
1434
+ if isinstance (path_elements , str ):
1435
+ path_elements = [path_elements ]
1436
+ file = Path (os .sep .join (path_elements ))
1437
+ file .unlink ()
1438
+ file .write_text (new_content )
1439
1439
1440
- yield tmp_dir
1440
+
1441
+ def _out_path (stage ):
1442
+ return Path (stage .outs [0 ].fspath )
1441
1443
1442
1444
1443
1445
def test_recursive_repro_default (dvc , repro_dir ):
1444
1446
"""
1445
1447
Test recursive repro on dir after a dep outside this dir has changed.
1446
1448
"""
1447
- origin = Path ("origin_data" )
1448
- origin .unlink ()
1449
- origin .write_text ("new origin data content" )
1449
+ _rewrite_file ("origin_data" , "new origin data content" )
1450
1450
1451
1451
stages = dvc .reproduce ("dir" , recursive = True )
1452
1452
1453
- # Check that the dependency ("source") and the dependent stages
1454
- # inside the folder have been reproduced ("first", "third")
1455
- names = [s .relpath for s in stages ]
1456
- assert len (names ) == 3
1457
- assert set (names ) == {
1458
- repro_dir .origin_copy + ".dvc" ,
1459
- repro_dir .origin_copy_2 + ".dvc" ,
1460
- repro_dir .last_stage ,
1461
- }
1462
- assert Path (repro_dir .origin_copy ).read_text () == "new origin data content"
1453
+ # Check that the dependency ("origin_copy") and the dependent stages
1454
+ # inside the folder have been reproduced ("origin_copy_2", "last_stage")
1455
+ assert stages == [
1456
+ repro_dir ["origin_copy" ],
1457
+ repro_dir ["origin_copy_2" ],
1458
+ repro_dir ["last_stage" ],
1459
+ ]
1460
+ assert (
1461
+ _out_path (repro_dir ["origin_copy" ]).read_text ()
1462
+ == "new origin data content"
1463
+ )
1463
1464
assert (
1464
- Path (repro_dir .origin_copy_2 ).read_text () == "new origin data content"
1465
+ _out_path (repro_dir ["origin_copy_2" ]).read_text ()
1466
+ == "new origin data content"
1465
1467
)
1466
1468
1467
1469
@@ -1470,26 +1472,20 @@ def test_recursive_repro_single(dvc, repro_dir):
1470
1472
Test recursive single-item repro on dir
1471
1473
after a dep outside this dir has changed.
1472
1474
"""
1473
- origin_data = Path ("origin_data" )
1474
- origin_data .unlink ()
1475
- origin_data .write_text ("new origin content" )
1476
-
1477
- dir_file = repro_dir / "data_dir" / "dir_file"
1478
- dir_file .unlink ()
1479
- dir_file .write_text ("new dir file content" )
1475
+ _rewrite_file ("origin_data" , "new origin content" )
1476
+ _rewrite_file (["data_dir" , "dir_file" ], "new dir file content" )
1480
1477
1481
1478
stages = dvc .reproduce ("dir" , recursive = True , single_item = True )
1482
1479
# Check that just stages inside given dir
1483
1480
# with changed direct deps have been reproduced.
1484
- # This means that "first" stage should not be reproduced
1485
- # since it depends on "source".
1486
- # Also check that "dir_file_copy" stage was reproduced before "third" stage
1487
- assert len (stages ) == 2
1488
- assert [s .relpath for s in stages ] == [
1489
- repro_dir .dir_file_copy + ".dvc" ,
1490
- repro_dir .last_stage ,
1491
- ]
1492
- assert Path (repro_dir .dir_file_copy ).read_text () == "new dir file content"
1481
+ # This means that "origin_copy_2" stage should not be reproduced
1482
+ # since it depends on "origin_copy".
1483
+ # Also check that "dir_file_copy" stage was reproduced before "last_stage"
1484
+ assert stages == [repro_dir ["dir_file_copy" ], repro_dir ["last_stage" ]]
1485
+ assert (
1486
+ _out_path (repro_dir ["dir_file_copy" ]).read_text ()
1487
+ == "new dir file content"
1488
+ )
1493
1489
1494
1490
1495
1491
def test_recursive_repro_single_force (dvc , repro_dir ):
@@ -1498,32 +1494,31 @@ def test_recursive_repro_single_force(dvc, repro_dir):
1498
1494
without any dependencies changing.
1499
1495
"""
1500
1496
stages = dvc .reproduce ("dir" , recursive = True , single_item = True , force = True )
1501
- assert len (stages ) == 3
1502
1497
# Check that all stages inside given dir have been reproduced
1503
- # Also check that "dir_file_copy" stage was reproduced before "third" stage
1504
- # and that "first " stage was reproduced before "third " stage
1505
- names = [ s . relpath for s in stages ]
1506
- assert {
1507
- repro_dir . origin_copy_2 + ".dvc" ,
1508
- repro_dir . dir_file_copy + ".dvc" ,
1509
- repro_dir . last_stage ,
1510
- } == set ( names )
1511
- assert names .index (repro_dir . origin_copy_2 + ".dvc" ) < names .index (
1512
- repro_dir . last_stage
1498
+ # Also check that "dir_file_copy" stage was reproduced before "last_stage"
1499
+ # and that "origin_copy " stage was reproduced before "last_stage " stage
1500
+ assert len ( stages ) == 3
1501
+ assert set ( stages ) == {
1502
+ repro_dir [ " origin_copy_2" ] ,
1503
+ repro_dir [ " dir_file_copy" ] ,
1504
+ repro_dir [ " last_stage" ] ,
1505
+ }
1506
+ assert stages .index (repro_dir [ " origin_copy_2" ] ) < stages .index (
1507
+ repro_dir [ " last_stage" ]
1513
1508
)
1514
- assert names .index (repro_dir . dir_file_copy + ".dvc" ) < names .index (
1515
- repro_dir . last_stage
1509
+ assert stages .index (repro_dir [ " dir_file_copy" ] ) < stages .index (
1510
+ repro_dir [ " last_stage" ]
1516
1511
)
1517
1512
1518
1513
1519
- def test_recursive_repro_empty_dir (dvc , repro_dir ):
1514
+ def test_recursive_repro_empty_dir (tmp_dir , dvc , repro_dir ):
1520
1515
"""
1521
1516
Test recursive repro on an empty directory
1522
1517
"""
1523
- (repro_dir / "emptydir" ).mkdir ()
1518
+ (tmp_dir / "emptydir" ).mkdir ()
1524
1519
1525
1520
stages = dvc .reproduce ("emptydir" , recursive = True , force = True )
1526
- assert len ( stages ) == 0
1521
+ assert stages == []
1527
1522
1528
1523
1529
1524
def test_recursive_repro_recursive_missing_file (dvc ):
@@ -1541,13 +1536,9 @@ def test_recursive_repro_on_stage_file(dvc, repro_dir):
1541
1536
Test recursive repro on a stage file instead of directory
1542
1537
"""
1543
1538
stages = dvc .reproduce (
1544
- repro_dir . origin_copy_2 + ".dvc" , recursive = True , force = True
1539
+ repro_dir [ " origin_copy_2" ]. relpath , recursive = True , force = True
1545
1540
)
1546
- assert len (stages ) == 2
1547
- assert [
1548
- repro_dir .origin_copy + ".dvc" ,
1549
- repro_dir .origin_copy_2 + ".dvc" ,
1550
- ] == [stage .relpath for stage in stages ]
1541
+ assert stages == [repro_dir ["origin_copy" ], repro_dir ["origin_copy_2" ]]
1551
1542
1552
1543
1553
1544
def test_dvc_formatting_retained (tmp_dir , dvc , run_copy ):
0 commit comments