scripts: iree script pylint cleanup Change-Id: I74f58130c7a39ba73882f14234c5cda8557cd59d
diff --git a/download_iree_compiler.py b/download_iree_compiler.py index 43a6baf..3be06a8 100755 --- a/download_iree_compiler.py +++ b/download_iree_compiler.py
@@ -6,11 +6,10 @@ import tarfile import time import argparse -import requests import urllib -import wget - from pathlib import Path +import requests +import wget def download_artifact(assets, keywords, out_dir): @@ -24,10 +23,10 @@ artifact_match = True break if not artifact_match: - print("%s is not found" % (keywords[0])) + print(f"{keywords[0]} is not found") sys.exit(1) - print("\nDownload %s from %s\n" % (artifact_name, download_url)) + print(f"\nDownload {artifact_name} from {download_url}\n") if not os.path.isdir(out_dir): os.makedirs(out_dir) out_file = os.path.join(out_dir, artifact_name) @@ -68,11 +67,12 @@ snapshot = None if args.tag_name: - r = requests.get(("%s/tags/%s" % (args.release_url, args.tag_name)), + r = requests.get((f"{args.release_url}/tags/{args.tag_name}"), auth=('user', 'pass')) if r.status_code != 200: - print("!!!!!IREE snapshot can't be found with tag %s, please try a " - "different tag!!!!!" % args.tag_name) + print( + f"!!!!!IREE snapshot can't be found with tag {args.tag_name}, " + "please try a different tag!!!!!") sys.exit(1) snapshot = r.json() else: @@ -86,14 +86,14 @@ tag_name = snapshot["tag_name"] commit_sha = snapshot["target_commitish"] - print("Snapshot: %s" % tag_name) + print(f"Snapshot: {tag_name}") tag_file = iree_compiler_dir / "tag" # Check the tag of the existing download. tag_match = False if os.path.isfile(tag_file): - with open(tag_file, 'r') as f: + with open(tag_file, 'r', encoding="utf-8") as f: for line in f: if tag_name == line.replace("\n", ""): tag_match = True @@ -111,7 +111,7 @@ snapshot["assets"], ["linux-x86_64.tar"], tmp_dir) # Install IREE TFLite tool - cmd = ("pip3 install %s --no-cache-dir" % whl_file) + cmd = (f"pip3 install {whl_file} --no-cache-dir") os.system(cmd) # Extract the tarball to ${iree_compiler_dir}/install @@ -119,17 +119,16 @@ if not install_dir: os.makedirs(install_dir) - tar = tarfile.open(tar_file) - tar.extractall(path=install_dir) - tar.close() + with tarfile.open(tar_file) as tar: + tar.extractall(path=install_dir) os.remove(tar_file) os.remove(whl_file) print("\nIREE compiler is installed") # Add tag file for future checks - with open(tag_file, "w") as f: - f.write("%s\ncommit_sha: %s\n" % (tag_name, commit_sha)) + with open(tag_file, "w", encoding="utf-8") as f: + f.write(f"{tag_name}\ncommit_sha: {commit_sha}\n") if __name__ == "__main__":