From patchwork Wed May 16 01:52:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 914118 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="lLZ5UOTl"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40lyHC6Z90z9ryk for ; Wed, 16 May 2018 11:57:11 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 900E4C21D4A; Wed, 16 May 2018 01:54:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8541CC21E12; Wed, 16 May 2018 01:53:21 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A9FD4C21DF9; Wed, 16 May 2018 01:53:14 +0000 (UTC) Received: from mail-it0-f43.google.com (mail-it0-f43.google.com [209.85.214.43]) by lists.denx.de (Postfix) with ESMTPS id 85558C21DB3 for ; Wed, 16 May 2018 01:53:09 +0000 (UTC) Received: by mail-it0-f43.google.com with SMTP id n64-v6so6578122itb.3 for ; Tue, 15 May 2018 18:53:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EmjId4p0+3s0O9e6FuDwIFXw0Wj5kxzZDXGDRbJopC8=; b=lLZ5UOTlCbkJRuRxTlJA0El3leRur8/cUgUn0XIHe7EDd+mExf1lNVXpbhZGeovy2u Y3x1wBHuCZtH4cnZY/f5AzQA3YVTvIbE9mIcroLYgIcxui/nKpkCowS9E+/tt+zIrSl1 8PIpvu7wVkS+FE+9wsVXP33wVC2CPVGp+QOmq3ywfrcYe07OTRjq2hlQLmWJ5NqOBzoP 1wPkC2pOoNzOOQ5fXFHk8mPktCczq9dbcM3kb23C2oNU2hJtyn4L1q5NAuR/RhnAKsl5 Shkj5heSEP8COzZbgGBwASIEWdC9/kyXfK6RPHzu6Vrm243Gp0PrILFLfvA7NY5vRH2u c3SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=EmjId4p0+3s0O9e6FuDwIFXw0Wj5kxzZDXGDRbJopC8=; b=mE8p1NXNawDby4bpelPdfb+hg9C0QednmrKS9mQIHKfIGBhnQaRKNzwq5xxEXr2ewK MRG+MoyZE0rmOspkIgdm+dK6f9sSgL/klncp4kWkcbOjExEYA5LrZRyljurFfWT0UG9s 2kE7r4IvPvSaTVl9UIrs1Xy1dQ8+A3RVt3b4NQMkYUYACht4wvI6oFEABs+ffpKy4gnJ UJBbiWwvsz1za9I51Jm56uKECzmRFNOp0vsK9gcyNmdeTcD7i7LyeSv89Rs1NBVykdz8 hz3xwBF/1vJFGfpb2GgrYXJH84fD/zWLK3Gv7aUbDYw7WOUrBw78JiOvEezO2Iyc5Yzs LprQ== X-Gm-Message-State: ALKqPwftFDvnqFIa3L2S8dDE+eWBLv2gMLlIKfxrLHCM0HyZXz2H11Ur RsDUY/l2VaZBQ8B1TmHmRK5EgQ== X-Google-Smtp-Source: AB8JxZrvIJAEdtjjr98m6TZYBfjEVArWvymQRSe+7cOjJdeUA6+ev2m9ruqxMWIzpYO31scVJEZ7Dw== X-Received: by 2002:a24:aa4f:: with SMTP id y15-v6mr511722iti.144.1526435587891; Tue, 15 May 2018 18:53:07 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id e189-v6sm790417ioe.0.2018.05.15.18.53.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 18:53:07 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id EF931141521; Tue, 15 May 2018 19:53:06 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 15 May 2018 19:52:51 -0600 Message-Id: <20180516015258.187295-6-sjg@chromium.org> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: <20180516015258.187295-1-sjg@chromium.org> References: <20180516015258.187295-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 05/12] binman: Avoid setting sys.path globally X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" At present we set the Python path at the start of binman so we can read modules in the 'etype' directory. This is a bit messy since it affects 'import' statements through binman. Adjust the code to set the path locally, just where it is needed. Move the 'entry' module in with the other base modules to help with this. It makes more sense here anyway since it does not implement an entry type. Signed-off-by: Simon Glass --- tools/binman/binman.py | 3 --- tools/binman/{etype => }/entry.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) rename tools/binman/{etype => }/entry.py (96%) diff --git a/tools/binman/binman.py b/tools/binman/binman.py index fa2f551f554..d49402a977e 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -23,9 +23,6 @@ for dirname in ['../patman', '../dtoc', '..']: # Bring in the libfdt module sys.path.insert(0, 'scripts/dtc/pylibfdt') -# Also allow entry-type modules to be brought in from the etype directory. -sys.path.insert(0, os.path.join(our_path, 'etype')) - import cmdline import command import control diff --git a/tools/binman/etype/entry.py b/tools/binman/entry.py similarity index 96% rename from tools/binman/etype/entry.py rename to tools/binman/entry.py index cbcabe20582..5374178542e 100644 --- a/tools/binman/etype/entry.py +++ b/tools/binman/entry.py @@ -14,10 +14,14 @@ except: have_importlib = False import fdt_util +import os +import sys import tools modules = {} +our_path = os.path.dirname(os.path.realpath(__file__)) + class Entry(object): """An Entry in the section @@ -80,8 +84,12 @@ class Entry(object): module_name = module_name.split('@')[0] module = modules.get(module_name) + # Also allow entry-type modules to be brought in from the etype directory. + # Import the module if we have not already done so. if not module: + old_path = sys.path + sys.path.insert(0, os.path.join(our_path, 'etype')) try: if have_importlib: module = importlib.import_module(module_name) @@ -90,6 +98,8 @@ class Entry(object): except ImportError: raise ValueError("Unknown entry type '%s' in node '%s'" % (etype, node.path)) + finally: + sys.path = old_path modules[module_name] = module # Call its constructor to get the object we want.