Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade arxiv dependency to 1.4.1 #18

Merged
merged 5 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions comparxiv/comparxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ def compare_preprints(arxiv_ID, version_a, version_b,keep_temp,show_latex_output
print_title(arxiv_ID, version_a, version_b)

#Check if old or new arxiv ID
if "/" in arxiv_ID:
ID_a = os.path.split(arxiv_ID)[-1]+"v"+str(version_a)
ID_b = os.path.split(arxiv_ID)[-1]+"v"+str(version_b)
else:
ID_a = arxiv_ID+"v"+str(version_a)
ID_b = arxiv_ID+"v"+str(version_b)
ID_a = arxiv_ID+"v"+str(version_a)
ID_b = arxiv_ID+"v"+str(version_b)

#Create folder for temporary files
if os.path.exists(temp_folder) == False:
Expand Down Expand Up @@ -124,20 +120,19 @@ def compare_preprints(arxiv_ID, version_a, version_b,keep_temp,show_latex_output
return success

def print_paper_information(arxiv_ID,vA,vB):
papers = arxiv.query(query="",
id_list=[arxiv_ID + "v" + str(vA),arxiv_ID + "v" + str(vB)],
max_results=2)
to_id = lambda v: '{}v{}'.format(arxiv_ID, str(v))
papers = list_papers([to_id(vA),to_id(vB)])
if papers[0].title != papers[1].title:
print("New title:\t%s" % papers[1].title)
print("Old title:\t%s" % papers[0].title)
else:
print("Title:\t\t%s" % papers[1].title)
if len(papers[1].authors) == 1:
print("Author:\t\t%s\n" % papers[1].authors[0])
print("Author:\t\t%s\n" % papers[1].authors[0].name)
elif len(papers[1].authors) > 6:
print("Authors:\t%s et al.\n" % papers[1].authors[0])
print("Authors:\t%s et al.\n" % papers[1].authors[0].name)
else:
print("Authors:\t",", " . join(papers[1].authors),"\n")
print("Authors:\t",", " . join([a.name for a in papers[1].authors]),"\n")

def check_arguments(arxiv_ID,vA,vB):
#1. Check for identical versions
Expand Down Expand Up @@ -173,22 +168,11 @@ def check_arguments(arxiv_ID,vA,vB):
os.abort()

def latest_available_version(arxiv_ID):
papers= arxiv.query(query="",
id_list=[arxiv_ID],
max_results=1)
papers = list_papers([arxiv_ID])
if len(papers) == 0:
print("Error: The paper [%s] cannot be found on the preprint server." % (arxiv_ID))
os.abort()
version_max = 1
while version_max < 100:
paper = arxiv.query(query="",
id_list=[arxiv_ID+"v"+str(version_max + 1)],
max_results=1)
if len(paper) > 0 and paper[0].id.split("v")[-1] == str(version_max + 1) :
version_max += 1
else:
break
return version_max
return int(papers[0].get_short_id().split("v")[-1])

def Generate_PDF(tex_file, folder, show_latex_output):
owd = os.getcwd()
Expand All @@ -203,6 +187,12 @@ def Generate_PDF(tex_file, folder, show_latex_output):
os.system(pdflatex_command)
os.chdir(owd)

def list_papers(ids):
try:
return list(arxiv.Search(id_list=ids).results())
except AttributeError:
# NOTE(lukasschwab): see lukasschwab/arxiv.py#80.
return []

#Download the files from the preprint server, if it hasn't been done before.
def download_from_url(url, destination):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def readme():
'tqdm',
'argparse',
'requests',
'arxiv==0.5.3'
'arxiv==1.4.1'
],
entry_points = {
'console_scripts': ['comparxiv=comparxiv.command_line:main'],
Expand Down
30 changes: 14 additions & 16 deletions tests/test_comparxiv.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
#!/usr/bin/env python
import os
import pytest

from comparxiv.comparxiv import *
from comparxiv.command_line import *

def test_comparxiv():
test_preprints = ["hep-ph/0612065","1709.06573","1901.04503","1905.05776"]
@pytest.mark.parametrize("ID",["hep-ph/0612065","1709.06573","1901.04503","1905.05776"])
def test_comparxiv(ID):
keep_temp_files = False
show_latex_output = False
dont_open_pdf = True
dont_compare_equations = False
for ID in test_preprints:
assert compare_preprints(ID, 1, 2, keep_temp_files, show_latex_output, dont_open_pdf, dont_compare_equations)
assert compare_preprints(ID, 1, 2, keep_temp_files, show_latex_output, dont_open_pdf, dont_compare_equations), "comparison unsuccessful"

def test_command_line():
tests = [
["comparxiv --dont_open_pdf 1907.06674 1 2","1907.06674_v1v2.pdf"],
["comparxiv --dont_open_pdf 1907.06674v3","1907.06674_v2v3.pdf"],
["comparxiv --dont_open_pdf 1410.0314 3","1410.0314_v2v3.pdf"],
["comparxiv --dont_open_pdf 1410.0314v1 3","1410.0314_v1v3.pdf"],
["comparxiv --dont_open_pdf 1709.06573","1709.06573_v1v2.pdf"]
]

for test in tests:
os.system(test[0])
assert os.path.isfile(test[1])
@pytest.mark.parametrize("cmd, pdf",[
("comparxiv --dont_open_pdf 1907.06674 1 2","1907.06674_v1v2.pdf"),
("comparxiv --dont_open_pdf 1907.06674v3","1907.06674_v2v3.pdf"),
("comparxiv --dont_open_pdf 1410.0314 3","1410.0314_v2v3.pdf"),
("comparxiv --dont_open_pdf 1410.0314v1 3","1410.0314_v1v3.pdf"),
("comparxiv --dont_open_pdf 1709.06573","1709.06573_v1v2.pdf")
])
def test_command_line(cmd, pdf):
os.system(cmd)
assert os.path.isfile(pdf), "missing expected PDF output: {}".format(pdf)