[Distutils] How to handle launcher script importability?

PJ Eby pje at telecommunity.com
Mon Aug 12 15:01:10 CEST 2013


On Mon, Aug 12, 2013 at 7:33 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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.

Oh, that reminds me: IIUC, it's not necessary to *actually* zip a
.pyz.  Remember, Python doesn't use the extension to determine the
contents, it sniffs for a zip trailer.  Likewise, there was IIRC no
plan for pylauncher to inspect zip contents -- it just reads the #!
line and runs python on the file.

This means that you can actually write source as a .pyz or .pwz file
on Windows, and it would Just Work -- *without any sys.path
modification*.

For *all versions of Python*, provided PyLauncher is installed.  (And
setuptools could check the environment and registry for that, if you
opt into the non-.exe scripts, and error out if you don't have them
set up correctly.)

IOW, implementing PEP 441 in PyLauncher gives us the "executable, not
importable" format for free.

(Granted, I can see reasons for not wanting to use the same extension
for source and zipped versions, mostly in the area of tools other than
pylauncher, but if you do have different extensions then there have to
be *four*, due to console vs. windowed and source vs. zipped.)


More information about the Distutils-SIG mailing list