<div dir="ltr"><div class="gmail_default" style="font-size:small">While these are interesting ideas, wouldn't it be better to leave this kind of packaging to snap and similar utilities that bundle the language support and libraries to allow simple isolated installation.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Kind regards</div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Steve Holden<br></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 26, 2019 at 10:05 PM Neil Schemenauer <<a href="mailto:nas-python@arctrix.com">nas-python@arctrix.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2019-02-26, Gregory P. Smith wrote:<br>
> On Tue, Feb 26, 2019 at 9:55 AM Barry Warsaw <<a href="mailto:barry@python.org" target="_blank">barry@python.org</a>> wrote:<br>
> For an OS distro provided interpreter, being able to restrict its use to<br>
> only OS distro provided software would be ideal (so ideal that people who<br>
> haven't learned the hard distro maintenance lessons may hate me for it).<br>
<br>
Interesting idea.  I remember when I was helping develop Debian<br>
packaging guides for Python software.   I had to fight with people<br>
to convince them that Debian packages should use <br>
<br>
    #!/usr/bin/pythonX.Y<br>
<br>
rather than<br>
<br>
    #!/usr/bin/env python<br>
<br>
The situtation is much better now but I still sometimes have<br>
packaged software fail because it picks up my version of<br>
/usr/local/bin/python.  I don't understand how people can believe<br>
grabbing /usr/local/bin/python is going to be a way to build a<br>
reliable system.<br>
<br>
> Such a restriction could be implemented within the interpreter itself. For<br>
> example: Say that only this set of fully qualified path whitelisted .py<br>
> files are allowed to invoke it, with no interactive, stdin, or command line<br>
> "-c" use allowed.<br>
<br>
I think this is related to an idea I was tinkering with on the<br>
weekend.  Why shouldn't we do more compile time linkage of Python<br>
packages?  At least, I think we give people the option to do it.<br>
Obviously you still need to also support run-time import search<br>
(interactive REPL, support __import__(unknown_at_compiletime)__).<br>
<br>
Here is the sketch of the idea (probably half-baked, as most of my<br>
ideas are):<br>
<br>
- add PYTHONPACKAGES envvar and -p options to 'python'<br>
<br>
- the argument for these options would be a colon separated list of<br>
  Python package archives (crates, bales, bundles?).  The -p option<br>
  could be a colon separated list or provided multiple times to<br>
  specify more packages.<br>
<br>
- the modules/packages contained in those archives become the<br>
  preferred bytecode code source when those names are imported.  We<br>
  look there first.  The crawling around behavor (dynamic import<br>
  based on sys.path) happens only if a module is not found and could<br>
  be turned off.<br>
<br>
- the linking of the modules could be computed when the code is<br>
  compiled and the package archive created, rather than when the<br>
  'import' statement gets executed.  This would provide a number of<br>
  advantages.  It would be faster.  Code analysis tools could<br>
  statically determine which modules imported code corresponds too.<br>
  E.g. if your code calls module.foo, assuming no monkey patching,<br>
  you know what code 'foo' actually is.<br>
<br>
- to get extra fancy, the package archives could be dynamic<br>
  link libraries containing "frozen modules" like this FB experiment:<br>
  <a href="https://github.com/python/cpython/pull/9320" rel="noreferrer" target="_blank">https://github.com/python/cpython/pull/9320</a><br>
  That way, you avoid the unmarshal step and just execute the module<br>
  bytecode directly.  On startup, Python would dlopen all of the<br>
  package archives specified by PYTHONPACKAGES.  On init, it would<br>
  build an index of the package tree and it would have the memory<br>
  location for the code object for each module.<br>
<br>
That would seem like quite a useful thing.  For an application like<br>
Mercurial, they could build all the modules/packages required into a<br>
single package archive.  Or, there would be a small number of<br>
archives (one for standard Python library, one for everything else<br>
that Mercurial needs).<br>
<br>
Now that I write this, it sounds a lot like the debate between<br>
static linking and dynamic linking.  Golang does static linking and<br>
people seem to like the single executable distribution.<br>
<br>
Regards,<br>
<br>
  Neil<br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/steve%40holdenweb.com" rel="noreferrer" target="_blank">https://mail.python.org/mailman/options/python-dev/steve%40holdenweb.com</a><br>
</blockquote></div>