Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add updated version of the main wrapper function using `argparse`

  • Loading branch information...
commit 697bbcff5293aba123c4922c1cce66e691ba9943 1 parent 4574012
@witsch authored
Showing with 51 additions and 7 deletions.
  1. +4 −0 config.py
  2. +35 −0 runner.py
  3. +12 −7 setup.py
View
4 config.py
@@ -0,0 +1,4 @@
+from PythonTidy import VERSION
+
+version = VERSION
+summary = 'Cleans up, regularizes, and reformats the text of Python scripts.'
View
35 runner.py
@@ -0,0 +1,35 @@
+from argparse import ArgumentParser, FileType
+from sys import stdin, stdout, exit
+from config import version, summary
+from PythonTidy import tidy_up
+from PythonTidyWrapper import Config
+
+
+parser = ArgumentParser(description=summary)
+parser.add_argument('input', nargs='?', type=FileType('r'), default=stdin,
+ help='specify input file instead of `stdin`')
+parser.add_argument('output', nargs='?', type=FileType('w'), default=stdout,
+ help='specify output file instead of `stdout`')
+parser.add_argument('-v', '--version', action='version',
+ version='%%(prog)s %s' % version)
+parser.add_argument('-d', '--dump', action='store_true',
+ help='dump default configuration parameters')
+parser.add_argument('-c', '--config', default=None,
+ help='read configuration parameters from file')
+
+
+def main():
+ args = parser.parse_args()
+ if args.dump:
+ config = Config()
+ config.from_pythontidy_namespace()
+ config.write(file=stdout)
+ exit()
+ if args.config:
+ config = Config(file=args.config)
+ config.to_pythontidy_namespace()
+ tidy_up(args.input, args.output)
+
+
+if __name__ == "__main__":
+ main()
View
19 setup.py
@@ -1,7 +1,14 @@
from setuptools import setup
-from PythonTidy import VERSION as version
+from config import version, summary
+
+
+install_requires = ['setuptools']
+try:
+ import argparse
+ argparse # make pyflakes happy
+except ImportError:
+ install_requires.append('argparse')
-summary = 'Cleans up, regularizes, and reformats the text of Python scripts.'
setup(name='PythonTidy',
version=version,
@@ -21,12 +28,10 @@
author_email='CRhode@LacusVeris.com',
url='http://pypi.python.org/pypi/PythonTidy',
license='GPL version 2',
- py_modules=['PythonTidy'],
+ py_modules=['PythonTidy', 'PythonTidyWrapper', 'config', 'runner'],
platforms='Any',
- install_requires=[
- 'setuptools',
- ],
+ install_requires=install_requires,
entry_points={
- 'console_scripts': ['pythontidy = PythonTidy:main'],
+ 'console_scripts': ['pythontidy = runner:main'],
},
)
Please sign in to comment.
Something went wrong with that request. Please try again.