-----BEGIN PGP SIGNED MESSAGE-----
Dne 16.10.2014 v 12:11 Johannes Meixner napsal(a):
A question regarding "include .pycs and
Do you recommend that a package schould provide both .pyc files and .pyo
files for each .py file i.e. that during build both "%py_compile" and
"%py_compile -O" should be run?
as long as it's not too much trouble, then yes
For me it looks overcomplicated to make and provide
both and then link them
via "%fdupes" if they are the same.
Why not only make and provide the optimized files in
That's a long story.
You can run the python interpreter either in "normal" or "optimized"
latter is enabled by "python -O". In normal mode, python only looks for .pyc;
in optimized mode, it only looks for .pyo. No fallback to the other one.
(IIRC, there are some technical and semantical issues, and the fallback
feature is not important enough to justify the tradeoff)
So if we want to support users of optimized mode, we need to provide both
kinds of files.
At this moment, the optimizations in the "optimized" bytecode are extremely
limited, so in the majority of cases, the resulting bytecode is the same. The
biggest potential difference is that .pyo does not include certain kinds of
strings; that also means that there is a potential difference of behavior, and
that's the main reason why the optimized mode is kept separate.
Personally, I believe that .pyo is kept around because the upstream is hoping
that someone will start implementing some worthwhile optimizations ;) There is
some work ongoing, but it's very low-priority.
In practice, maybe this is one more thing we don't have to care about. I have
never in my life met anyone who uses the optimized mode, so i believe it's a
minority usecase; people looking for more performance are switching to PyPy or
My rule of thumb is this: if it's not too much trouble, provide both .pyc and
.pyo and merge them with fdupes. If it causes problems, forget about .pyo.
A subsequent question:
When a package ships .pyc and/or .pyo files, I wonder if the .py files are
still needed by a normal users.
Does Python software work correctly only with .pyc and/or .pyo files?
If yes, shoudn't then the .py files moved into a
sub-package that is not installed by default?
We also do not install *.c source files but only the binaries.
That's honestly something that never crossed my mind.
It's somewhat different than with C sources though. On an installed system, C
sources are for reference only -- if you want to make changes, you have to
recompile and install the result.
For Python, source code is the primary material and the bytecode is just a
"cached result". Changes to sources are reflected immediately on the next run;
the interpreter checks mtimes, and if the source doesn't match the bytecode,
runs from source (and updates the bytecode if it can).
Personally, i'd vote to keep the sources for this reason alone :) It more
closely matches the spirit of open source, after all.
And there's also a number of smaller reasons: don't fix what ain't broken,
every other distro does it like this, *-python-source would complicate
But it is something worth thinking about.
Strictly spaking, if it works only with .pyc and/or .pyo files, there is no
need to provide the Python source files in the RPM. Only the SRPM provides
Exception: Python scripts that are meant to be adapted by the end-user.
Kind Regards Johannes Meixner
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
-----END PGP SIGNATURE-----
To unsubscribe, e-mail: opensuse-packaging+unsubscribe(a)opensuse.org
To contact the owner, e-mail: opensuse-packaging+owner(a)opensuse.org