[Distutils] How to handle launcher script importability?

Nick Coghlan ncoghlan at gmail.com
Mon Aug 12 13:33:18 CEST 2013

On 11 Aug 2013 21:37, "PJ Eby" <pje at telecommunity.com> wrote:
> On Sun, Aug 11, 2013 at 7:31 PM, Jason R. Coombs <jaraco at jaraco.com>
> >> -----Original Message-----
> >> From: Nick Coghlan [mailto:ncoghlan at gmail.com]
> >> Sent: Sunday, 11 August, 2013 17:14
> >>
> >> We actually have a proposal on import-sig to allow module specific
> >> path manipulation (including the ability to say "don't import this
> >> from this directory, even though it looks like it is here"). I'd
favour that
> >> mechanism over a new "not importable" file extension.
> >
> > I don't believe this mechanism would suffice. My previous example was
> > over-simplified to the general problem, which is that any script could
> > potentially be imported as a module of the same name. So if I were to
> > easy_install.py, it would set sys.path[0] to Scripts\ and if it were
then to
> > import cython (which it does), it would import Scripts/cython.py as
> > unless there were some way to globally declare all installed scripts
> > so they're excluded from import.
> Indeed.  It really *does* need to be a "don't import this" extension,
> though it doesn't much matter what that extension is.  Except on
> Windows, of course, where it has to be something associated with
> Python that also still works as a console app and is listed in
> (As you surmised earlier, my choice of '-script.py' was indeed chosen
> to prevent accidental importing, as the '-' ensures it's not a valid
> module name.)

Having an empty "cython.ref" file (extension TBC) would tell Python to skip
that directory for "import cython" regardless of the presence of something
that otherwise would be considered. The actual downside is that won't land
until 3.4 at the earliest, while PyLauncher can associate additional
extensions with itself (and modify PATHEXT) earlier than that.

Having pys and pyz for "executable, but not importable" (source and zip
archive forms) could be quite clean. In effect, the pys extension would
bring windows to parity with *nix, where "no extension at all" has
traditionally served the purpose of making it impossible to import a script.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20130812/206f836b/attachment.html>

More information about the Distutils-SIG mailing list