@@ -380,6 +380,13 @@ pub fn create_empty_venv<'a>(
380380 )
381381 . into_diagnostic ( ) ?;
382382
383+ // And include our horrid path machinery
384+ fs:: write (
385+ & venv. site_dir . join ( "_aspect.py" ) ,
386+ include_str ! ( "_aspect.py" ) ,
387+ )
388+ . into_diagnostic ( ) ?;
389+
383390 Ok ( venv)
384391}
385392
@@ -441,10 +448,11 @@ pub fn populate_venv_with_copies(
441448 let action_bin_dir = action_src_dir. join ( bin_dir) ;
442449
443450 #[ cfg( feature = "debug" ) ]
444- eprintln ! ( "action_src_dir: {}" , & action_src_dir. to_str( ) . unwrap( ) ) ;
445-
446- #[ cfg( feature = "debug" ) ]
447- eprintln ! ( "action_bin_dir: {}" , & action_bin_dir. to_str( ) . unwrap( ) ) ;
451+ {
452+ println ! ( "action_src_dir: {}" , & action_src_dir. to_str( ) . unwrap( ) ) ;
453+ println ! ( "action_bin_dir: {}" , & action_bin_dir. to_str( ) . unwrap( ) ) ;
454+ println ! ( "venv.site_dir: {}" , & venv. site_dir. to_str( ) . unwrap( ) ) ;
455+ }
448456
449457 let source_pth = File :: open ( pth_file. src . as_path ( ) )
450458 . into_diagnostic ( )
@@ -459,7 +467,7 @@ pub fn populate_venv_with_copies(
459467 . write (
460468 b"\
461469 # Generated by Aspect py_binary
462- # Contains relative import paths to non site-package trees within the .runfiles
470+ # Sets up imports within the .runfiles tree
463471" ,
464472 )
465473 . into_diagnostic ( ) ?;
@@ -532,14 +540,16 @@ pub fn populate_venv_with_copies(
532540 //
533541 // [1] https://github.com/python/cpython/blob/ce31ae5209c976d28d1c21fcbb06c0ae5e50a896/Lib/site.py#L215
534542
535- let path_to_runfiles =
536- diff_paths ( & action_bin_dir, action_bin_dir. join ( & venv. site_dir ) ) . unwrap ( ) ;
537-
538543 writeln ! ( dest_pth_writer, "# @{}" , line) . into_diagnostic ( ) ?;
539544 writeln ! (
540545 dest_pth_writer,
541- "{}" ,
542- path_to_runfiles. join( entry) . to_str( ) . unwrap( )
546+ "import _aspect;_aspect.pathadd('{}', workspace='{}')" ,
547+ line. replace( "'" , "\\ '" ) ,
548+ if workspace == main_module {
549+ & ""
550+ } else {
551+ main_module. to_str( ) . unwrap( )
552+ } ,
543553 )
544554 . into_diagnostic ( ) ?;
545555 }
0 commit comments