diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2019-03-10 13:06:31 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2019-03-10 13:28:48 +0100 |
| commit | 8ddefeab1fd04c74a5638ca1e2cc5dbccfad5dd8 (patch) | |
| tree | 44efc1778ac9343080715654d91d57ed0acc3242 | |
| parent | e72f679e4916174a0f98a6e8cac43bb986270891 (diff) | |
Import 'platform' and 'subprocess' as needed
Saves around 10 ms of startup time when they aren't, as measured with
'-X importtime'.
| -rw-r--r-- | kconfiglib.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 5401bd8..306d166 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -525,9 +525,7 @@ import errno import glob import importlib import os -import platform import re -import subprocess import sys # File layout: @@ -2114,9 +2112,9 @@ class Kconfig(object): # # The preprocessor functionality changed how # environment variables are referenced, to $(FOO). - val = os.path.expandvars( - s[i + 1:end_i - 1].replace("$UNAME_RELEASE", - platform.uname()[2])) + val = os.path.expandvars(s[i + 1:end_i - 1] + .replace("$UNAME_RELEASE", + _UNAME_RELEASE)) i = end_i @@ -6224,6 +6222,9 @@ def _error_if_fn(kconf, _, cond, msg): return "" def _shell_fn(kconf, _, command): + # Only import as needed, to save some startup time + import subprocess + stdout, stderr = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ).communicate() @@ -6310,6 +6311,13 @@ STR_TO_TRI = { # Are we running on Python 2? _IS_PY2 = sys.version_info[0] < 3 +try: + _UNAME_RELEASE = os.uname()[2] +except AttributeError: + # Only import as needed, to save some startup time + import platform + _UNAME_RELEASE = platform.uname()[2] + # Tokens, with values 1, 2, ... . Avoiding 0 simplifies some checks by making # all tokens except empty strings truthy. ( |
