Skip to content

Commit

Permalink
Allow setup.py to fetch trec_eval source from Github.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Van Gysel committed Mar 21, 2018
1 parent a03919a commit 74bdcd3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 37 deletions.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
109 changes: 72 additions & 37 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,78 @@
import os
"""Sets up pytrec_eval."""

from distutils.core import setup, Extension
import os
import tempfile

TREC_EVAL_DIR = os.path.realpath(
REMOTE_TREC_EVAL_ZIP = 'https://github.com/usnistgov/' \
'trec_eval/archive/v9.0.5.zip'

REMOTE_TREC_EVAL_ZIP_DIRNAME = 'trec_eval-9.0.5'

LOCAL_TREC_EVAL_DIR = os.path.realpath(
os.path.join(__file__, '..', 'trec_eval'))

TREC_EVAL_SRC = []

for filename in os.listdir(TREC_EVAL_DIR):
if filename.endswith('.c'):
TREC_EVAL_SRC.append(os.path.join(TREC_EVAL_DIR, filename))

pytrec_eval_ext = Extension(
'pytrec_eval_ext',
sources=['src/pytrec_eval.cpp'] + TREC_EVAL_SRC,
libraries=['m', 'stdc++'],
include_dirs=[TREC_EVAL_DIR],
undef_macros=['NDEBUG'],
extra_compile_args=['-g', '-Wall', '-O3'],
define_macros=[('VERSIONID', '\"pytrec_eval\"'),
('_GLIBCXX_USE_CXX11_ABI', '0'),
('P_NEEDS_GNU_CXX_NAMESPACE', '1')])

setup(name='pytrec_eval',
version='alpha',
description='Provides Python bindings for popular Information Retrieval '
'measures implemented within trec_eval.',
author='Christophe Van Gysel',
author_email='[email protected]',
ext_modules=[pytrec_eval_ext],
packages=['pytrec_eval'],
package_dir={'pytrec_eval': 'py'},
url='https://github.com/cvangysel/pytrec_eval',
keywords=['trec_eval', 'information retrieval', 'evaluation', 'ranking'],
classifiers=[
'Development Status :: 3 - Alpha',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: C++',
'Intended Audience :: Science/Research',
'Operating System :: POSIX :: Linux',
'Topic :: Text Processing :: General',
])
with tempfile.TemporaryDirectory() as tmp_dir:
if os.path.isfile(os.path.join(LOCAL_TREC_EVAL_DIR, 'trec_eval.h')):
# Use local version.
trec_eval_dir = LOCAL_TREC_EVAL_DIR
else: # Fetch remote version.
print('Fetching trec_eval from {}.'.format(REMOTE_TREC_EVAL_ZIP))

import io
import urllib.request
import zipfile

response = urllib.request.urlopen(REMOTE_TREC_EVAL_ZIP)
mmap_f = io.BytesIO(response.read())

trec_eval_zip = zipfile.ZipFile(mmap_f)
trec_eval_zip.extractall(tmp_dir)

trec_eval_dir = os.path.join(tmp_dir, REMOTE_TREC_EVAL_ZIP_DIRNAME)

for filename in os.listdir(LOCAL_TREC_EVAL_DIR):
if filename.endswith('.c'):
TREC_EVAL_SRC.append(os.path.join(LOCAL_TREC_EVAL_DIR, filename))

pytrec_eval_ext = Extension(
'pytrec_eval_ext',
sources=['src/pytrec_eval.cpp'] + TREC_EVAL_SRC,
libraries=['m', 'stdc++'],
include_dirs=[trec_eval_dir],
undef_macros=['NDEBUG'],
extra_compile_args=['-g', '-Wall', '-O3'],
define_macros=[('VERSIONID', '\"pytrec_eval\"'),
('_GLIBCXX_USE_CXX11_ABI', '0'),
('P_NEEDS_GNU_CXX_NAMESPACE', '1')])

setup(name='pytrec_eval',
version='0.1',
description='Provides Python bindings for popular '
'Information Retrieval measures implemented '
'within trec_eval.',
author='Christophe Van Gysel',
author_email='[email protected]',
ext_modules=[pytrec_eval_ext],
packages=['pytrec_eval'],
package_dir={'pytrec_eval': 'py'},
python_requires='>=3',
url='https://github.com/cvangysel/pytrec_eval',
download_url='https://github.com/cvangysel/pytrec_eval/tarball/0.1',
keywords=[
'trec_eval',
'information retrieval',
'evaluation',
'ranking',
],
classifiers=[
'Development Status :: 3 - Alpha',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: C++',
'Intended Audience :: Science/Research',
'Operating System :: POSIX :: Linux',
'Topic :: Text Processing :: General',
])

0 comments on commit 74bdcd3

Please sign in to comment.