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