Commit 33a69a5f authored by Jonathan L. Verner's avatar Jonathan L. Verner
Browse files

Create a Python package installable via pip.

parent 6b1e9ba9
build*
dist*
makebib.egg-info*
*.kdev4*
*pyc
# Include the license file
include LICENSE.txt
include README.md
......@@ -7,6 +7,7 @@ database so that only items actually cited appear.
import os
import sys
import argparse
from pybtex.__main__ import main as run_bibtex
from pybtex import auxfile
......@@ -18,44 +19,48 @@ DEFAULT_CFG = {
CFG_FILES = ['/etc/makebib', '~/.makebib', './.makebib']
HELP = """
A simple script to generate a local bib file from a central database.
def construct_argparser():
parser = argparse.ArgumentParser(
description='A simple script to generate a local bib file from a central database.',
epilog="""
CONFIGURATION
Usage: """+sys.argv[0]+""" arg
The program reads its configuration from """+', '.join(CFG_FILES)+""".
Each configuration option is given on a single line in the form of
arg is
key = val
either the basename of a texfile, in which case
the script creates a bib file and populates it with items
which are cited by the document and can be found in the
central database. Then it runs (a python version) of bibtex
on the texfile.
Spaces around '=' are ignored as is everything following the first '#'.
Lines not containing '=' are also ignored. The options are case-insensitive.
Currently the following options (and their default values) are available:
or --list which is followed by one of cited, missing, all, cfg
and a texfile in which case the program prints out a list of
"""+'\n'.join([" " + k + " = " + v for k, v in DEFAULT_CFG.items()])
)
parser.add_argument('--db', help='Path to the central bib dbase')
parser.add_argument('--config', help='Path to the configuration file')
cited citekeys which are cited in the texfile
command_parsers = parser.add_subparsers(dest='action')
missing citekeys which are cited in the texfile but not present
in the central database
compile_parser = command_parsers.add_parser('compile', help='Create a local bib file for the given TeX-file and run BibTeX')
compile_parser.add_argument('document', help='base filename of the TeX source')
compile_parser.add_argument('--nobibtex', help='do not run bibtex', action='store_true', default=False)
all all citekeys in the central database
show_parser = command_parsers.add_parser('show', help='Show various information')
showcommand_parsers = show_parser.add_subparsers(help='Information types', dest='info_type')
cited_parser = showcommand_parsers.add_parser('cited', help='Show all the keys cited by the specified TeX document')
cited_parser.add_argument('document', help='base filename of the TeX source')
cfg configuration
missing_parser = showcommand_parsers.add_parser('missing', help='Show all the keys cited by the specified TeX document & missing from the central dbase')
missing_parser.add_argument('document', help='base filename of the TeX source')
all_parser = showcommand_parsers.add_parser('all', help='Show all the cite keys in the central dbase')
CONFIGURATION
entry_parser = showcommand_parsers.add_parser('bibentry', help='Show the database entry with the given key')
entry_parser.add_argument('key', help='The citekey of the entry to show')
The program reads its configuration from """+', '.join(CFG_FILES)+""".
Each configuration option is given on a single line in the form of
cfg_parser = showcommand_parsers.add_parser('cfg', help='Show configuration')
key = val
Spaces around '=' are ignored as is everything following the first '#'.
Lines not containing '=' are also ignored. The options are case-insensitive.
Currently the following options (and their default values) are available:
"""+'\n'.join([" " + k + " = " + v for k, v in DEFAULT_CFG.items()])
return parser
def make_bib(basename, bib_dbase):
......@@ -82,11 +87,13 @@ def list_missing_keys(basename, bib_dbase):
print('\n'.join(missing))
def load_cfg():
def load_cfg(cfg_file=None):
global CFG_FILES, DEFAULT_CFG
cfg = {}
for k, v in DEFAULT_CFG.items():
cfg[k] = v
if cfg_file is not None:
CFG_FILES.append(cfg_file)
for f in CFG_FILES:
f = os.path.expanduser(f)
if os.path.exists(f):
......@@ -105,24 +112,36 @@ def load_cfg():
pass
return cfg
if __name__ == '__main__':
CFG = load_cfg()
if len(sys.argv) < 2:
print(sys.argv[0]+": Needs at least one argument")
sys.exit(1)
if sys.argv[1] == '--list':
if sys.argv[2] == 'cited':
list_cited_keys(sys.argv[3])
elif sys.argv[2] == 'missing':
list_missing_keys(sys.argv[3], CFG['db'])
elif sys.argv[2] == 'all':
def main():
args = construct_argparser().parse_args()
CFG = load_cfg(args.config)
if args.db:
CFG['db'] = args.db
if args.action == 'compile':
make_bib(args.document, CFG['db'])
if not args.nobibtex:
run_bibtex()
elif args.action == 'show':
if args.info_type == 'cited':
list_cited_keys(args.document)
elif args.info_type == 'missing':
list_missing_keys(args.document, CFG['db'])
elif args.info_type == 'all':
list_db_keys(CFG['db'])
elif sys.argv[2] == 'cfg':
elif args.info_type == 'bibentry':
show_bibentry(args.key, CFG['db'])
elif args.info_type == 'cfg':
for k, v in CFG.items():
print(k, '=', v)
elif sys.argv[1] == '--help':
print(HELP)
else:
make_bib(sys.argv[1], CFG['db'])
print("No command specified, defaulting to compile")
make_bib(args.action, CFG['db'])
run_bibtex()
[bdist_wheel]
# This flag says that the code is written to work on both Python 2 and Python
# 3. If at all possible, it is good practice to do this. If you cannot, you
# will need to generate wheels for each Python version that you support.
universal=1
"""A setuptools based setup module.
See:
https://packaging.python.org/en/latest/distributing.html
https://github.com/pypa/sampleproject
"""
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
from os import path
here = path.abspath(path.dirname(__file__))
try:
import pypandoc
long_description = pypandoc.convert('README.md', 'rst')
long_description = long_description.replace("\r", "") # YOU NEED THIS LINE
except (ImportError, OSError):
print("Pandoc not found. Long_description conversion failure.")
import io
# pandoc is not installed, fallback to using raw contents
with open(path.join(here, 'README.md'), encoding="utf-8") as f:
long_description = f.read()
setup(
name='makebib',
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.1.0',
description='A simple script to generate a local bib file from a central database',
long_description=long_description,
# The project's main homepage.
url='https://gitlab.com/Verner/makebib',
# Author details
author='Jonathan L. Verner',
author_email='jonathan@temno.eu',
# Choose your license
license='MIT',
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 3 - Alpha',
# Indicate who your project is intended for
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Text Processing :: Markup :: LaTeX',
# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: MIT License',
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
# What does your project relate to?
keywords='bibtex latex',
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
packages=find_packages(),
# List run-time dependencies here. These will be installed by pip when
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=['pybtex'],
# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
entry_points={
'console_scripts': [
'makebib=makebib:main',
],
},
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment