From 88ae6ef7229bbb2bef2016fc202ae27dc5100a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= Date: Sat, 28 Jan 2023 14:31:20 +0100 Subject: [PATCH 1/2] Remove un-Pythonic semicolons --- external/fetch_external_sources.py | 46 +++++++++++++++--------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/external/fetch_external_sources.py b/external/fetch_external_sources.py index 90720c6..78dab4d 100644 --- a/external/fetch_external_sources.py +++ b/external/fetch_external_sources.py @@ -37,7 +37,7 @@ from optparse import OptionParser -TargetDir = os.getcwd() + "/"; # target directory the source code downloaded to. +TargetDir = os.getcwd() + "/" # target directory the source code downloaded to. class GitRepo: def __init__(self, httpsUrl, moduleName, defaultRevision, extractDir): @@ -49,36 +49,36 @@ def __init__(self, httpsUrl, moduleName, defaultRevision, extractDir): def GetRevision(self): SrcFile = TargetDir + "../CHANGES"; if not os.path.exists(SrcFile): - print(SrcFile + " does not exist, default revision is " + self.revision); - return; + print(SrcFile + " does not exist, default revision is " + self.revision) + return - revFile = open(SrcFile,'r'); - lines = revFile.readlines(); + revFile = open(SrcFile,'r') + lines = revFile.readlines() found = False; for line in lines: if (found == True): if (line.find("Commit:") == 0): - self.revision = line[7:]; - break; + self.revision = line[7:] + break if (self.moduleName.lower() in line.lower()): - found = True; + found = True else: - found = False; - revFile.close(); + found = False + revFile.close() if (found == False): print("Warning: Revision is not gotten from " + SrcFile + " correctly, please check it!!!") else: - print("Get the revision of " + self.extractDir + ": " + self.revision); + print("Get the revision of " + self.extractDir + ": " + self.revision) def CheckOut(self): fullDstPath = os.path.join(TargetDir, self.extractDir) if not os.path.exists(fullDstPath): - os.system("git clone " + self.httpsUrl + " " + fullDstPath); + os.system("git clone " + self.httpsUrl + " " + fullDstPath) - os.chdir(fullDstPath); - os.system("git fetch"); - os.system("git checkout " + self.revision); + os.chdir(fullDstPath) + os.system("git fetch") + os.system("git checkout " + self.revision) PACKAGES = [ GitRepo("https://github.com/KhronosGroup/glslang.git", "glslang", "980ac508", "glslang"), @@ -88,7 +88,7 @@ def CheckOut(self): ] def GetOpt(): - global TargetDir; + global TargetDir parser = OptionParser() @@ -100,15 +100,15 @@ def GetOpt(): (options, args) = parser.parse_args() if options.targetdir: - print("The source code is downloaded to %s" % (options.targetdir)); - TargetDir = options.targetdir; + print("The source code is downloaded to %s" % (options.targetdir)) + TargetDir = options.targetdir else: - print("The target directory is not specified, using default: " + TargetDir); + print("The target directory is not specified, using default: " + TargetDir) def DownloadSourceCode(): - global TargetDir; + global TargetDir - os.chdir(TargetDir); + os.chdir(TargetDir) # Touch the spvgen CMakeLists.txt to ensure that the new directories get used. os.utime('../CMakeLists.txt', None) @@ -117,5 +117,5 @@ def DownloadSourceCode(): pkg.GetRevision() pkg.CheckOut() -GetOpt(); -DownloadSourceCode(); +GetOpt() +DownloadSourceCode() From 86580cd72bc1e2bb4a3ea6864760151f3e23411b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= Date: Sat, 28 Jan 2023 14:31:21 +0100 Subject: [PATCH 2/2] Default to the directory of fetch_external_sources.py instead of CWD This is more likely to be what people need, i.e. in other projects that have a "fetch sources" script, the guidance is often to invoke it like $ python3 external/fetch_external_sources.py That doesn't work based on CWD, but it does work based on the script file itself. --- external/fetch_external_sources.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/external/fetch_external_sources.py b/external/fetch_external_sources.py index 78dab4d..6aa867e 100644 --- a/external/fetch_external_sources.py +++ b/external/fetch_external_sources.py @@ -33,11 +33,13 @@ import sys import os +import os.path import string from optparse import OptionParser -TargetDir = os.getcwd() + "/" # target directory the source code downloaded to. +# Target directory the source code downloaded to by default. +TargetDir = os.path.dirname(os.path.abspath(__file__)) class GitRepo: def __init__(self, httpsUrl, moduleName, defaultRevision, extractDir):