@@ -183,13 +183,16 @@ class _ExecutableTarget:
183183
184184class _ScriptTarget (_ExecutableTarget ):
185185 def __init__ (self , target ):
186+ self ._orig_target = target
186187 self ._target = os .path .realpath (target )
187188
188- if not os .path .exists (self ._target ):
189- print (f'Error: { target } does not exist' )
189+ # Pass the original target to system functions
190+ # to support pseudofilesystems (GH-142315).
191+ if not os .path .exists (self ._orig_target ):
192+ print (f'Error: { self ._orig_target } does not exist' )
190193 sys .exit (1 )
191- if os .path .isdir (self ._target ):
192- print (f'Error: { target } is a directory' )
194+ if os .path .isdir (self ._orig_target ):
195+ print (f'Error: { self . _orig_target } is a directory' )
193196 sys .exit (1 )
194197
195198 # If safe_path(-P) is not set, sys.path[0] is the directory
@@ -207,7 +210,8 @@ def filename(self):
207210 @property
208211 def code (self ):
209212 # Open the file each time because the file may be modified
210- with io .open_code (self ._target ) as fp :
213+ use_realpath = os .path .exists (self ._target )
214+ with io .open_code (self ._target if use_realpath else self ._orig_target ) as fp :
211215 return f"exec(compile({ fp .read ()!r} , { self ._target !r} , 'exec'))"
212216
213217 @property
0 commit comments