Python .pyc and .pyo files

Bug #163109 reported by Johannes Meixner
6
Affects Status Importance Assigned to Milestone
HPLIP
Confirmed
Medium
David Suffield

Bug Description

When I build HPLIP for openSUSE, I use in the RPM spec file
---------------------------------------------------------------------------------
./configure --prefix=/usr \
 --libdir=%_libdir \
 --disable-foomatic-xml-install \
 --enable-foomatic-ppd-install \
 --with-hpppddir=%{_datadir}/cups/model/manufacturer-PPDs/%{name} \
 --with-cupsbackenddir=%{_libdir}/cups/backend \
 --with-docdir=%{_defaultdocdir}/%{name}
make
...
make install DESTDIR=%{buildroot}
---------------------------------------------------------------------------------

This results all Python .py files to be installed under /usr/share/hplip/

Neither .pyc nor .pyo files are compiled or installed.

1.
All python files should be under /usr/lib[64]/pythonx.y/site-package
e.g. /usr/lib[64]/python2.5/site-packages/hplip/

Because this directory is both architecture and Python version
dependant, a configure option like --with-pythondir=DIR
is required so that one can use in the RPM spec file
--with-pythondir=%{_libdir}/python%{py_ver}/site-packages/hplip/

The current directory /usr/share/hplip/ leads to problems.

Reason:
Byte-compiled Python .pyc and .pyo files can differ for
different major versions of Python.
If one upgraded to a new major version of Python, it would
report errors about bad bytecode, and I don't know if Python
would recompile automatically.
Therefore Python has versioned site-packages.

2.
It would be good to create byte-compiled Python .pyc and .pyo files
by default (preferably via a configure option like
--enable-byte-compiled-python which is by default enabled)
and install them because this speeds up loading of Python modules.

Reason:
Only if root runs HPLIP's .py files, Python can create the
matching .pyc and .pyo files and store them where the .py files are
because only root has write access where the .py files are.
As long as root doesn't run HPLIP's .py files, 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.
When root runs .py files, the matching .pyc or .pyo files
are created in any case.
If later there is a Python major version upgrade
and a normal user runs the outdated .pyc or .pyo files,
it would not help when Python tries to recompile them
because a normal user cannot write the new .pyc or .pyo files.
Hopefully Python will use then the .py files as fallback
but I don't know if it does.

Revision history for this message
Johannes Meixner (jsmeix) wrote :

You may like to have a look at the
"How to deal with Python .pyc and .pyo files?" thread on the
<email address hidden> mailing list,
in particular see
http://lists.opensuse.org/opensuse-packaging/2007-11/msg00069.html

Revision history for this message
Aaron Albright (albrigha-deactivatedaccount) wrote :

Put on the todo list, assigning to Don.

A

Changed in hplip:
assignee: nobody → dwelch91
importance: Undecided → Medium
status: New → Confirmed
dwelch91 (dwelch91)
Changed in hplip:
assignee: dwelch91 (dwelch91) → David Suffield (david-suffield)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.