From 7201488f9503753466084f2a37a35617a7cba100 Mon Sep 17 00:00:00 2001 From: saisoma123 Date: Tue, 19 Jul 2022 13:35:10 -0400 Subject: [PATCH] Added indentation and spacing as well as fixing variable references --- interpreter/cling/tools/packaging/cpt.py | 73 ++++++++++++------------ 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/interpreter/cling/tools/packaging/cpt.py b/interpreter/cling/tools/packaging/cpt.py index 1aa3a831712ae..30b4a2d88be16 100755 --- a/interpreter/cling/tools/packaging/cpt.py +++ b/interpreter/cling/tools/packaging/cpt.py @@ -51,7 +51,7 @@ def _convert_subprocess_cmd(cmd): if OS == 'Windows': - cmd = cmd.replace('\\','/') + cmd = cmd.replace('\\', '/') return shlex.split(cmd, posix=True, comments=True) @@ -64,7 +64,8 @@ def _perror(e): def exec_subprocess_call(cmd, cwd, showCMD=False): - if showCMD: print(cmd) + if showCMD: + print(cmd) cmd = _convert_subprocess_cmd(cmd) try: subprocess.check_call(cmd, cwd=cwd, shell=False, @@ -87,13 +88,13 @@ def exec_subprocess_check_output(cmd, cwd): def travis_fold_start(tag): if os.environ.get('TRAVIS_BUILD_DIR', None): - print('travis_fold:start:cpt-%s:' % (tag)) + print('travis_fold:start:cpt-%s:' % (tag)) def travis_fold_end(tag): - if os.environ.get('TRAVIS_BUILD_DIR', None): + if os.environ.get('TRAVIS_BUILD_DIR', None): - print('travis_fold:end:cpt-%s:' % (tag)) + print('travis_fold:end:cpt-%s:' % (tag)) def box_draw_header(): @@ -225,7 +226,7 @@ def update_old_llvm(): checkout() exec_subprocess_call('git fetch --tags', srcdir) exec_subprocess_call('git pull origin refs/tags/cling-patches-r%s' - % llvm_revision, srcdir) + % llvm_revision, srcdir) if os.path.isdir(srcdir): update_old_llvm() @@ -301,6 +302,7 @@ def __init__(self, url, rootDir, depth=10): self.__depth = depth self.__projDir = rootDir self.__workDir = os.path.join(rootDir, url.split('/')[-1]) + def fetch(self, branch): if os.path.isdir(self.__workDir): exec_subprocess_call('git stash', self.__workDir) @@ -340,7 +342,9 @@ def fetch_clang(llvm_revision): else: dir = os.path.join(srcdir, 'tools') global clangdir + clangdir = os.path.join(dir, 'clang') + def checkout(): exec_subprocess_call('git checkout cling-patches-r%s' % llvm_revision, clangdir) @@ -356,9 +360,10 @@ def update_old_clang(): exec_subprocess_call('git fetch --tags', clangdir) checkout() + exec_subprocess_call('git fetch --tags', clangdir) exec_subprocess_call('git pull origin refs/tags/cling-patches-r%s' % llvm_revision, - clangdir) + clangdir) if os.path.isdir(clangdir): update_old_clang() @@ -554,8 +559,8 @@ def compile(arg): print("Creating build directory: " + LLVM_OBJ_ROOT) os.makedirs(LLVM_OBJ_ROOT) - ### FIX: Target isn't being set properly on Travis OS X - ### Either because ccache(when enabled) or maybe the virtualization environment + # FIX: Target isn't being set properly on Travis OS X + # Either because ccache(when enabled) or maybe the virtualization environment if TRAVIS_BUILD_DIR and OS == 'Darwin': triple = exec_subprocess_check_output('sh %s/cmake/config.guess' % srcdir, srcdir) if triple: @@ -575,7 +580,7 @@ def compile(arg): build.make('install') if TRAVIS_BUILD_DIR: - ### Run cling once, dumping the include paths, helps debug issues + # Run cling once, dumping the include paths, helps debug issues try: subprocess.check_call(os.path.join(workdir, 'builddir', 'bin', 'cling') + ' -v ".I"', shell=True) @@ -616,7 +621,7 @@ def compile_for_binary(arg): build.make('install') if TRAVIS_BUILD_DIR: - ### Run cling once, dumping the include paths, helps debug issues + # Run cling once, dumping the include paths, helps debug issues try: subprocess.check_call(os.path.join(workdir, 'builddir', 'bin', 'cling') + ' -v ".I"', shell=True) @@ -635,8 +640,8 @@ def install_prefix(): regex_array = [] regex_filename = os.path.join(CPT_SRC_DIR, 'dist-files.txt') for line in open(regex_filename).read().splitlines(): - if line and not line.startswith('#'): - regex_array.append(line) + if line and not line.startswith('#'): + regex_array.append(line) for root, dirs, files in os.walk(TMP_PREFIX): for file in files: @@ -644,9 +649,10 @@ def install_prefix(): if OS == 'Windows': f = f.replace('\\', '/') for regex in regex_array: - if args['with_verbose_output']: print ("Applying regex " + regex + " to file " + f) + if args['with_verbose_output']: + print("Applying regex " + regex + " to file " + f) if re.search(regex, f): - print ("Adding to final binary " + f) + print("Adding to final binary " + f) if not os.path.isdir(os.path.join(prefix, os.path.dirname(f))): os.makedirs(os.path.join(prefix, os.path.dirname(f))) shutil.copy(os.path.join(TMP_PREFIX, f), os.path.join(prefix, f)) @@ -665,8 +671,8 @@ def install_prefix_for_binary(): regex_array = [] regex_filename = os.path.join(CPT_SRC_DIR, 'dist-files.txt') for line in open(regex_filename).read().splitlines(): - if line and not line.startswith('#'): - regex_array.append(line) + if line and not line.startswith('#'): + regex_array.append(line) for root, dirs, files in os.walk(TMP_PREFIX): for file in files: @@ -674,9 +680,10 @@ def install_prefix_for_binary(): if OS == 'Windows': f = f.replace('\\', '/') for regex in regex_array: - if args['with_verbose_output']: print ("Applying regex " + regex + " to file " + f) + if args['with_verbose_output']: + print("Applying regex " + regex + " to file " + f) if re.search(regex, f): - print ("Adding to final binary " + f) + print("Adding to final binary " + f) if not os.path.isdir(os.path.join(prefix, os.path.dirname(f))): os.makedirs(os.path.join(prefix, os.path.dirname(f))) shutil.copy(os.path.join(TMP_PREFIX, f), os.path.join(prefix, f)) @@ -684,7 +691,7 @@ def install_prefix_for_binary(): travis_fold_end("install") -def runSingleTest(test, Idx = 2, Recurse = True): +def runSingleTest(test, Idx=2, Recurse=True): try: test = os.path.join(CLING_SRC_DIR, 'test', test) @@ -759,7 +766,7 @@ def setup_tests(): else: llvm_dir = os.path.join("/usr", "lib", "llvm-" + llvm_vers, "build") subprocess.Popen( - ["sudo mkdir {1}/utils/".format(commit, llvm_dir)], + ["sudo mkdir {0}/utils/".format(llvm_dir)], cwd=os.path.join(CLING_SRC_DIR, "tools"), shell=True, stdin=subprocess.PIPE, @@ -861,7 +868,7 @@ def cleanup(): def check_version_string_ge(vstring, min_vstring): version_fields = [int(x) for x in vstring.split('.')] min_versions = [int(x) for x in min_vstring.split('.')] - for i in range(0,len(min_versions)): + for i in range(0, len(min_versions)): if version_fields[i] < min_versions[i]: return False elif version_fields[i] > min_versions[i]: @@ -1086,7 +1093,7 @@ def debianize(): # -*- makefile -*- %: - dh $@ + dh $@ override_dh_auto_build: @@ -1318,7 +1325,6 @@ def check_win(pkg): print(pkg.ljust(20) + '[OK]'.ljust(30)) - def is_os_64bit(): return platform.machine().endswith('64') @@ -1346,7 +1352,7 @@ def tryCmake(cmake): vers = [int(v) for v in rslt.split()[2].split('.')] if vers[0] >= 3 and (vers[1] > 6 or (vers[1] == 6 and vers[2] >= 2)): return cmake - except: + except Exception: pass return False @@ -1677,7 +1683,7 @@ def check_mac(pkg): def make_dmg(): box_draw("Building Apple Disk Image") APP_NAME = 'Cling' - DMG_BACKGROUND_IMG = 'graphic.png' + # DMG_BACKGROUND_IMG = 'graphic.png' APP_EXE = '%s.app/Contents/MacOS/bin/%s' % (APP_NAME, APP_NAME.lower()) VOL_NAME = "%s-%s" % (APP_NAME.lower(), VERSION) DMG_TMP = "%s-temp.dmg" % (VOL_NAME) @@ -1703,7 +1709,6 @@ def make_dmg(): print("Remove file: " + os.path.join(workdir, DMG_FINAL)) os.remove(os.path.join(workdir, DMG_FINAL)) - if os.path.isdir(os.path.join(workdir, '%s.app' % (APP_NAME))): print("Remove directory:", os.path.join(workdir, '%s.app' % (APP_NAME))) shutil.rmtree(os.path.join(workdir, '%s.app' % (APP_NAME))) @@ -1714,7 +1719,7 @@ def make_dmg(): print('Populate directory: ' + os.path.join(workdir, '%s.app' % (APP_NAME), 'Contents', 'MacOS')) shutil.copytree( prefix, - os.path.join(workdir, '%s.app'%(APP_NAME), 'Contents', 'MacOS') + os.path.join(workdir, '%s.app' % (APP_NAME), 'Contents', 'MacOS') ) os.makedirs(os.path.join(workdir, '%s.app' % (APP_NAME), 'Contents', 'Resources')) @@ -1722,8 +1727,6 @@ def make_dmg(): os.path.join(CPT_SRC_DIR, 'LLVM.icns'), os.path.join(workdir, '%s.app' % (APP_NAME), 'Contents', 'Resources', 'LLVM.icns') ) - - print('Configuring Info.plist file') plist_path = os.path.join(workdir, '%s.app' % (APP_NAME), 'Contents', 'Info.plist') f = open(plist_path, 'w') @@ -1765,11 +1768,8 @@ def make_dmg(): f.write(plist_xml) f.close() - - print('Copy APP Bundle to staging area: ' + STAGING_DIR) shutil.copytree(os.path.join(workdir, '%s.app' % (APP_NAME)), STAGING_DIR) - print('Stripping file: ' + APP_EXE) exec_subprocess_call('strip -u -r %s' % os.path.join(workdir, APP_EXE), workdir) @@ -1865,6 +1865,7 @@ def custom_input(prompt, always_yes=False): # Global variables # ############################################################################### + if __name__ == "__main__": workdir = os.path.abspath(os.path.expanduser(args['with_workdir'])) srcdir = os.path.join(workdir, 'cling-src') @@ -1916,7 +1917,7 @@ def custom_input(prompt, always_yes=False): elif OS == 'Linux': try: import distro - except: + except Exception: yes = {'yes', 'y', 'ye', ''} choice = custom_input(''' CPT will now attempt to install the distro package automatically. @@ -2002,7 +2003,7 @@ def custom_input(prompt, always_yes=False): LLVM_GIT_URL = args['with_llvm_url'] else: LLVM_GIT_URL = "http://root.cern.ch/git/llvm.git" - + if args['with_binary_llvm'] and args['with_llvm_tar']: raise Exception("Cannot specify flags --with-binary-llvm and --with-llvm-tar together") @@ -2066,7 +2067,7 @@ def custom_input(prompt, always_yes=False): stdin=subprocess.PIPE, stdout=None, stderr=subprocess.STDOUT).communicate('yes'.encode('utf-8')) - except: + except Exception: tar_required = True elif OS == 'Windows':