'ArcanistPhutilXHPASTLinter' => 'lint/linter/ArcanistPhutilXHPASTLinter.php',
'ArcanistPhutilXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php',
'ArcanistPyFlakesLinter' => 'lint/linter/ArcanistPyFlakesLinter.php',
+ 'ArcanistPyFlakesLinterTestCase' => 'lint/linter/__tests__/ArcanistPyFlakesLinterTestCase.php',
'ArcanistPyLintLinter' => 'lint/linter/ArcanistPyLintLinter.php',
'ArcanistRepositoryAPI' => 'repository/api/ArcanistRepositoryAPI.php',
'ArcanistRepositoryAPIMiscTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIMiscTestCase.php',
'ArcanistPhutilTestTerminatedException' => 'Exception',
'ArcanistPhutilXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
'ArcanistPhutilXHPASTLinterTestCase' => 'ArcanistArcanistLinterTestCase',
- 'ArcanistPyFlakesLinter' => 'ArcanistLinter',
+ 'ArcanistPyFlakesLinter' => 'ArcanistExternalLinter',
+ 'ArcanistPyFlakesLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistPyLintLinter' => 'ArcanistLinter',
'ArcanistRepositoryAPIMiscTestCase' => 'ArcanistTestCase',
'ArcanistRepositoryAPIStateTestCase' => 'ArcanistTestCase',
*
* @group linter
*/
-final class ArcanistPyFlakesLinter extends ArcanistLinter {
+final class ArcanistPyFlakesLinter extends ArcanistExternalLinter {
public function getLinterName() {
- return 'PyFlakes';
+ return 'PYFLAKES';
}
- public function getPyFlakesOptions() {
- return null;
+ public function getLinterConfigurationName() {
+ return 'pyflakes';
}
- public function lintPath($path) {
+ public function getDefaultBinary() {
$config = $this->getEngine()->getConfigurationManager();
- $pyflakes_path = $config->getConfigFromAnySource('lint.pyflakes.path');
- $pyflakes_prefix = $config->getConfigFromAnySource('lint.pyflakes.prefix');
-
- // Default to just finding pyflakes in the users path
- $pyflakes_bin = 'pyflakes';
- $python_path = array();
-
- // If a pyflakes path was specified, then just use that as the
- // pyflakes binary and assume that the libraries will be imported
- // correctly.
- //
- // If no pyflakes path was specified and a pyflakes prefix was
- // specified, then use the binary from this prefix and add it to
- // the PYTHONPATH environment variable so that the libs are imported
- // correctly. This is useful when pyflakes is installed into a
- // non-default location.
- if ($pyflakes_path !== null) {
- $pyflakes_bin = $pyflakes_path;
- } else if ($pyflakes_prefix !== null) {
- $pyflakes_bin = $pyflakes_prefix.'/bin/pyflakes';
- $python_path[] = $pyflakes_prefix.'/lib/python2.7/site-packages';
- $python_path[] = $pyflakes_prefix.'/lib/python2.7/dist-packages';
- $python_path[] = $pyflakes_prefix.'/lib/python2.6/site-packages';
- $python_path[] = $pyflakes_prefix.'/lib/python2.6/dist-packages';
+ $prefix = $config->getConfigFromAnySource('lint.pyflakes.prefix');
+ $bin = $config->getConfigFromAnySource('lint.pyflakes.bin', 'pyflakes');
+
+ if ($prefix) {
+ return $prefix.'/'.$bin;
+ } else {
+ return $bin;
}
- $python_path[] = '';
- $python_path = implode(':', $python_path);
- $options = $this->getPyFlakesOptions();
-
- $f = new ExecFuture(
- '/usr/bin/env PYTHONPATH=%s$PYTHONPATH %s %C',
- $python_path,
- $pyflakes_bin,
- $options);
- $f->write($this->getData($path));
-
- try {
- list($stdout, $_) = $f->resolvex();
- } catch (CommandException $e) {
- // PyFlakes will return an exit code of 1 if warnings/errors
- // are found but print nothing to stderr in this case. Therefore,
- // if we see any output on stderr or a return code other than 1 or 0,
- // pyflakes failed.
- if ($e->getError() !== 1 || $e->getStderr() !== '') {
- throw $e;
- } else {
- $stdout = $e->getStdout();
- }
+ }
+
+ public function getVersion() {
+ list($stdout) = execx('%C --version', $this->getExecutableCommand());
+
+ $matches = array();
+ if (preg_match('/^(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
+ return $matches['version'];
+ } else {
+ return false;
}
+ }
+
+ public function getInstallInstructions() {
+ return pht('Install pyflakes with `pip install pyflakes`.');
+ }
+
+ public function shouldExpectCommandErrors() {
+ return true;
+ }
+
+ public function supportsReadDataFromStdin() {
+ return true;
+ }
+
+ protected function parseLinterOutput($path, $err, $stdout, $stderr) {
+ $lines = phutil_split_lines($stdout, false);
- $lines = explode("\n", $stdout);
$messages = array();
foreach ($lines as $line) {
$matches = null;
$message->setCode($this->getLinterName());
$message->setDescription($description);
$message->setSeverity($severity);
- $this->addLintMessage($message);
+
+ $messages[] = $message;
+ }
+
+ if ($err && !$messages) {
+ return false;
}
+
+ return $messages;
}
}