-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extend linter API to allow overriding the max line length #51
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,11 @@ | |
from __future__ import print_function | ||
|
||
import argparse | ||
from configparser import ConfigParser | ||
import difflib | ||
import filecmp | ||
import os | ||
import re | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
@@ -45,6 +47,9 @@ def main(argv=sys.argv[1:]): | |
default=config_file, | ||
dest='config_file', | ||
help='The config file') | ||
parser.add_argument( | ||
'--linelength', metavar='N', type=int, | ||
help='The maximum line length (default: specified in the config file)') | ||
parser.add_argument( | ||
'paths', | ||
nargs='*', | ||
|
@@ -72,6 +77,20 @@ def main(argv=sys.argv[1:]): | |
print("Could not config file '%s'" % args.config_file, file=sys.stderr) | ||
return 1 | ||
|
||
if args.linelength is not None: | ||
# check if different from config file | ||
config = ConfigParser() | ||
with open(args.config_file, 'r') as h: | ||
config_str = h.read() | ||
config.read_string('[DEFAULT]\n' + config_str) | ||
code_width = config['DEFAULT']['code_width'] | ||
code_width = int(re.split('[ \t#]', code_width, maxsplit=1)[0]) | ||
if args.linelength != code_width: | ||
# generate temporary config file with custom line length | ||
temp_config = tempfile.NamedTemporaryFile('w') | ||
temp_config.write(config_str + '\ncode_width=%d' % args.linelength) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appends the config parameter, but does not remove the original if it's already set. Will that work correctly in that case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in an ini-like file the last value is the one being used. |
||
args.config_file = temp_config.name | ||
|
||
if args.xunit_file: | ||
start_time = time.time() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
Fixed in #52.