[prev in list] [next in list] [prev in thread] [next in thread] 

List:       opensuse-packaging
Subject:    Re: [opensuse-packaging] How to deal with Python .pyc and .pyo
From:       Johannes Meixner <jsmeix () suse ! de>
Date:       2007-11-16 8:39:22
Message-ID: Pine.LNX.4.64.0711160902460.2525 () nelson ! suse ! de
[Download RAW message or body]


Hello Jan,

On Nov 15 20:09 Jan Matejek wrote (shortened):
> Johannes Meixner napsal(a):
> > 
> > Are byte-compiled Python .pyc and .pyo files the same for any Python
> > and/or is any Python sufficiently smart to know when .pyc and/or .pyo
> > files are outdated (even if the matching .py files are unchanged)?
> 
> They are (mostly) the same, AND there is some kind of version check in
> the file. Don't worry about this, python would notice any problem by
> itself ;e)
> 
> Second worst case would be if you upgraded to a new major version of
> python, i.e. from 1.5 to 2.0. In that case python would report errors
> about bad bytecode, and i'm really not sure if it would recompile
> automatically. But i think it would.
> 
> Worst case would be if you downgraded, i don't think python 1.5 could
> cope... But on the other hand, i don't think this problem is worth
> considering.
> 
> That's why python has versioned site-packages.
> In your other post you noticed that python files are strewn all over the
> system. In most cases that is bad packaging. Generally speaking, all
> python files should be located in /usr/lib[64]/pythonx.y/site-packages
> (of course there are exceptions, but let's not go into that).

Many thanks for the explanation!

Now I understand the stuff and now I understand why and what
I must fix in particular in my hplip package which installs
its .py files (but no .pyc or .pyo file at all)
under /usr/share/hplip/*
Currently I just run HP's "make install" (HPLIP is made by HP)
and I need to find a solution together with HP to get it fixed.


By the way:

Isn't there a general problem with "python files strewn
all over the system"?

How does Python deal with .py files from whatever personal
Python projects in user's home directories?
The user has write access so that he gets .pyc or .pyo files
stored where his .py files are.
What happens if the system admin upgrades to a new major
version of Python?

I think the same problem (perhaps even in a worse shape)
exists for whatever third-party Python stuff which gets
installed somewhere under /opt/ or /usr/local/.
Think about proprietary third-party software which cannot
be changed and which exists for more than one SLES version.
I don't know if the Python license allows to have proprietary
Python stuff but I think you understand the basic idea behind.
http://www.python.org/doc/1.5.1p1/tut/node43.html
seems to indicate that at least semi-proprietary Python stuff
can exist because it reads:
---------------------------------------------------------------
It is possible to have a file called "spam.pyc" (or "spam.pyo"
when -O is used) without a module "spam.py" in the same module.
This can be used to distribute a library of Python code in a
form that is moderately hard to reverse engineer. 
---------------------------------------------------------------
There could be even "binary-only" third-party Python stuff
where no .py files exist.
What happens if a system upgrade (e.g. SLES N -> SLES N+1)
upgrades Python to a new major version?


> But even more important is that regular user doesn't have write access
> to wherever the .py files are stored. You would need to run each python
> program as root first, otherwise python would need to compile the
> sources every time the program is run.

This has another consequence:
It doesn't help not to provide .pyc or .pyo files in the RPM
to avoid problems with outdated .pyc or .pyo files if the
Python major version changes because when root runs whatever
.py files, the matching .pyc or .pyo files are created in any case.


> > I am no Python expert at all and I would be happy if a Python expert
> > could provide some background information.
> 
> is this background sufficient? ;e)

Yes, it is perfect and I am happy.


Kind Regards
Johannes Meixner
-- 
SUSE LINUX Products GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
AG Nuernberg, HRB 16746, GF: Markus Rex
---------------------------------------------------------------------
To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse-packaging+help@opensuse.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic