From: vrana Date: Fri, 15 Feb 2013 00:16:08 +0000 (-0800) Subject: Run PEP8 linter on background X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=81171ca39da27b5c955289987ce8fe1a7350378b;p=arcanist.git Run PEP8 linter on background Test Plan: $ arc lint pep8.py --cache 0 --engine ComprehensiveLintEngine --trace Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4967 --- diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0495dc65..f59aea5c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -61,6 +61,7 @@ phutil_register_library_map(array( 'ArcanistFlagWorkflow' => 'workflow/ArcanistFlagWorkflow.php', 'ArcanistFlake8Linter' => 'lint/linter/ArcanistFlake8Linter.php', 'ArcanistFlake8LinterTestCase' => 'lint/linter/__tests__/ArcanistFlake8LinterTestCase.php', + 'ArcanistFutureLinter' => 'lint/linter/ArcanistFutureLinter.php', 'ArcanistGeneratedLinter' => 'lint/linter/ArcanistGeneratedLinter.php', 'ArcanistGetConfigWorkflow' => 'workflow/ArcanistGetConfigWorkflow.php', 'ArcanistGitAPI' => 'repository/api/ArcanistGitAPI.php', @@ -206,6 +207,7 @@ phutil_register_library_map(array( 'ArcanistFlagWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistFlake8Linter' => 'ArcanistLinter', 'ArcanistFlake8LinterTestCase' => 'ArcanistArcanistLinterTestCase', + 'ArcanistFutureLinter' => 'ArcanistLinter', 'ArcanistGeneratedLinter' => 'ArcanistLinter', 'ArcanistGetConfigWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistGitAPI' => 'ArcanistRepositoryAPI', @@ -233,7 +235,7 @@ phutil_register_library_map(array( 'ArcanistNoEngineException' => 'ArcanistUsageException', 'ArcanistNoLintLinter' => 'ArcanistLinter', 'ArcanistNoLintTestCaseMisnamed' => 'ArcanistLinterTestCase', - 'ArcanistPEP8Linter' => 'ArcanistLinter', + 'ArcanistPEP8Linter' => 'ArcanistFutureLinter', 'ArcanistPasteWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistPatchWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistPhpcsLinter' => 'ArcanistLinter', diff --git a/src/lint/linter/ArcanistFutureLinter.php b/src/lint/linter/ArcanistFutureLinter.php new file mode 100644 index 00000000..05a33f38 --- /dev/null +++ b/src/lint/linter/ArcanistFutureLinter.php @@ -0,0 +1,31 @@ +futures = $this->buildFutures($paths); + if (is_array($this->futures)) { + foreach ($this->futures as $future) { + $future->isReady(); + } + $this->futures = Futures($this->futures); + } + } + + public function lintPath($path) { + } + + public function didRunLinters() { + if ($this->futures) { + foreach ($this->futures as $path => $future) { + $this->resolveFuture($path, $future); + } + } + } + +} diff --git a/src/lint/linter/ArcanistPEP8Linter.php b/src/lint/linter/ArcanistPEP8Linter.php index 3e4a51a0..0a349d8a 100644 --- a/src/lint/linter/ArcanistPEP8Linter.php +++ b/src/lint/linter/ArcanistPEP8Linter.php @@ -5,11 +5,7 @@ * * @group linter */ -final class ArcanistPEP8Linter extends ArcanistLinter { - - public function willLintPaths(array $paths) { - return; - } +final class ArcanistPEP8Linter extends ArcanistFutureLinter { public function getLinterName() { return 'PEP8'; @@ -81,9 +77,8 @@ final class ArcanistPEP8Linter extends ArcanistLinter { return $bin; } - public function lintPath($path) { + public function buildFutures(array $paths) { $severity = ArcanistLintSeverity::SEVERITY_WARNING; - if (!$this->getEngine()->isSeverityEnabled($severity)) { return; } @@ -91,12 +86,23 @@ final class ArcanistPEP8Linter extends ArcanistLinter { $pep8_bin = $this->getPEP8Path(); $options = $this->getPEP8Options(); - list($rc, $stdout) = exec_manual( - "%C %C %s", - $pep8_bin, - $options, - $this->getEngine()->getFilePathOnDisk($path)); + $futures = Futures(array())->limit(8); + + foreach ($paths as $path) { + $future = new ExecFuture( + "%C %C %s", + $pep8_bin, + $options, + $this->getEngine()->getFilePathOnDisk($path)); + + $futures->addFuture($future, $path); + } + + return $futures; + } + public function resolveFuture($path, Future $future) { + list($rc, $stdout) = $future->resolve(); $lines = explode("\n", $stdout); $messages = array(); foreach ($lines as $line) { @@ -117,7 +123,7 @@ final class ArcanistPEP8Linter extends ArcanistLinter { $message->setCode($matches[4]); $message->setName('PEP8 '.$matches[4]); $message->setDescription($matches[5]); - $message->setSeverity($severity); + $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING); $this->addLintMessage($message); } }