Mailinglist Archive: opensuse-packaging (122 mails)

< Previous Next >
Re: [opensuse-packaging] How to deal with Python .pyc and .pyo files?
  • From: Jan Matejek <jmatejek@xxxxxxx>
  • Date: Thu, 15 Nov 2007 20:09:58 +0100
  • Message-id: <473C9986.3020701@xxxxxxx>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Johannes Meixner napsal(a):
Hello,

On Nov 14 16:00 Marcus Rueckert wrote (shortened):

On Wed, 2007-11-14 at 15:08 +0100, Johannes Meixner wrote:
Hello,

what is the recommended way for packaging Python stuff?

Either
have byte-compiled Python .pyc and .pyo files packaged into the RPM
or
let this be done by the currently actually installed Python system
during run-time on the end-user's computer and not by whatever
(perhaps different) Python system during package build-time?
as we build with the same python version as the user will run it later.
you can safely package the .pyc files.

I understand that it is the same Python version directly after
a new system installation.

But what happens when the user later change/update his Pyhon?

Think about the "worst case" when the user replaces our Pyhon
with whatever self-compiled Pyhon.

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).

i would even recommend packaging
them so they get removed if you uninstall the package.

Removal when uninstalling could also be done by whatever
other magic (e.g. via %ghost or a %preun scriptlet in RPM).

Bad magic, bad bad magic. We have enough trouble with scriptlets as they
are now.

I wonder why in this case small RPMs seem not to count.

For example the installed .pyc and .pyo files in python
on a openSUSE 10.3 i386 system are more than 7MB and
still about 1.6MB after "bzip2" so that those files
should make the python RPM about 1.6MB bigger.

At least according to
http://www.python.org/doc/1.5.1p1/tut/node43.html
I wonder if there is a noticeable advantage to provide
.pyc and .pyo files in the RPM because it reads:
"A program doesn't run any faster when it is read from
a ".pyc" or ".pyo" file than when it is read from a ".py" file;
the only thing that's faster about ".pyc" or ".pyo" files is
the speed with which they are loaded."

True, and that's why we provide them. Think about it this way: python
programs need to be compiled too. We provide the "binaries" form so that
users' computers don't need to do the compilation themselves.

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.

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)



Kind Regards
Johannes Meixner

regards
jan matejek
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFHPJmGjBrWA+AvBr8RAu4nAJ44givXOzCG9LY1ge9DWoSouwTFHQCgjlf2
WA9ogJSDXliAvm2NxmAsy2E=
=zapY
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: opensuse-packaging+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse-packaging+help@xxxxxxxxxxxx

< Previous Next >