Skip to content
Go to file
Cannot retrieve contributors at this time
executable file 154 lines (140 sloc) 5.61 KB
#!/usr/bin/env python
duecredit -- publications (donations, etc) tracer
import re
import os
import sys
import re
from datetime import datetime
from setuptools import setup
from pkgutil import walk_packages
from subprocess import Popen, PIPE
from os.path import exists
# Adopted from citeproc-py
# License: BSD-2
# Copyright 2011-2013 Brecht Machiels
PACKAGE = 'duecredit'
PACKAGE_ABSPATH = os.path.abspath(PACKAGE)
# retrieve the version number from git or VERSION_FILE
# inspired by
if exists('debian/copyright'):
print('Generating out of debian/copyright information')
# building debian package. Deduce version from debian/copyright
with open('debian/changelog', 'r') as f:
lines = f.readlines()
__version__ = re.sub('(.*)-(.*?)$', r'\1.debian\2',
).replace('-', '.')
# TODO: unify format whenever really bored ;)
__release_date__ = re.sub('^ -- .*>\s*(.*)', r'\1',
list(filter(lambda x: x.startswith(' -- '), lines))[0].rstrip())
print('Attempting to get version number from git...')
git = Popen(['git', 'describe', '--abbrev=4', '--dirty'],
stdout=PIPE, stderr=sys.stderr)
if git.wait() != 0:
raise OSError
line = git.stdout.readlines()[0].strip().decode('ascii')
if line.count('-') >= 2:
# we should parse it to make version compatible with PEP440
# unfortunately we wouldn't be able to include git treeish
# into the version, and thus can have collisions. So let's
# release from master only
line = '.dev'.join(line.split('-')[:2])
__version__ = line
__release_date__ ='%b %d %Y, %H:%M:%S')
with open(VERSION_FILE, 'w') as version_file:
version_file.write("__version__ = '{0}'\n".format(__version__))
version_file.write("__release_date__ = '{0}'\n".format(__release_date__))
except OSError as e:
print('Assume we are running from a source distribution.')
# read version from VERSION_FILE
if os.path.exists(VERSION_FILE):
with open(VERSION_FILE) as version_file:
code = compile(, VERSION_FILE, 'exec')
exec(code, locals(), globals())
__version__ = ''
print("Version: %s" % __version__)
# In some environments with too basic locale settings
# it might not be able to read the file with unicode, so we
# would then just ignore the errors
with open('', 'rb') as f:
# We need to decode it reliably
README = README.decode()
except UnicodeDecodeError:
README = README.decode('ascii', errors='replace')
def find_packages(path, prefix):
yield prefix
prefix = prefix + "."
for _, name, ispkg in walk_packages(path, prefix):
if ispkg:
yield name
packages=list(find_packages([PACKAGE_ABSPATH], PACKAGE)),
install_requires=['requests', 'citeproc-py>=0.4', 'six'],
'tests': [
'vcrpy', 'contextlib2'
'console_scripts': [
author='Yaroslav Halchenko, Matteo Visconti di Oleggio Castello',
description='Publications (and donations) tracer',
duecredit is being conceived to address the problem of inadequate
citation of scientific software and methods, and limited visibility of
donation requests for open-source software.
It provides a simple framework (at the moment for Python only) to
embed publication or other references in the original code so they are
automatically collected and reported to the user at the necessary
level of reference detail, i.e. only references for actually used
functionality will be presented back if software provides multiple
citeable implementations.
To get a sense of what duecredit is about, run for example shipped along
example script, or your analysis script with `-m duecredit`, e.g.
python -m duecredit examples/
# Download URL will point to the latest release, thus suffixes removed
% re.sub('-.*$', '', __version__),
keywords=['citation tracing'],
license='2-clause BSD License',
'Development Status :: 4 - Beta',
'Environment :: Console',
'Environment :: Other Environment',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Legal Industry',
'Intended Audience :: Other Audience',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Documentation',
'Topic :: Software Development :: Documentation',
'Topic :: Software Development :: Libraries :: Python Modules',
You can’t perform that action at this time.