]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Run PEP8 linter on background
authorvrana <jakubv@fb.com>
Fri, 15 Feb 2013 00:16:08 +0000 (16:16 -0800)
committervrana <jakubv@fb.com>
Tue, 19 Feb 2013 20:56:57 +0000 (12:56 -0800)
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

src/__phutil_library_map__.php
src/lint/linter/ArcanistFutureLinter.php [new file with mode: 0644]
src/lint/linter/ArcanistPEP8Linter.php

index 0495dc65ba2a961490ff584ceb510a2582e5aefa..f59aea5c6e3024b19d35fda1fa405ad5fbfa2490 100644 (file)
@@ -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 (file)
index 0000000..05a33f3
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+abstract class ArcanistFutureLinter extends ArcanistLinter {
+
+  private $futures;
+
+  abstract function buildFutures(array $paths);
+  abstract function resolveFuture($path, Future $future);
+
+  public function willLintPaths(array $paths) {
+    $this->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);
+      }
+    }
+  }
+
+}
index 3e4a51a04f7d393424a914f9b6a73d7a39fc1277..0a349d8a399ef94142e4b28c8c49d8b44d62356c 100644 (file)
@@ -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);
     }
   }