For PyPy: I'm not an expert in our import, but from looking at the source
1) imp.cache_from_source is unimplemented, it's an AttributeError.
2) sys.dont_write_bytecode is always false, we don't respect that flag (we really
should IMO, but it's not a high priority for me, or anyone else apparently)
I would like to have importlib just work out of the box for all VMs in 3.3 instead of requiring a minor patch in order to not throw an exception when loading from source and there is no bytecode. The relevant code for this discussion can be seen at http://hg.python.org/cpython/file/c2910971eb86/Lib/importlib/_bootstrap.py#l691 .First question is what are all the VMs doing for imp.cache_from_source()? Are you implementing it like CPython, or are you returning None? And if you implemented it, what does marshal.loads() do? Right now cache_from_source() is implemented in importlib itself, but we can either provide a flag to control what it does or in your setup code for import you can override the function with ``lambda _, __=None: None``.
On Tue, Jun 12, 2012 at 12:38 PM, Alex Gaynor <alex....@gmail.com> wrote:For PyPy: I'm not an expert in our import, but from looking at the source
1) imp.cache_from_source is unimplemented, it's an AttributeError.Well, you will have it come Python 3.3 one way or another. =)
2) sys.dont_write_bytecode is always false, we don't respect that flag (we really
should IMO, but it's not a high priority for me, or anyone else apparently)But doesn't PyPy read and write .pyc files (http://doc.pypy.org/en/latest/config/objspace.usepycfiles.html suggests you do)? So I would assume you are not affected by this. Jython and IronPython, though, would be (I think).
On Tue, Jun 12, 2012 at 11:47 AM, Brett Cannon <br...@python.org> wrote:On Tue, Jun 12, 2012 at 12:38 PM, Alex Gaynor <alex....@gmail.com> wrote:For PyPy: I'm not an expert in our import, but from looking at the source
1) imp.cache_from_source is unimplemented, it's an AttributeError.Well, you will have it come Python 3.3 one way or another. =)Sure, I'm not totally up to speed on the py3k effort.
2) sys.dont_write_bytecode is always false, we don't respect that flag (we really
should IMO, but it's not a high priority for me, or anyone else apparently)But doesn't PyPy read and write .pyc files (http://doc.pypy.org/en/latest/config/objspace.usepycfiles.html suggests you do)? So I would assume you are not affected by this. Jython and IronPython, though, would be (I think).This is a compile time option, not a runtime option. However, it looks like I lied, someone did implement it correctly, so we have the same behavior as CPython.
On Tue, Jun 12, 2012 at 9:38 AM, Alex Gaynor <alex....@gmail.com> wrote:Jython does not (yet) have a cache_from_source.
> For PyPy: I'm not an expert in our import, but from looking at the source
>
> 1) imp.cache_from_source is unimplemented, it's an AttributeError.
Jython does support sys.dont_write_bytecode, but doesn't support
> 2) sys.dont_write_bytecode is always false, we don't respect that flag (we really
> should IMO, but it's not a high priority for me, or anyone else apparently)
sys.dont_read_bytecode yet - do you happen to know when
dont_read_bytecode was added?
It should be pretty straightforward, and
so I'll probably add it to our 2.7.
On Tue, Jun 12, 2012 at 10:48 AM, Brett Cannon <br...@python.org> wrote:Or check for "sys.implementation.cache_tag is None"...
> I should mention another option is to add sys.dont_read_bytecode (I think I
> have discussed this with Frank at some point).
On Tue, Jun 12, 2012 at 12:01 PM, Brett Cannon <br...@python.org> wrote:IronPython will probably never *write* pyc files, but it might *read*
> On Tue, Jun 12, 2012 at 2:28 PM, Eric Snow <ericsnow...@gmail.com>
> wrote:
>>
>> On Tue, Jun 12, 2012 at 10:48 AM, Brett Cannon <br...@python.org> wrote:
>> > I should mention another option is to add sys.dont_read_bytecode (I
>> > think I
>> > have discussed this with Frank at some point).
>>
>> Or check for "sys.implementation.cache_tag is None"...
>
>
> Perfect! Will that work for Jython (Franke) and IronPython (Jeff)?
them at some point -- as I understand cache_tag, we'd set it to
whatever version of CPython's pyc files we could read (that seems to
violate the spirit of sys.implementation).
The combination of that and
sys.dont_write_bytecode should cover all of the states; I'll just lock
down sys.dont_write_bytecode so that changes are completely ignored.
>NotImplementedError?
> This does mean, though, that imp.cache_from_source() and
> imp.source_from_cache() might need to be updated to raise a reasonable
> exception when sys.implementation.cache_tag is set to None as I believe
> right now it will raise a TypeError because None isn't a str. But what to
> raise instead? TypeError? EnvironmentError?
On Jun 12, 2012 6:24 PM, "fwier...@gmail.com" <fwier...@gmail.com> wrote:
>
> On Tue, Jun 12, 2012 at 12:01 PM, Brett Cannon <br...@python.org> wrote:
> >
> >
> > On Tue, Jun 12, 2012 at 2:28 PM, Eric Snow <ericsnow...@gmail.com>
> > wrote:
> >>
> >> On Tue, Jun 12, 2012 at 10:48 AM, Brett Cannon <br...@python.org> wrote:
> >> > I should mention another option is to add sys.dont_read_bytecode (I
> >> > think I
> >> > have discussed this with Frank at some point).
> >>
> >> Or check for "sys.implementation.cache_tag is None"...
> >
> >
> > Perfect! Will that work for Jython (Franke) and IronPython (Jeff)?
> So Jython does actually emit bytecodes, but they are Java bytecodes
> instead of Python bytecodes. Right now they end up next to the .py
> files just like .pyc files. They have the possibly unfortunate naming
> foo.py -> foo$py.class -- If I understand cache_tag (I may not) I
> guess Python 3 is putting the .pyc files into hidden subdirectories
> instead of putting them next to the .py files?
Yes, __pycache__. The tag is to allow different versions of bytecode to exist side-by-side (eg for CPython 3.3 it's cpython33 so the file ends up being named foo-cpython33.pyc).
If so we may do the
> same with our $py.class files.
That was part of the hope when it was designed.
>
> Incidentally we also have a mode for reading .pyc files -- though we
> haven't implementing writing them yet (we probably will eventually)
If you can read .pyc files then you should be fine.
>
> I guess what I'm trying to say is that I don't know exactly how we
> will handle these new flags, but chances are we will use them (Again
> provided my guesses about what they do are anywhere near what they
> really do).
IOW it's too soon to be having this discussion. :) I mean regardless of what happens you can always tweak the import lib code as necessary, I just wanted to try to avoid it.
>
> >
> > This does mean, though, that imp.cache_from_source() and
> > imp.source_from_cache() might need to be updated to raise a reasonable
> > exception when sys.implementation.cache_tag is set to None as I believe
> > right now it will raise a TypeError because None isn't a str. But what to
> > raise instead? TypeError? EnvironmentError?
> NotImplementedError seems fine for me too if we don't end up using this flag.
OK, that's 2 votes for that exception.
>
> -Frank
On Wed, Jun 13, 2012 at 11:10 AM, Brett Cannon <br...@python.org> wrote:+ 1 from me as well, both for skipping any implicit reading or writing
>> > This does mean, though, that imp.cache_from_source() and
>> > imp.source_from_cache() might need to be updated to raise a reasonable
>> > exception when sys.implementation.cache_tag is set to None as I believe
>> > right now it will raise a TypeError because None isn't a str. But what
>> > to
>> > raise instead? TypeError? EnvironmentError?
>> NotImplementedError seems fine for me too if we don't end up using this
>> flag.
>
> OK, that's 2 votes for that exception.
of the cache when cache_tag is None (IIRC, that's the use case we had
in mind when we allowed that field to be None in the PEP 421
discussion), and for *explicit* attempts to access the cache when the
tag is None triggering NotImplementedError.
That way people are free to use either LBYL (checking cache_tag) or
EAFP (catching NotImplementedError).