[Buildroot] [PATCH 2/2] support/scripts/size-stats: properly assign pre-compiled .pyc files

yann.morin at orange.com yann.morin at orange.com
Mon Sep 14 12:00:08 UTC 2026


Vincent, All,

On 2026-09-14 11:27 +0200, MORIN Yann INNOV/IT-S spake thusly:
> On 2026-08-19 13:44 +0000, Vincent Fazio spake thusly:
[--SNIP--]
> > Maybe we can leverage `source_from_cache` [2] and compare the file names?
> Ah, good idea if it can work out-of-tree as we install for the target.
> I'll look into that.

Oh, wait, wait... That's the other way around: we do have the path of
the original .py file, and we are looking for the path of the
pre-compiled file!

So I gave it a try with cache_from_source() [0] instead, and it kinda
of works...

"Kinda", because it only works when we do have both the source and the
pre-compiled files together (BR2_PACKAGE_PYTHON3_PY_PYC), but fails
when we only have the precompiled files (BR2_PACKAGE_PYTHON3_PYC_ONLY).
That's because cache_from_source() only work on the path string, and
does not check files.

But that is not an issue in practice:

1. BR2_PACKAGE_PYTHON3_PY_ONLY: we only have .py files, so when we try
   to look at the cprfe-copmpiled files, it will not be found, and thus
   ignored (as it is today already)

2. BR2_PACKAGE_PYTHON3_PYC_ONLY: we'll only have the .pyc file in the
   pycache directory, and the .py file will be ignored (as it is today
   already).

3. BR2_PACKAGE_PYTHON3_PY_PYC: both will be found, and we'll properly
   account for both (unlike today)

So, that's what I'm going to go with, using cache_from_source(), rather
than with my open-coding the split. Thanks for the hint! 👍

However, I have not seen a way to convert from a source file path to an
*optimised* precompiled pyc file. So I still believe this should be
addressed when (if!) we eventually add squpport for optimised
precompiled pyc files. If we forget about size-stat then, that's not a
problem: the interested parties will have to fixup afterward (like I'm
currently doing anyway ;-) ).

[0] https://github.com/python/cpython/blob/20e6c2fc7c174342214d561845419c4030f8638f/Lib/importlib/_bootstrap_external.py#L239

Regards,
Yann E. MORIN.

-- 
                                        ____________
.-----------------.--------------------:       _    :------------------.
|  Yann E. MORIN  | Real-Time Embedded |    __/ )   | /"\ ASCII RIBBON |
|                 | Software  Designer |  _/ - /'   | \ / CAMPAIGN     |
| +33 638.411.245 '--------------------: (_    `--, |  X  AGAINST      |
| yann.morin (at) orange.com           |_="    ,--' | / \ HTML MAIL    |
'--------------------------------------:______/_____:------------------'

____________________________________________________________________________________________________________
Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.


More information about the buildroot mailing list