The %run
magic has a parameter file_finder
that it uses to get the full path to the file to execute (see here); as you note, it just looks in the current directory, appending ".py" if necessary.
There doesn't seem to be a way to specify which file finder to use from the %run
magic, but there's nothing to stop you from defining your own magic command that calls into %run
with an appropriate file finder.
As a very nasty hack, you could override the default file_finder
with your own:
IPython.core.magics.execution.ExecutionMagics.run.im_func.func_defaults[2] = my_file_finder
To be honest, at the rate the IPython API is changing that's as likely to continue to work as defining your own magic is.
import <module>
is essentially the same asexec(<moduleSource>)
in JavaScript or Perl. – Vortico