forked from coala/coala-bears
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CPDBear: Fix for crash when many files are given
Until now, the files to run on were given to CPD with the --files option, which would raise 'OSError: [Errno 7] Argument list too long'. Now, the files are saved in a temporary file, and that file is given to CPD with the --filelist option, which takes a csv file containing a list of files to run on. Fixes coala/coala#3701
- Loading branch information
Showing
1 changed file
with
12 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import os | ||
from shutil import which | ||
from xml.etree import ElementTree | ||
|
||
|
@@ -36,6 +37,7 @@ class CPDBear(GlobalBear): | |
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Duplication'} | ||
TEMP_FILELIST = '.tmp_filelist' | ||
|
||
@classmethod | ||
def check_prerequisites(cls): # pragma: no cover | ||
|
@@ -89,11 +91,15 @@ def run(self, language: str, minimum_tokens: int=20, | |
'--skip-duplicate-files': skip_duplicate_files} | ||
|
||
files = ','.join(self.file_dict.keys()) | ||
f = open(self.TEMP_FILELIST, 'w') | ||
f.write(str(files)) | ||
f.close() | ||
|
||
executable = which('pmd') or which('run.sh') | ||
arguments = ('bash', executable, 'cpd', '--skip-lexical-errors', | ||
'--minimum-tokens', str(minimum_tokens), | ||
'--language', self.lowered_lang_dict[language], | ||
'--files', files, | ||
'--filelist', self.TEMP_FILELIST, | ||
'--format', 'xml') | ||
|
||
arguments += tuple(option | ||
|
@@ -102,6 +108,11 @@ def run(self, language: str, minimum_tokens: int=20, | |
|
||
stdout_output, _ = run_shell_command(arguments) | ||
|
||
try: | ||
os.remove(self.TEMP_FILELIST) | ||
except OSError: | ||
pass | ||
|
||
if stdout_output: | ||
root = ElementTree.fromstring(stdout_output) | ||
|
||
|