From 9c2fb51a24db08473e327ce57e97f0df107a44c9 Mon Sep 17 00:00:00 2001 From: Timon Emken Date: Fri, 24 Apr 2020 08:06:46 +0200 Subject: [PATCH 1/4] Adds a check of the arxiv ID input. --- README.md | 2 +- comparxiv/command_line.py | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 05c47c7..ba78c06 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ comparxiv hep-ph/0612370 It is also possible to run ``` -comparxiv 1709.06573v*N* +comparxiv 1709.06573v[N] ``` This will compare version *N* to *N-1*, and the optional second and third arguments are ignored. diff --git a/comparxiv/command_line.py b/comparxiv/command_line.py index f598ef7..8b44c42 100644 --- a/comparxiv/command_line.py +++ b/comparxiv/command_line.py @@ -11,7 +11,7 @@ def main(): parser.add_argument("-P","--dont_open_pdf", help="Do not automatically open the generated pdf in the end.", action="store_true") parser.add_argument("arxiv_ID", help = "The arXiv ID of the paper to be compared, e.g. \'1905.06348\'.", - type = str) + type = check_arxiv_ID) parser.add_argument("version_A", help = "The reference version of the preprint to be compared. (Default: 1)", nargs='?', default = 1, type = check_version_input) parser.add_argument("version_B", help = "The new version of the preprint to be compared. (Default: 2)", @@ -39,4 +39,20 @@ def check_version_input(value): raise argparse.ArgumentTypeError("Version %s is an invalid arXiv version." % value) if ivalue < 1: raise argparse.ArgumentTypeError("Version %s is an invalid arXiv version." % value) - return ivalue \ No newline at end of file + return ivalue + +def check_arxiv_ID(ID): + is_valid_ID = False + # New IDs + if ID[4] == "." and ID.split(".",1)[0].isdigit() and int(ID[2:4])<13 and ID[-1].isdigit(): + is_valid_ID = True + # Old IDs + elif "/" in ID: + i = ID.find("/") + if ID[i+3:i+5].isdigit() and int(ID[i+3:i+5]) < 13 and ID[-1].isdigit(): + is_valid_ID = True + if is_valid_ID: + return ID + else: + raise argparse.ArgumentTypeError("The input %s is not a valid arXiv ID." % ID) + \ No newline at end of file From 50decc5e2182548193dc73aa0a7fe0e04c00ecba Mon Sep 17 00:00:00 2001 From: Timon Emken Date: Fri, 24 Apr 2020 08:29:17 +0200 Subject: [PATCH 2/4] Adds a new test. --- comparxiv/tests/test_comparxiv.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/comparxiv/tests/test_comparxiv.py b/comparxiv/tests/test_comparxiv.py index 2b32d29..2ca97d0 100755 --- a/comparxiv/tests/test_comparxiv.py +++ b/comparxiv/tests/test_comparxiv.py @@ -4,10 +4,6 @@ from ..comparxiv import * def test_comparxiv(): - test_preprints = ["hep-ph/0612065","1709.06573"] + test_preprints = ["hep-ph/0612065","1709.06573","1905.05776"] for ID in test_preprints: - if "/" in ID: - diff_file = os.path.split(ID)[-1]+"_v1v2" - else: - diff_file = ID+"_v1v2" assert compare_preprints(ID, 1, 2, False, False, True) From 50c51f885e2282fcea2654a65049b91b52fb3b31 Mon Sep 17 00:00:00 2001 From: Timon Emken Date: Fri, 24 Apr 2020 08:29:54 +0200 Subject: [PATCH 3/4] Fixes the removal of temporary files for old arxiv IDs. --- comparxiv/comparxiv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/comparxiv/comparxiv.py b/comparxiv/comparxiv.py index b758b76..611a395 100755 --- a/comparxiv/comparxiv.py +++ b/comparxiv/comparxiv.py @@ -90,7 +90,7 @@ def compare_preprints(arxiv_ID, version_a, version_b,keep_temp,show_latex_output #8. Delete temporary files if keep_temp == False: - remove_temporary_files(arxiv_ID) + remove_temporary_files(ID_a) return success @@ -193,7 +193,7 @@ def identify_bbl_file(path, arxiv_ID): def remove_temporary_files(arxiv_ID): print("Delete temporary files:") for file in os.listdir("."): - if file.startswith(".temp_"+arxiv_ID) or (file.startswith(arxiv_ID) and not file.endswith("pdf")): + if file.startswith(".temp_"+arxiv_ID[0:7]) or (file.startswith(arxiv_ID[0:7]) and not file.endswith("pdf")): print("\t",file) os.system("rm -r "+ file) From b0b167ea74cb88d2e8733fa7e258807616cfac83 Mon Sep 17 00:00:00 2001 From: Timon Emken Date: Fri, 24 Apr 2020 08:55:24 +0200 Subject: [PATCH 4/4] Moves all the temp file to a single hidden folder. --- comparxiv/comparxiv.py | 32 ++++++++++++++++++-------------- setup.py | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/comparxiv/comparxiv.py b/comparxiv/comparxiv.py index 611a395..ae18f9a 100755 --- a/comparxiv/comparxiv.py +++ b/comparxiv/comparxiv.py @@ -7,10 +7,11 @@ from sys import platform from tqdm import tqdm -version = '0.1.2' +version = '0.1.3' author = 'Timon Emken' year = '2020' +temp_folder = ".temp_comparxiv/" def compare_preprints(arxiv_ID, version_a, version_b,keep_temp,show_latex_output,dont_open_pdf): #Check if old or new arxiv ID @@ -21,8 +22,12 @@ def compare_preprints(arxiv_ID, version_a, version_b,keep_temp,show_latex_output ID_a = arxiv_ID+"v"+str(version_a) ID_b = arxiv_ID+"v"+str(version_b) - temp_folder_a = './.temp_'+ID_a+'/' - temp_folder_b = './.temp_'+ID_b+'/' + #Create folder for temporary files + if os.path.exists(temp_folder) == False: + os.mkdir(temp_folder) + + temp_folder_a = './' + temp_folder + 'temp_' + ID_a+'/' + temp_folder_b = './' + temp_folder + 'temp_' + ID_b+'/' diff_file = os.path.split(arxiv_ID)[-1]+"_v"+str(version_a)+"v"+str(version_b) # #1. Download and unpack files @@ -103,7 +108,7 @@ def Generate_PDF(file, folder, show_latex_output): print("\t",pdflatex_command,"\n") os.system(pdflatex_command) os.system(pdflatex_command) - os.chdir("..") + os.chdir("../..") #Download the files from the preprint server, if it hasn't been done before. @@ -132,10 +137,10 @@ def download_from_url(url, destination): def download_from_arxiv(arxiv_ID,version): #Check if old or new arxiv ID if "/" in arxiv_ID: - filepath = "./"+os.path.split(arxiv_ID)[-1]+"v"+str(version) + filepath = "./"+temp_folder+os.path.split(arxiv_ID)[-1]+"v"+str(version) else: - filepath = "./"+arxiv_ID+"v"+str(version) + filepath = "./"+temp_folder+arxiv_ID+"v"+str(version) if os.path.isfile(filepath) == False: url="https://arxiv.org/e-print/"+arxiv_ID+"v"+str(version) @@ -148,14 +153,16 @@ def unpack_source_files(arxiv_ID,version,path_destination): version_ID = arxiv_ID+"v"+str(version) #Check if old or new arxiv ID if "/" in arxiv_ID: - path_source = "./"+os.path.split(version_ID)[-1] + path_source = "./"+temp_folder+os.path.split(version_ID)[-1] else: - path_source = "./"+version_ID + path_source = "./"+temp_folder+version_ID + + print(path_destination,path_source) # Create folder for temporary files print("Unpack source files of",version_ID,"to",path_destination,".") if os.path.isfile(path_source) and os.path.exists(path_destination) == False: - os.mkdir(path_destination) + os.makedirs(path_destination) # Unpack files os.system('tar -xzf '+path_source +' -C '+ path_destination) @@ -191,11 +198,8 @@ def identify_bbl_file(path, arxiv_ID): return bbl_file def remove_temporary_files(arxiv_ID): - print("Delete temporary files:") - for file in os.listdir("."): - if file.startswith(".temp_"+arxiv_ID[0:7]) or (file.startswith(arxiv_ID[0:7]) and not file.endswith("pdf")): - print("\t",file) - os.system("rm -r "+ file) + print("Delete temporary files.") + os.system("rm -r "+ temp_folder) def print_title(ID,v1,v2): asci_title = " __ ___ \n ___ ___ _ __ ___ _ __ __ _ _ _\ \/ (_)_ __\n / __/ _ \| '_ ` _ \| '_ \ / _` | '__\ /| \ \ / /\n| (_| (_) | | | | | | |_) | (_| | | / \| |\ V / \n \___\___/|_| |_| |_| .__/ \__,_|_| /_/\_\_| \_/ \n |_| \n" diff --git a/setup.py b/setup.py index a60da40..13b83eb 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ def readme(): return f.read() setup(name='comparxiv', - version='0.1.2', + version='0.1.3', description='Compare two versions of an arXiv preprint with latexdiff.', long_description = readme(), long_description_content_type='text/markdown',