Fix import spawn error on Python 3.6.5(Default Python version on Ubuntu 18.04 LTS). - Copy the find_executable() function from python3.5/distutils/spawn.py - npm.py do not need to import spawn
PATCH 1/1 Fix import spawn error on Python 3.6.5(Default Python version on Ubuntu 18.04 LTS). - Copy the find_executable() function from python3.5/distutils/spawn.py - npm.py do not need to import spawn
--- lib/bb/fetch2/clearcase.py | 28 ++++++++++++++++++++++++++-- lib/bb/fetch2/npm.py | 1 - 2 files changed, 26 insertions(+), 3 deletions(-)
lib/bb/fetch2/clearcase.py +26 -2
@@ -69,7 +69,6 @@ from bb.fetch2 import FetchMethod from bb.fetch2 import FetchError from bb.fetch2 import runfetchcmd from bb.fetch2 import logger -from distutils import spawn class ClearCase(FetchMethod): """Class to fetch urls via 'clearcase'"""
@@ -107,7 +106,7 @@ class ClearCase(FetchMethod): else: ud.module = "" - ud.basecmd = d.getVar("FETCHCMD_ccrc") or spawn.find_executable("cleartool") or spawn.find_executable("rcleartool") + ud.basecmd = d.getVar("FETCHCMD_ccrc") or _find_executable("cleartool") or _find_executable("rcleartool") if d.getVar("SRCREV") == "INVALID": raise FetchError("Set a valid SRCREV for the clearcase fetcher in your recipe, e.g. SRCREV = \"/main/LATEST\" or any other label of your choice.")
@@ -207,6 +206,31 @@ class ClearCase(FetchMethod): output = runfetchcmd(cmd, d, workdir=ud.ccasedir) logger.info("rmview output: %s", output) + def _find_executable(executable, path=None): + """Tries to find 'executable' in the directories listed in 'path'. + + A string listing directories separated by 'os.pathsep'; defaults to + os.environ['PATH']. Returns the complete filename or None if not found. + """ + if path is None: + path = os.environ['PATH'] + + paths = path.split(os.pathsep) + base, ext = os.path.splitext(executable) + + if (sys.platform == 'win32') and (ext != '.exe'): + executable = executable + '.exe' + + if not os.path.isfile(executable): + for p in paths: + f = os.path.join(p, executable) + if os.path.isfile(f): + # the file exists, we have a shot at spawn working + return f + return None + else: + return executable + def need_update(self, ud, d): if ("LATEST" in ud.label) or (ud.customspec and "LATEST" in ud.customspec): ud.identifier += "-%s" % d.getVar("DATETIME",d, True)
lib/bb/fetch2/npm.py +0 -1
@@ -32,7 +32,6 @@ from bb.fetch2 import runfetchcmd from bb.fetch2 import logger from bb.fetch2 import UnpackError from bb.fetch2 import ParameterError -from distutils import spawn def subprocess_setup(): # Python installs a SIGPIPE handler by default. This is usually not what
Signature · 1 line
2.17.0
Hi there,
Thanks for the patch. A few comments:
1) All patches need to have Signed-off-by and a proper commit message. Please refer to: http://www.openembedded.org/wiki/Commit_Patch_Message_Guidelines
2) We shouldn't be copying in functions verbatim from Python, that's potentially problematic for licensing reasons if nothing else.
3) I wonder, is this even necessary? It should be searching PATH already, thus we should be able to just put the name of the executable we want to run without needing to find the full path. Looking at the other fetcher modules we typically use "/usr/bin/env <command> <options>" so I think that should work here as well.
Cheers,
Paul
Quoted 18 lines · NZST Tzu Hsiang Lin
--- lib/bb/fetch2/clearcase.py | 28 ++++++++++++++++++++++++++-- lib/bb/fetch2/npm.py | 1 - 2 files changed, 26 insertions(+), 3 deletions(-)lib/bb/fetch2/clearcase.py +0
-1@@ -69,7 +69,6 @@ from bb.fetch2 import FetchMethod from bb.fetch2 import FetchError from bb.fetch2 import runfetchcmd from bb.fetch2 import logger -from distutils import spawn class ClearCase(FetchMethod): """Class to fetch urls via 'clearcase'"""
lib/bb/fetch2/clearcase.py class ClearCase(FetchMethod): · line 110
Quoted 4 lines
lib/bb/fetch2/clearcase.py +0
-1@@ -107,7 +106,7 @@ class ClearCase(FetchMethod): else: ud.module = "" - ud.basecmd = d.getVar("FETCHCMD_ccrc") or
spawn.find_executable("cleartool") or spawn.find_executable("rcleartool")
lib/bb/fetch2/clearcase.py class ClearCase(FetchMethod): · line 109
Quoted 1 line
lib/bb/fetch2/clearcase.py +1
-0+ ud.basecmd = d.getVar("FETCHCMD_ccrc") or
_find_executable("cleartool") or _find_executable("rcleartool")
lib/bb/fetch2/clearcase.py class ClearCase(FetchMethod): · line 111
Quoted 3 lines
lib/bb/fetch2/clearcase.py +0
-0if d.getVar("SRCREV") == "INVALID": raise FetchError("Set a valid SRCREV for the clearcase fetcher in
your recipe, e.g. SRCREV = \"/main/LATEST\" or any other label of your choice.")
lib/bb/fetch2/clearcase.py class ClearCase(FetchMethod): · line 213
Quoted 9 lines
lib/bb/fetch2/clearcase.py +5
-0@@ -207,6 +206,31 @@ class ClearCase(FetchMethod): output = runfetchcmd(cmd, d, workdir=ud.ccasedir) logger.info("rmview output: %s", output) + def _find_executable(executable, path=None): + """Tries to find 'executable' in the directories listed in 'path'. + + A string listing directories separated by 'os.pathsep'; defaults to + os.environ['PATH']. Returns the complete filename or None if not
found.
Quoted 12 lines
lib/bb/fetch2/clearcase.py +12
-0+ """ + if path is None: + path = os.environ['PATH'] + + paths = path.split(os.pathsep) + base, ext = os.path.splitext(executable) + + if (sys.platform == 'win32') and (ext != '.exe'): + executable = executable + '.exe' + + if not os.path.isfile(executable): + for p in paths:
lib/bb/fetch2/clearcase.py class ClearCase(FetchMethod):
Quoted 10 lines
lib/bb/fetch2/clearcase.py +8
-0+ f = os.path.join(p, executable) + if os.path.isfile(f): + # the file exists, we have a shot at spawn working + return f + return None + else: + return executable + def need_update(self, ud, d): if ("LATEST" in ud.label) or (ud.customspec and "LATEST" in
ud.customspec):
lib/bb/fetch2/npm.py from bb.fetch2 import runfetchcmd · line 37
Quoted 13 lines
lib/bb/fetch2/clearcase.py +0
-0ud.identifier += "-%s" % d.getVar("DATETIME",d, True)lib/bb/fetch2/npm.py +0
-1@@ -32,7 +32,6 @@ from bb.fetch2 import runfetchcmd from bb.fetch2 import logger from bb.fetch2 import UnpackError from bb.fetch2 import ParameterError -from distutils import spawn def subprocess_setup(): # Python installs a SIGPIPE handler by default. This is usually not
what
Quoted 1 line
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre