Skip to content

Commit

Permalink
Fix windows error (#492)
Browse files Browse the repository at this point in the history
* windows subprocess error

* using python rather than python3, we assume python is linked to python3
  • Loading branch information
MXueguang authored Apr 21, 2021
1 parent f29307a commit 2adbf1b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion integrations/run_simplesearcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RunSimpleSearcher:
def __init__(self, index: str, topics: str):
self.index_path = index
self.topics = topics
self.pyserini_base_cmd = 'python3 -m pyserini.search'
self.pyserini_base_cmd = 'python -m pyserini.search'

@staticmethod
def _cleanup(files: List[str]):
Expand Down
2 changes: 1 addition & 1 deletion integrations/simplesearcher_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, anserini_root: str, index: str, topics: str, pyserini_topics:

self.anserini_base_cmd = os.path.join(self.anserini_root,
'target/appassembler/bin/SearchCollection -topicreader Trec')
self.pyserini_base_cmd = 'python3 -m pyserini.search'
self.pyserini_base_cmd = 'python -m pyserini.search'

self.eval_base_cmd = 'tools/eval/trec_eval.9.0.4/trec_eval -m map -m P.30'

Expand Down
7 changes: 5 additions & 2 deletions pyserini/eval/msmarco_doc_eval.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import subprocess
import sys
import platform

from pyserini.search import get_qrels_file
from pyserini.util import download_evaluation_script

script_path = download_evaluation_script('msmarco_doc_eval')
cmd_prefix = ['python3', script_path]
cmd_prefix = ['python', script_path]
args = sys.argv
if len(args) > 1:
cmd = cmd_prefix + args[1:]
Expand All @@ -17,9 +18,11 @@
else:
cmd = cmd_prefix
print(f'Running command: {cmd}')
shell = platform.system() == "Windows"
process = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE,
shell=shell)
stdout, stderr = process.communicate()
if stderr:
print(stderr.decode("utf-8"))
Expand Down
7 changes: 5 additions & 2 deletions pyserini/eval/msmarco_passage_eval.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import subprocess
import sys
import platform

from pyserini.search import get_qrels_file
from pyserini.util import download_evaluation_script

script_path = download_evaluation_script('msmarco_passage_eval')
cmd_prefix = ['python3', script_path]
cmd_prefix = ['python', script_path]
args = sys.argv
if len(args) > 1:
cmd = cmd_prefix + args[1:]
Expand All @@ -15,9 +16,11 @@
else:
cmd = cmd_prefix
print(f'Running command: {cmd}')
shell = platform.system() == "Windows"
process = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE,
shell=shell)
stdout, stderr = process.communicate()
if stderr:
print(stderr.decode("utf-8"))
Expand Down
5 changes: 4 additions & 1 deletion pyserini/eval/trec_eval.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
import platform

from pyserini.search import get_qrels_file
from pyserini.util import download_evaluation_script
Expand All @@ -15,9 +16,11 @@
else:
cmd = cmd_prefix
print(f'Running command: {cmd}')
shell = platform.system() == "Windows"
process = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE,
shell=shell)
stdout, stderr = process.communicate()
if stderr:
print(stderr.decode("utf-8"))
Expand Down
22 changes: 11 additions & 11 deletions tests/test_tokenize_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
class TestTokenizeJson(unittest.TestCase):
def test_bert_single_file(self):
inj = 'test_bert_single_file.json'
outj='out_test_bert_single_file.json'
outj = 'out_test_bert_single_file.json'
f = open(inj, 'w')
f.write('{"id": "doc1","contents": "I have a new gpu!"}\n{"id": "doc2","contents": "I do have an old gpu!"}')
f.close()
if(os.getcwd().endswith('tests')):
os.system(f'python3 ../pyserini/tokenize_json_collection.py --input {inj} --output {outj}')
os.system(f'python ../pyserini/tokenize_json_collection.py --input {inj} --output {outj}')
else:
os.system(f'python3 pyserini/tokenize_json_collection.py --input {inj} --output {outj}')
with open(outj,'r') as ret:
os.system(f'python pyserini/tokenize_json_collection.py --input {inj} --output {outj}')
with open(outj, 'r') as ret:
for i, line in enumerate(ret):
contents = json.loads(line)['contents']
if (i == 0):
Expand All @@ -49,24 +49,24 @@ def test_bert_dir(self):
if(os.path.isdir(indir)):
rmtree(indir)
os.mkdir(indir)
f1 = open(indir+'/doc00.json','w')
f1 = open(indir+'/doc00.json', 'w')
f1.write('{"id": "doc1","contents": "I have a new gpu!"}\n{"id": "doc2","contents": "I do have an old gpu!"}')
f1.close()
f2 = open(indir+'/doc01.json','w')
f2 = open(indir+'/doc01.json', 'w')
f2.write('{"id": "doc1","contents": "A new gpu!"}\n{"id": "doc2","contents": "An old gpu!"}')
f2.close()
if (os.getcwd().endswith('tests')):
os.system(f'python3 ../pyserini/tokenize_json_collection.py --input {indir} --output {outdir}')
os.system(f'python ../pyserini/tokenize_json_collection.py --input {indir} --output {outdir}')
else:
os.system(f'python3 pyserini/tokenize_json_collection.py --input {indir} --output {outdir}')
with open(outdir+'/docs00.json','r') as ret:
os.system(f'python pyserini/tokenize_json_collection.py --input {indir} --output {outdir}')
with open(outdir+'/docs00.json', 'r') as ret:
for i, line in enumerate(ret):
contents = json.loads(line)['contents']
if (i == 0):
self.assertEqual('i have a new gp ##u !', contents)
else:
self.assertEqual('i do have an old gp ##u !', contents)
with open(outdir+'/docs01.json','r') as ret:
with open(outdir+'/docs01.json', 'r') as ret:
for i, line in enumerate(ret):
contents = json.loads(line)['contents']
if (i == 0):
Expand All @@ -78,4 +78,4 @@ def test_bert_dir(self):


if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit 2adbf1b

Please sign in to comment.