Skip to content

Commit

Permalink
Merge pull request #6 from temken/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Timon Emken committed Apr 24, 2020
2 parents 9ea1fd9 + b0b167e commit c8e2c4d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.
Expand Down
20 changes: 18 additions & 2 deletions comparxiv/command_line.py
Expand Up @@ -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)",
Expand Down Expand Up @@ -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
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)

34 changes: 19 additions & 15 deletions comparxiv/comparxiv.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -90,7 +95,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

Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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) or (file.startswith(arxiv_ID) 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"
Expand Down
6 changes: 1 addition & 5 deletions comparxiv/tests/test_comparxiv.py
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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',
Expand Down

0 comments on commit c8e2c4d

Please sign in to comment.