From c5be3f5079422940ac04475e1834b8b588347ad0 Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Sun, 21 Aug 2022 19:06:26 +0200 Subject: [PATCH 1/3] Update port git_tester.py on Windows --- examples/git_tester.py | 64 ++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/examples/git_tester.py b/examples/git_tester.py index aaf70c82..990f7eba 100644 --- a/examples/git_tester.py +++ b/examples/git_tester.py @@ -1,34 +1,44 @@ +import os + +from sys import platform from pydriller import Repository -import os -import datetime -os.system("cp examples/speedtest.py examples/speedtest2.py") # the file has to be outside of git -for idx, commit in enumerate(Repository('.', from_tag="v0.6.0").traverse_commits()): - name=commit.msg.replace('\n', ' ').replace('\r', ' ') - print(idx, commit.hash, name) +if platform == "win32": + copy_cmd = "copy" + rm_dir_cmd = "rmdir /s /q" +else: + copy_cmd = "cp" + rm_dir_cmd = "rm -rf" +speedtest_src_path = os.path.join("examples", "speedtest.py") +speedtest_path = os.path.join("examples", "speedtest2.py") +os.system(f"{copy_cmd} {speedtest_src_path} {speedtest_path}") # the file has to be outside of git + +commits = list(Repository('.', from_tag="v0.6.0").traverse_commits()) +print("Found commits:") +for idx, commit in enumerate(commits): + name = commit.msg.replace('\n', ' ').replace('\r', ' ') + print(idx, commit.hash, name) -for commit in Repository('.', from_tag="v0.6.0").traverse_commits(): - - name=commit.msg.replace('\n', ' ').replace('\r', ' ') - print(commit.hash, name) - - os.system(f"git checkout {commit.hash}; rm -rf build; ") +for commit in commits: + name = commit.msg.replace('\n', ' ').replace('\r', ' ') + print("\nProcessing", commit.hash, name) + + os.system(f"git checkout {commit.hash}") + os.system(f"{rm_dir_cmd} build") print("\n\n--------------------\n\n") - ret=os.system("python -m pip install .") - print(ret) - - if ret != 0: - print ("build failed!!!!") - print ("build failed!!!!") - print ("build failed!!!!") - print ("build failed!!!!") - continue - - os.system(f'python examples/speedtest2.py -n "{name}" -d 4 -t 1') - os.system(f'python examples/speedtest2.py -n "{name}" -d 64 -t 1') - os.system(f'python examples/speedtest2.py -n "{name}" -d 128 -t 1') - os.system(f'python examples/speedtest2.py -n "{name}" -d 4 -t 24') - os.system(f'python examples/speedtest2.py -n "{name}" -d 128 -t 24') + ret = os.system("python -m pip install .") + print("Install result:", ret) + if ret != 0: + print("build failed!!!!") + print("build failed!!!!") + print("build failed!!!!") + print("build failed!!!!") + continue + os.system(f'python {speedtest_path} -n "{name}" -d 4 -t 1') + os.system(f'python {speedtest_path} -n "{name}" -d 64 -t 1') + os.system(f'python {speedtest_path} -n "{name}" -d 128 -t 1') + os.system(f'python {speedtest_path} -n "{name}" -d 4 -t 24') + os.system(f'python {speedtest_path} -n "{name}" -d 128 -t 24') From e8da5a09955fb8f899ff360616e6b9f570d38677 Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Sat, 27 Aug 2022 12:02:08 +0200 Subject: [PATCH 2/3] Refactoring --- examples/git_tester.py | 14 +++++++------- python_bindings/bindings.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/git_tester.py b/examples/git_tester.py index 990f7eba..39a3af6c 100644 --- a/examples/git_tester.py +++ b/examples/git_tester.py @@ -11,8 +11,8 @@ rm_dir_cmd = "rm -rf" speedtest_src_path = os.path.join("examples", "speedtest.py") -speedtest_path = os.path.join("examples", "speedtest2.py") -os.system(f"{copy_cmd} {speedtest_src_path} {speedtest_path}") # the file has to be outside of git +speedtest_copy_path = os.path.join("examples", "speedtest2.py") +os.system(f"{copy_cmd} {speedtest_src_path} {speedtest_copy_path}") # the file has to be outside of git commits = list(Repository('.', from_tag="v0.6.0").traverse_commits()) print("Found commits:") @@ -37,8 +37,8 @@ print("build failed!!!!") continue - os.system(f'python {speedtest_path} -n "{name}" -d 4 -t 1') - os.system(f'python {speedtest_path} -n "{name}" -d 64 -t 1') - os.system(f'python {speedtest_path} -n "{name}" -d 128 -t 1') - os.system(f'python {speedtest_path} -n "{name}" -d 4 -t 24') - os.system(f'python {speedtest_path} -n "{name}" -d 128 -t 24') + os.system(f'python {speedtest_copy_path} -n "{name}" -d 4 -t 1') + os.system(f'python {speedtest_copy_path} -n "{name}" -d 64 -t 1') + os.system(f'python {speedtest_copy_path} -n "{name}" -d 128 -t 1') + os.system(f'python {speedtest_copy_path} -n "{name}" -d 4 -t 24') + os.system(f'python {speedtest_copy_path} -n "{name}" -d 128 -t 24') diff --git a/python_bindings/bindings.cpp b/python_bindings/bindings.cpp index 3050d972..a72b5b21 100644 --- a/python_bindings/bindings.cpp +++ b/python_bindings/bindings.cpp @@ -155,7 +155,7 @@ class Index { void loadIndex(const std::string &path_to_index, size_t max_elements) { if (appr_alg) { - std::cerr<<"Warning: Calling load_index for an already inited index. Old index is being deallocated."; + std::cerr << "Warning: Calling load_index for an already inited index. Old index is being deallocated." << std::endl; delete appr_alg; } appr_alg = new hnswlib::HierarchicalNSW(l2space, path_to_index, false, max_elements); @@ -768,7 +768,7 @@ class BFIndex { void loadIndex(const std::string &path_to_index, size_t max_elements) { if (alg) { - std::cerr<<"Warning: Calling load_index for an already inited index. Old index is being deallocated."; + std::cerr << "Warning: Calling load_index for an already inited index. Old index is being deallocated." << std::endl; delete alg; } alg = new hnswlib::BruteforceSearch(space, path_to_index); From bdd022035b5ffcf7ba1bd322bcccd6bc527f3ab1 Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Sun, 28 Aug 2022 10:24:23 +0200 Subject: [PATCH 3/3] Use shutil --- examples/git_tester.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/examples/git_tester.py b/examples/git_tester.py index 39a3af6c..be3b8a25 100644 --- a/examples/git_tester.py +++ b/examples/git_tester.py @@ -1,18 +1,13 @@ import os +import shutil from sys import platform from pydriller import Repository -if platform == "win32": - copy_cmd = "copy" - rm_dir_cmd = "rmdir /s /q" -else: - copy_cmd = "cp" - rm_dir_cmd = "rm -rf" speedtest_src_path = os.path.join("examples", "speedtest.py") speedtest_copy_path = os.path.join("examples", "speedtest2.py") -os.system(f"{copy_cmd} {speedtest_src_path} {speedtest_copy_path}") # the file has to be outside of git +shutil.copyfile(speedtest_src_path, speedtest_copy_path) # the file has to be outside of git commits = list(Repository('.', from_tag="v0.6.0").traverse_commits()) print("Found commits:") @@ -24,8 +19,9 @@ name = commit.msg.replace('\n', ' ').replace('\r', ' ') print("\nProcessing", commit.hash, name) + if os.path.exists("build"): + shutil.rmtree("build") os.system(f"git checkout {commit.hash}") - os.system(f"{rm_dir_cmd} build") print("\n\n--------------------\n\n") ret = os.system("python -m pip install .") print("Install result:", ret)