-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add updated version of the main wrapper function using
argparse
- Loading branch information
Showing
3 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from PythonTidy import VERSION | ||
|
||
version = VERSION | ||
summary = 'Cleans up, regularizes, and reformats the text of Python scripts.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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='[email protected]', | ||
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'], | ||
}, | ||
) |