From 33fb82b05c1d3bb9f2b1de8ed3a627a3e4c9f76a Mon Sep 17 00:00:00 2001 From: Andrew Baumann Date: Tue, 10 Aug 2021 16:55:12 -0700 Subject: [PATCH] added pypi packaging support and a version number scheme --- pdfannots.py | 14 +++++++++----- requirements.txt | 2 +- setup.py | 31 ++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/pdfannots.py b/pdfannots.py index 9ff9854..bf3e991 100755 --- a/pdfannots.py +++ b/pdfannots.py @@ -17,6 +17,8 @@ import pdfminer.settings import pdfminer.utils +__version__ = '0.1' + pdfminer.settings.STRICT = False SUBSTITUTIONS = { @@ -563,9 +565,11 @@ def process_file(fh, emit_progress=False): return (allannots, outlines) -def parse_args(argv): +def parse_args(): p = argparse.ArgumentParser(description=__doc__) + p.add_argument('--version', action='version', version='%(prog)s ' + __version__) + p.add_argument("input", metavar="INFILE", type=argparse.FileType("rb"), help="PDF files to process", nargs='+') @@ -591,11 +595,11 @@ def parse_args(argv): g.add_argument("-w", "--wrap", metavar="COLS", type=int, help="wrap text at this many output columns") - return p.parse_args(argv) + return p.parse_args() -def main(argv): - args = parse_args(argv) +def main(): + args = parse_args() global COLUMNS_PER_PAGE COLUMNS_PER_PAGE = args.cols @@ -615,4 +619,4 @@ def main(argv): if __name__ == "__main__": - main(sys.argv[1:]) + main() diff --git a/requirements.txt b/requirements.txt index f0769a2..65addad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ # pip requirements for pdfannots # Use as: pip3 install -r requirements.txt -pdfminer.six == 20201018 \ No newline at end of file +pdfminer.six == 20201018 diff --git a/setup.py b/setup.py index 33c10ed..5ae1a3b 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,42 @@ from setuptools import setup +import os.path +import pathlib +here = pathlib.Path(__file__).parent.resolve() + +def get_version_from_file(filename): + with open(here / filename, 'r') as fh: + for line in fh.readlines(): + if line.startswith('__version__'): + delim = '"' if '"' in line else "'" + return line.split(delim)[1] + + raise RuntimeError("Unable to find version string in " + filename) def main(): name = 'pdfannots' setup( name=name, + version=get_version_from_file(name + '.py'), + description='Tool to extract PDF annotations as markdown for reviewing', + long_description=(here/'README.md').read_text(), + long_description_content_type='text/markdown', + url='https://github.com/0xabu/pdfannots', + classifiers=[ + 'Intended Audience :: Science/Research', + 'Topic :: Text Processing', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3', + ], zip_safe=False, py_modules=[name], - install_requires=open('requirements.txt').read().splitlines(), + entry_points={ + 'console_scripts': [ + 'pdfannots=pdfannots:main', + ], + }, + python_requires='>=3', + install_requires=['pdfminer.six'], )