@@ -448,6 +448,7 @@ aspect-runfiles-repo = {1}
448
448
/// the depth of the `ip` then back down to the workspace-relative path of
449
449
/// the target file.
450
450
pub fn populate_venv_with_copies (
451
+ repo : & str ,
451
452
venv : Virtualenv ,
452
453
pth_file : PthFile ,
453
454
bin_dir : PathBuf ,
@@ -458,7 +459,6 @@ pub fn populate_venv_with_copies(
458
459
459
460
// Get $PWD, which is the build working directory.
460
461
let action_src_dir = current_dir ( ) . into_diagnostic ( ) ?;
461
- let main_module = action_src_dir. file_name ( ) . unwrap ( ) ;
462
462
let action_bin_dir = action_src_dir. join ( bin_dir) ;
463
463
464
464
#[ cfg( feature = "debug" ) ]
@@ -486,7 +486,7 @@ pub fn populate_venv_with_copies(
486
486
. into_diagnostic ( ) ?;
487
487
488
488
for line in BufReader :: new ( source_pth) . lines ( ) . map_while ( Result :: ok) {
489
- // #[cfg(feature = "debug")]
489
+ #[ cfg( feature = "debug" ) ]
490
490
eprintln ! ( "Got pth line {}" , & line) ;
491
491
492
492
let line = line. trim ( ) . to_string ( ) ;
@@ -499,12 +499,12 @@ pub fn populate_venv_with_copies(
499
499
format ! ( "{}/" , line)
500
500
} ;
501
501
502
- let Some ( ( workspace , entry_path) ) = line. split_once ( "/" ) else {
502
+ let Some ( ( entry_repo , entry_path) ) = line. split_once ( "/" ) else {
503
503
return Err ( miette ! ( "Invalid path file entry!" ) ) ;
504
504
} ;
505
505
506
506
#[ cfg( feature = "debug" ) ]
507
- eprintln ! ( "Got pth entry @{}//{}" , workspace , entry_path) ;
507
+ eprintln ! ( "Got pth entry @{}//{}" , entry_repo , entry_path) ;
508
508
509
509
let mut entry = PathBuf :: from ( entry_path) ;
510
510
@@ -515,9 +515,9 @@ pub fn populate_venv_with_copies(
515
515
516
516
// If the entry is external then we have to adjust the path
517
517
// FIXME: This isn't quite right outside of bzlmod
518
- if workspace != main_module {
518
+ if entry_repo != repo {
519
519
entry = PathBuf :: from ( "external" )
520
- . join ( PathBuf :: from ( workspace ) )
520
+ . join ( PathBuf :: from ( entry_repo ) )
521
521
. join ( entry)
522
522
}
523
523
@@ -542,32 +542,25 @@ pub fn populate_venv_with_copies(
542
542
}
543
543
}
544
544
} else {
545
- // Need to insert an appropriate pth file entry. Pth file lines
546
- // are relativized to the site dir [1] so here we need to take
547
- // the path from the site dir back to the root of the runfiles
548
- // tree and then append the entry to that relative path.
549
- //
550
- // This is the path from the venv's site-packages destination
551
- // "back up to" the bazel-bin dir we're building into, plus one
552
- // level.
553
- //
554
- // [1] https://github.com/python/cpython/blob/ce31ae5209c976d28d1c21fcbb06c0ae5e50a896/Lib/site.py#L215
555
-
556
- // aspect-build/rules_py#610
557
- //
558
- // While these relative paths seem to work fine for _internal_
559
- // runfiles within the `_main` workspace, problems occur when we
560
- // try to take relative paths to _other_ workspaces because bzlmod
561
- // may munge the directory names to be something that doesn't
562
- // exist.
563
- let path_to_runfiles =
564
- diff_paths ( & action_bin_dir, action_bin_dir. join ( & venv. site_dir ) ) . unwrap ( ) ;
545
+ if entry_repo != repo {
546
+ eprintln ! ( "Warning: @@{entry_repo}//{entry_path} is not `site-packages`via pth rather than copy" , )
547
+ }
548
+ // The path to the runfiles root is _one more than_ the relative
549
+ // oath from the venv's target dir to the root of the module
550
+ // containing the venv.
551
+ let path_to_runfiles = diff_paths ( & action_bin_dir, action_bin_dir. join ( & venv. site_dir ) )
552
+ . unwrap ( )
553
+ . join ( ".." ) ;
565
554
566
555
writeln ! ( dest_pth_writer, "# @{}" , line) . into_diagnostic ( ) ?;
567
556
writeln ! (
568
557
dest_pth_writer,
569
558
"{}" ,
570
- path_to_runfiles. join( entry) . to_str( ) . unwrap( )
559
+ path_to_runfiles // .runfiles
560
+ . join( entry_repo) // ${REPO}
561
+ . join( entry_path) // ${PATH}
562
+ . to_str( )
563
+ . unwrap( )
571
564
)
572
565
. into_diagnostic ( ) ?;
573
566
}
@@ -584,6 +577,7 @@ pub fn populate_venv_with_copies(
584
577
585
578
#[ expect( unused_variables) ]
586
579
pub fn populate_venv_with_pth (
580
+ repo : & str ,
587
581
venv : Virtualenv ,
588
582
pth_file : PthFile ,
589
583
bin_dir : PathBuf ,
0 commit comments