Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main(prog=None, args=None):
"""Entry point for the script "pyflakes"."""
import optparse
# Handle "Keyboard Interrupt" and "Broken pipe" gracefully
_exitOnSignal('SIGINT', '... stopped')
_exitOnSignal('SIGPIPE', 1)
parser = optparse.OptionParser(prog=prog, version=__version__)
(__, args) = parser.parse_args(args=args)
reporter = modReporter._makeDefaultReporter()
if args:
warnings = checkRecursive(args, reporter)
else:
warnings = check(sys.stdin.read(), '', reporter)
raise SystemExit(warnings > 0)
def main(prog=None, args=None):
"""Entry point for the script "pyflakes"."""
import optparse
# Handle "Keyboard Interrupt" and "Broken pipe" gracefully
_exitOnSignal('SIGINT', '... stopped')
_exitOnSignal('SIGPIPE', 1)
parser = optparse.OptionParser(prog=prog, version=__version__)
(__, args) = parser.parse_args(args=args)
reporter = modReporter._makeDefaultReporter()
if args:
warnings = checkRecursive(args, reporter)
else:
warnings = check(sys.stdin.read(), '', reporter)
raise SystemExit(warnings > 0)
def main(prog=None):
"""Entry point for the script "pyflakes"."""
import optparse
import signal
# Handle "Keyboard Interrupt" and "Broken pipe" gracefully
try:
signal.signal(signal.SIGINT, lambda sig, f: sys.exit('... stopped'))
signal.signal(signal.SIGPIPE, lambda sig, f: sys.exit(1))
except ValueError:
pass # SIGPIPE is not supported on Windows
parser = optparse.OptionParser(prog=prog, version=__version__)
(__, args) = parser.parse_args()
reporter = modReporter._makeDefaultReporter()
if args:
warnings = checkRecursive(args, reporter)
else:
warnings = check(sys.stdin.read(), '', reporter)
raise SystemExit(warnings > 0)
def flake_check(codeString, filename, reporter=None):
if reporter is None:
reporter = pyflakes.reporter._makeDefaultReporter()
# First, compile into an AST and handle syntax errors.
try:
tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
except SyntaxError:
value = sys.exc_info()[1]
msg = value.args[0]
(lineno, offset, text) = value.lineno, value.offset, value.text
if pyflakes.checker.PYPY:
if text is None:
lines = codeString.splitlines()
if len(lines) >= lineno:
text = lines[lineno - 1]
if sys.version_info >= (3, ) and isinstance(text, bytes):
try:
message = messageClass(self.filename, *args, **kwargs)
self.dublicated_funcs.append(message.to_list())
else:
if self.filename not in IGNORE_FILES:
print(messageClass(self.filename, *args, **kwargs))
ERRORS[str(messageClass)] = messageClass(self.filename, *args, **kwargs).to_list()
def reset_lists():
GLOBAL_CHECKER.undefined_names = []
GLOBAL_CHECKER.unused_imports = []
GLOBAL_CHECKER.unused_var = []
GLOBAL_CHECKER.shadowed_var = []
GLOBAL_CHECKER.dublicated_funcs = []
modReporter.Reporter.syntaxError = my_exception
GLOBAL_REPORTER = modReporter._makeDefaultReporter()
GLOBAL_REPORTER.indent_error = []
GLOBAL_REPORTER.general_error = []
GLOBAL_CHECKER = Checker
GLOBAL_CHECKER.report = my_report
pym.Message.to_list = my_to_list
def print_all_info(**kwargs):
if PRINT_LINE:
if kwargs['line_idx'] in PRINT_LINE:
for key in sorted(kwargs.keys()):
print(key, ':', kwargs[key])
print('')
reporter = ListReporter()
try:
pyflakes.api.check(source, filename='', reporter=reporter)
except (AttributeError, RecursionError, UnicodeDecodeError):
pass
return reporter.messages
class StubFile(object):
"""Stub out file for pyflakes."""
def write(self, *_):
"""Stub out."""
class ListReporter(pyflakes.reporter.Reporter):
"""Accumulate messages in messages list."""
def __init__(self):
"""Initialize.
Ignore errors from Reporter.
"""
ignore = StubFile()
pyflakes.reporter.Reporter.__init__(self, ignore, ignore)
self.messages = []
def flake(self, message):
"""Accumulate messages."""
self.messages.append(message)
@param codeString: The Python source to check.
@type codeString: C{str}
@param filename: The name of the file the source came from, used to report
errors.
@type filename: C{str}
@param reporter: A L{Reporter} instance, where errors and warnings will be
reported.
@return: The number of warnings emitted.
@rtype: C{int}
"""
if reporter is None:
reporter = modReporter._makeDefaultReporter()
# First, compile into an AST and handle syntax errors.
try:
tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
except SyntaxError:
value = sys.exc_info()[1]
msg = value.args[0]
(lineno, offset, text) = value.lineno, value.offset, value.text
# If there's an encoding problem with the file, the text is None.
if text is None:
# Avoid using msg, since for the only known case, it contains a
# bogus message that claims the encoding the file declared was
# unknown.
reporter.unexpectedError(filename, 'problem decoding source')
else:
def checkPath(filename, reporter=None):
"""
Check the given path, printing out any warnings detected.
@param reporter: A L{Reporter} instance, where errors and warnings will be
reported.
@return: the number of warnings printed
"""
if reporter is None:
reporter = modReporter._makeDefaultReporter()
try:
# in Python 2.6, compile() will choke on \r\n line endings. In later
# versions of python it's smarter, and we want binary mode to give
# compile() the best opportunity to do the right thing WRT text
# encodings.
if sys.version_info < (2, 7):
mode = 'rU'
else:
mode = 'rb'
with open(filename, mode) as f:
codestr = f.read()
if sys.version_info < (2, 7):
codestr += '\n' # Work around for Python <= 2.6
except UnicodeError:
reporter.unexpectedError(filename, 'problem decoding source')
self.dublicated_funcs.append(message.to_list())
else:
if self.filename not in IGNORE_FILES:
print(messageClass(self.filename, *args, **kwargs))
ERRORS[str(messageClass)] = messageClass(self.filename, *args, **kwargs).to_list()
def reset_lists():
GLOBAL_CHECKER.undefined_names = []
GLOBAL_CHECKER.unused_imports = []
GLOBAL_CHECKER.unused_var = []
GLOBAL_CHECKER.shadowed_var = []
GLOBAL_CHECKER.dublicated_funcs = []
modReporter.Reporter.syntaxError = my_exception
GLOBAL_REPORTER = modReporter._makeDefaultReporter()
GLOBAL_REPORTER.indent_error = []
GLOBAL_REPORTER.general_error = []
GLOBAL_CHECKER = Checker
GLOBAL_CHECKER.report = my_report
pym.Message.to_list = my_to_list
def print_all_info(**kwargs):
if PRINT_LINE:
if kwargs['line_idx'] in PRINT_LINE:
for key in sorted(kwargs.keys()):
print(key, ':', kwargs[key])
print('')
else:
print('WOHOO')
print(filename, msg, lineno, offset, text.strip())
def my_report(self, messageClass, *args, **kwargs):
message = messageClass(self.filename, *args, **kwargs)
if self.filename not in IGNORE_FILES:
self.my_error_dict.setdefault(str(messageClass), []).append(message.to_list())
def reset_lists():
GLOBAL_CHECKER.my_error_dict = {}
GLOBAL_REPORTER.indent_error = []
modReporter.Reporter.syntaxError = my_exception
GLOBAL_REPORTER = modReporter._makeDefaultReporter()
GLOBAL_CHECKER = Checker
GLOBAL_CHECKER.report = my_report
GLOBAL_CHECKER.my_error_dict = {}
pym.Message.to_list = my_to_list
USED_FOLDER_EMAN2 = ('libpyEM/qtgui', )
EMAN2_GUI_DICT = {}
def get_file_dict():
file_dict = {}
for folder_name in USED_FOLDER:
#files_dir = os.path.join(CURRENT_DIR, NO_USED, folder_name, '*.py')
#file_dict.setdefault('no_used', {})[folder_name] = sorted(glob.glob(files_dir))
files_dir = os.path.join(CURRENT_DIR, NO_UNUSED, folder_name, '*.py')