From 369f35b2fdbf655e3dca33cd7c04892068f30075 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Mon, 11 Dec 2023 15:21:36 +0100 Subject: [PATCH] annotations: move sys.dont_write_bytecode to main script Move sys.dont_write_bytecode to the main script and put a comment that describe why we need this to be enabled. Signed-off-by: Andrea Righi --- annotations | 17 +++++++++++++++-- kconfig/run.py | 11 ++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/annotations b/annotations index 34d70da..3a05fe9 100755 --- a/annotations +++ b/annotations @@ -4,8 +4,21 @@ # This file is not installed; it's just to run annotations from inside a source # distribution without installing it in the system. -import os -from kconfig import run +import sys + +# Prevent generating .pyc files on import +# +# We may end up adding these files to our git repos by mistake, so simply +# prevent generating them in advance. +# +# There's a tiny performance penalty with this, because python needs to +# re-generate the bytecode on-the-fly every time the script is executed, but +# this overhead is absolutely negligible compared the rest of the kernel build +# time. +sys.dont_write_bytecode = True + +import os # noqa: E402 Import not at top of file +from kconfig import run # noqa: E402 Import not at top of file # Update PATH to make sure that annotations can be executed directly from the diff --git a/kconfig/run.py b/kconfig/run.py index 5171dfc..e857d56 100644 --- a/kconfig/run.py +++ b/kconfig/run.py @@ -3,13 +3,10 @@ # Copyright © 2022 Canonical Ltd. import sys - -sys.dont_write_bytecode = True - -import os # noqa: E402 Import not at top of file -import argparse # noqa: E402 Import not at top of file -import json # noqa: E402 Import not at top of file -from signal import signal, SIGPIPE, SIG_DFL # noqa: E402 Import not at top of file +import os +import argparse +import json +from signal import signal, SIGPIPE, SIG_DFL try: from argcomplete import autocomplete -- 2.31.1