Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| python:compiledpackages [2012/06/03 20:02] – typo MarkLinimon | python:compiledpackages [2023/02/15 21:56] (current) – typo, mention -B CharlieLi | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| CPython' | CPython' | ||
| - | (//.pyc// and/or //.pyo//) of a Python file at installation or run-time. The byte-compiled versions of the | + | (//.pyc// and sometimes |
| Python files are used in the first place by the interpreter to speed up loading and importing the files, when | Python files are used in the first place by the interpreter to speed up loading and importing the files, when | ||
| Python code is to be executed by a program. | Python code is to be executed by a program. | ||
| Line 10: | Line 10: | ||
| ===== Trouble in Userland ===== | ===== Trouble in Userland ===== | ||
| - | Right now, both package installers, // | + | Right now, both package installers, |
| '' | '' | ||
| files. | files. | ||
| Line 16: | Line 16: | ||
| At packaging and installation time, the files are picked up by the **// | At packaging and installation time, the files are picked up by the **// | ||
| them is created and written into '' | them is created and written into '' | ||
| - | (//pkgng//). | + | (//pkg//). |
| When a byte-compiled version of the original //.py// file is created, CPython stores the file's **st_mtime** and a | When a byte-compiled version of the original //.py// file is created, CPython stores the file's **st_mtime** and a | ||
| Line 28: | Line 28: | ||
| the checksum verification will also fail for every package that installs python modules. | the checksum verification will also fail for every package that installs python modules. | ||
| - | ===== Avoiding the Trouble | + | ===== Mitigation considerations |
| - | To avoid those issues, the most simple solution would be to avoid creating a checksum for those files, since the CPython | + | On first glance, the most simple solution would be to avoid creating a checksum for those files, since the CPython |
| - | interpreter will not stop (re)compiling the files as long as | + | interpreter will not stop (re)compiling the files unless |
| - | | + | |
| - | | + | |
| - | | + | |
| - | The %%FreeBSD%% port maintainers and packaging tools are not in the position to decide for users whether byte-ompiling | + | 2) and 3) work as long as ports are built as a non-root user. When root, the CPython package directories are accessible for write operations, so bytecode is written, causing filesystem violations. 1) is not feasible unless '' |
| + | |||
| + | The %%FreeBSD%% port maintainers and packaging tools are not in the position to decide for users whether byte-compiling | ||
| should be performed or not. Hence the three requirements from above should be supported but not enforced on users. | should be performed or not. Hence the three requirements from above should be supported but not enforced on users. | ||
| - | ==== Solution for pkg_install ==== | + | ===== Current approach ===== |
| + | |||
| + | This is a hybrid of not compiling bytecode during the port build process and avoiding package checksum mismatches (described in historical approaches). Using //pkg// triggers, bytecode files are compiled or removed after the pkg transactions complete, mimicking what Python' | ||
| + | |||
| + | This approach was chosen primarily due to the '' | ||
| + | |||
| + | ==== Deterministic bytecode ==== | ||
| + | |||
| + | By default, the **st_mtime** checking between bytecode and original sources is not deterministic and thus results in non-reproducible builds. [[https:// | ||
| + | |||
| + | This approach was not chosen because the aforementioned pitfalls were not addressed. Further, no installation tool that %%PyPA%% supports supplies a parameter to pass '' | ||
| + | |||
| + | ===== Historical approaches ===== | ||
| + | |||
| + | //Retained for historical purposes and commentary.// | ||
| + | |||
| + | ==== Avoiding package checksum mismatches ==== | ||
| + | |||
| + | === Solution for pkg === | ||
| + | |||
| + | In contrast to //pkg_install// //pkgng// picks up the '' | ||
| + | post-checksum operation as for // | ||
| + | as regular expression) to ignore the checksum creation for files matching on it. | ||
| + | |||
| + | **// | ||
| + | |||
| + | === Solution for pkg_install | ||
| To avoid checksum mismatches for // | To avoid checksum mismatches for // | ||
| not contain checksums for the byte-compiled files. Since changing // | not contain checksums for the byte-compiled files. Since changing // | ||
| - | necessary code might go into the port tree's Makefile | + | necessary code might go into the port tree's Makefile |
| By enhancing the **fake-pkg** target in '' | By enhancing the **fake-pkg** target in '' | ||
| - | we can avoid to mess around with '' | + | we can avoid messing |
| < | < | ||
| Line 61: | Line 89: | ||
| **// | **// | ||
| - | ==== Solution for pkgng ==== | + | ==== Avoid byte-compiling ==== |
| - | + | ||
| - | In contrast to // | + | |
| - | post-checksum operation as for // | + | |
| - | as regular expression) to ignore the checksum creation for files matching on it. | + | |
| - | + | ||
| - | **// | + | |
| - | + | ||
| - | ===== Avoid byte-compiling | + | |
| If checksums are not created anymore, audits based on the packaging tools create a hole for the byte-compiled files, since | If checksums are not created anymore, audits based on the packaging tools create a hole for the byte-compiled files, since | ||
| Line 76: | Line 96: | ||
| minimum of necessary files. | minimum of necessary files. | ||
| - | ==== pkg_install | + | === pkg === |
| + | |||
| + | **// | ||
| + | |||
| + | === pkg_install | ||
| To create a sort of //frozen// package without any byte-compiled files, byte-compiling should be made optional and it should | To create a sort of //frozen// package without any byte-compiled files, byte-compiling should be made optional and it should | ||
| Line 83: | Line 107: | ||
| At the moment '' | At the moment '' | ||
| - | without giving a user the choice | + | without giving a user the chance |
| with potential security issues. | with potential security issues. | ||
| Line 99: | Line 123: | ||
| * a new '' | * a new '' | ||
| - | This change enables us to track which Python files are installed as Python packages and moudles | + | This change enables us to track which Python files are installed as Python packages and modules |
| would be byte-compiled by default). | would be byte-compiled by default). | ||
| Line 140: | Line 164: | ||
| **// | **// | ||
| - | |||
| - | ==== pkgng ==== | ||
| - | |||
| - | **// | ||