本文整理汇总了Python中pyflakes.scripts.pyflakes.checkPath函数的典型用法代码示例。如果您正苦于以下问题:Python checkPath函数的具体用法?Python checkPath怎么用?Python checkPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了checkPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_pyflakes_analysis
def _run_pyflakes_analysis(self, package):
package_path = os.path.dirname(package.__file__)
for dir_path, dir_names, file_names in os.walk(package_path):
for file_name in file_names:
if file_name.endswith('.py'):
file_path = os.path.join(dir_path, file_name)
checkPath(file_path)
示例2: run
def run(self, apps_locations, **options):
output = open(os.path.join(options['output_dir'], 'pyflakes.report'), 'w')
# run pyflakes tool with captured output
old_stdout, pyflakes_output = sys.stdout, StringIO()
sys.stdout = pyflakes_output
try:
for location in apps_locations:
if os.path.isdir(location):
for dirpath, dirnames, filenames in os.walk(os.path.relpath(location)):
if dirpath.endswith(tuple(
''.join([os.sep, exclude_dir]) for exclude_dir in options['pyflakes_exclude_dirs'])):
continue
for filename in filenames:
if filename.endswith('.py'):
pyflakes.checkPath(os.path.join(dirpath, filename))
else:
pyflakes.checkPath(os.path.relpath(location))
finally:
sys.stdout = old_stdout
# save report
pyflakes_output.seek(0)
while True:
line = pyflakes_output.readline()
if not line:
break
message = re.sub(r': ', r': [E] PYFLAKES:', line)
output.write(message)
output.close()
示例3: teardown_test_environment
def teardown_test_environment(self, **kwargs):
locations = get_apps_locations(self.test_labels, self.test_all)
# run pyflakes tool with captured output
old_stdout, pyflakes_output = sys.stdout, StringIO()
sys.stdout = pyflakes_output
try:
for location in locations:
if os.path.isdir(location):
for dirpath, dirnames, filenames in os.walk(relpath(location)):
for filename in filenames:
if filename.endswith('.py'):
pyflakes.checkPath(os.path.join(dirpath, filename))
else:
pyflakes.checkPath(relpath(location))
finally:
sys.stdout = old_stdout
# save report
pyflakes_output.reset()
while True:
line = pyflakes_output.readline()
if not line:
break
message = re.sub(r': ', r': [E] PYFLAKES:', line)
self.output.write(message)
self.output.close()
示例4: directory_py_files
def directory_py_files(self, parent_directory):
import pyflakes.scripts.pyflakes as pyflake
directory_generator = os.walk(parent_directory)
directory_info = directory_generator.next()
for file in directory_info[2]:
if file.endswith('py') and not file.startswith('__init__'):
pyflake.checkPath('%s/%s' % (directory_info[0], file))
for directory in directory_info[1]:
if not directory.startswith('.') and not directory.startswith('migrations'):
self.directory_py_files('%s/%s' % (parent_directory, directory))
示例5: __check_path
def __check_path(self, path):
old_stdout = sys.stdout
stream = FakeStream()
try:
sys.stdout = stream
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
if filename.endswith('.py'):
pyflakes.checkPath(os.path.join(dirpath, filename))
finally:
sys.stdout = old_stdout
stream.check()
示例6: test_pyflakes
def test_pyflakes(self):
"""Check all the code."""
stdout = StringIO()
with patch('sys.stdout', stdout):
for dirpath, _, filenames in os.walk('src'):
for filename in filenames:
if filename.endswith('.py'):
checkPath(os.path.join(dirpath, filename))
errors = [line.strip() for line in stdout.getvalue().splitlines()
if line.strip()]
if errors:
self.fail('\n'.join(errors))
示例7: _run
def _run(self, path, **kwargs):
old_stdout = sys.stdout
stream = FakeStream(**kwargs)
try:
sys.stdout = stream
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
if _compat.PY3 and filename in ("m4a.py", "test_m4a.py"):
continue
if filename.endswith('.py'):
pyflakes.checkPath(os.path.join(dirpath, filename))
finally:
sys.stdout = old_stdout
stream.check()
示例8: _run
def _run(self, path):
old_stdout = sys.stdout
stream = StringIO()
try:
sys.stdout = stream
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
if filename.endswith('.py'):
pyflakes.checkPath(os.path.join(dirpath, filename))
finally:
sys.stdout = old_stdout
lines = stream.getvalue()
if lines:
raise Exception(lines)
示例9: __check_path
def __check_path(self, path):
if not pyflakes:
raise Exception("pyflakes missing; please install")
old_stdout = sys.stdout
stream = FakeStream()
try:
sys.stdout = stream
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
if filename.endswith('.py'):
pyflakes.checkPath(os.path.join(dirpath, filename))
finally:
sys.stdout = old_stdout
stream.check()
示例10: audit
def audit():
"""Audit WxGeometrie's source with PyFlakes.
Audit WxGeometrie source code for following issues:
- Names which are used but not defined or used before they are defined.
- Names which are redefined without having been used.
"""
os.chdir(WXGEODIR)
try:
import pyflakes.scripts.pyflakes as flakes
except ImportError:
print("""In order to run the audit, you need to have PyFlakes installed.""")
sys.exit(-1)
print('\n == Auditing files... ==')
warns = 0
for dirpath, dirnames, filenames in os.walk('.'):
if not any((dirpath.startswith('./' + dir) or dir + '/' == dirpath) for dir in SKIP_DIRS):
print('\nAuditing ' + dirpath + '...')
print([('./' + dir, dirpath.startswith('./' + dir)) for dir in SKIP_DIRS])
for filename in filenames:
if filename.endswith('.py') and filename != '__init__.py':
warns += flakes.checkPath(os.path.join(dirpath, filename))
if warns > 0:
print("Audit finished with total %d warnings" % warns)
else:
print("Audit finished without any warning. :)")
示例11: check_pyflakes
def check_pyflakes(srcdir):
print(">>> Running pyflakes...")
clean = True
for pyfile in findpy(srcdir):
if pyflakes.checkPath(pyfile) != 0:
clean = False
return clean
示例12: run
def run(self):
import sys
try:
import pyflakes.scripts.pyflakes as flakes
except ImportError:
print "Audit requires PyFlakes installed in your system."
sys.exit(-1)
warns = 0
# Define top-level directories
dirs = ('.')
for dir in dirs:
for root, _, files in os.walk(dir):
if root.startswith(('./build', './doc')):
continue
for file in files:
if not file.endswith(('__init__.py', 'upload.py')) \
and file.endswith('.py'):
warns += flakes.checkPath(os.path.join(root, file))
if warns > 0:
print "Audit finished with total %d warnings." % warns
sys.exit(-1)
else:
print "No problems found in sourcecode."
sys.exit(0)
示例13: test_missingTrailingNewline
def test_missingTrailingNewline(self):
"""
Source which doesn't end with a newline shouldn't cause any
exception to be raised nor an error indicator to be returned by
L{check}.
"""
fName = fileWithContents("def foo():\n\tpass\n\t")
self.assertFalse(checkPath(fName))
示例14: test_checkPathNonExisting
def test_checkPathNonExisting(self):
"""
L{checkPath} handles non-existing files.
"""
err = StringIO()
count = withStderrTo(err, lambda: checkPath('extremo'))
self.assertEquals(err.getvalue(), 'extremo: No such file or directory\n')
self.assertEquals(count, 1)
示例15: output
def output(self):
stderr, sys.stderr = sys.stderr, StringIO.StringIO()
stdout, sys.stdout = sys.stdout, StringIO.StringIO()
try:
from pyflakes.scripts import pyflakes
pyflakes.checkPath(self.path)
errors = sys.stderr.getvalue().strip()
if errors:
return errors
else:
output = sys.stdout.getvalue().strip()
return output
finally:
sys.stderr = stderr
sys.stdout = stdout