Pylint
Description
Adds the PyLint analyzer
Changes
none
Additions
PyLint analyzer
Test and Review
Resolves #141 (closed)
To be filled in by the reviewers
-
All of the methods are commented to expectation -
The methods are tested to satisfaction -
There are no unnecessary files present in the MR -
The continuous integration has no problems with the MR -
The MR is filled in as requested (including labels, milestones, and reviewers) -
The documentation is up-to-date -
All nullable parameters are marked as such
Merge request reports
Activity
changed milestone to %Extend python support
added 6 commits
-
d973a08d...99c3674c - 5 commits from branch
development
- 9e00e507 - Merge branch 'development' into pylint
-
d973a08d...99c3674c - 5 commits from branch
90 * Analyzes a submission or a fragment of a submission. 91 * 92 * @param thing the submission or fragment thereof to analyze 93 * @param options any options for the analysis to perform 94 * @return the analysis results 95 * @throws IOException if the job or fragment couldn't be read 96 */ 97 @Override 98 public ProjectEntity analyze(final Job thing, final Object options) throws IOException { 99 final var projectEntity = new ProjectEntity(); 100 final var analyzePath = thing.getDir().toAbsolutePath(); 101 var pylintPathString = this.pyLintPath.toAbsolutePath().toString(); 102 pylintPathString = pylintPathString.replace("\\", "/"); 103 104 // For every module 105 for (var i = 0; i < Objects.requireNonNull(analyzePath.toFile().listFiles()).length; i++) { changed this line in version 3 of the diff
117 env.put("PYTHONPATH", pylintPathString); 118 process.directory(this.pyLintPath.toFile()); 119 final var tempOutputFile = Files.createTempFile( 120 this.settings.getTemp(), "pyout", ".json" 121 ); 122 process.redirectOutput(tempOutputFile.toFile()); 123 124 // Start the new process and wait for it to finish or cancel after 2 minutes 125 final var runningProcess = process.start(); 126 127 try { 128 final var done = runningProcess.waitFor(2, TimeUnit.MINUTES); 129 if (!done) { 130 logger.warn("The Python process for PyLint timed out during execution"); 131 throw new IOException( 132 "The Python process for PyLint timed out during execution" Not an I/O exception
Edited by Luc Eversechanged this line in version 3 of the diff
- Resolved by Luc Everse
131 throw new IOException( 132 "The Python process for PyLint timed out during execution" 133 ); 134 } 135 } catch (InterruptedException e) { 136 logger.warn("The Python process from analyzer PyLint was interrupted"); 137 throw new IOException( 138 "The python process from analyzer PyLint was interrupted during execution" 139 ); 140 } 141 142 // Retrieve the JSon object from the process 143 final var pyLintResults = new HashSet<PyLintResult>(); 144 try (var reader = new InputStreamReader( 145 new FileInputStream(tempOutputFile.toFile()))) { 146 var gson = new GsonBuilder().create(); changed this line in version 3 of the diff
132 "The Python process for PyLint timed out during execution" 133 ); 134 } 135 } catch (InterruptedException e) { 136 logger.warn("The Python process from analyzer PyLint was interrupted"); 137 throw new IOException( 138 "The python process from analyzer PyLint was interrupted during execution" 139 ); 140 } 141 142 // Retrieve the JSon object from the process 143 final var pyLintResults = new HashSet<PyLintResult>(); 144 try (var reader = new InputStreamReader( 145 new FileInputStream(tempOutputFile.toFile()))) { 146 var gson = new GsonBuilder().create(); 147 var jsonReader = gson.newJsonReader(reader); changed this line in version 3 of the diff
22 import java.util.List; 23 import java.util.stream.Collectors; 24 25 import static org.assertj.core.api.Assertions.assertThat; 26 27 public class PyLintTest { 28 29 @Test 30 public void testLizard() throws IOException { 31 final var unzipper = new JobUnzipper(new WorkerSettings( 32 Ob.map("name", Arrays.asList("Otto"), "api-token", List.of("koolzuur")))); 33 final var tempDir = Paths.get(System.getProperty("java.io.tmpdir")); 34 var zipPath = Files.createTempFile(tempDir, "pyFilesForTesting", ".zip"); 35 36 try (var in = TestSmellsAnalyzer.class. 37 getResourceAsStream("/python/lizard.zip"); changed this line in version 3 of the diff
76 } 77 78 final var fragments = new ArrayList<Fragment>(); 79 final var frag = new Fragment("MA_testcase2", tempPath.toFile()); 80 fragments.add(frag); 81 82 final var job = new Job(fragments, "python", 83 new HashMap<>(), "best ID", path); 84 85 final var pyLint = new PyLint(new WorkerSettings(Ob.map( 86 "name", Arrays.asList("Otto"), 87 "api-token", List.of("TOKEN!!!")) 88 ), new JobUnzipper(new WorkerSettings(Ob.map( 89 "name", Arrays.asList("Otto"), 90 "api-token", List.of("TOKEN!!!")) 91 ))); changed this line in version 3 of the diff
- Resolved by Luc Everse
151 } 152 153 // Retrieve the JSon object from the process 154 final var pyLintResults = new HashSet<PyLintResult>(); 155 var gson = new GsonBuilder().create(); 156 try (var reader = Files.newBufferedReader(tempOutputFile); 157 var jsonReader = gson.newJsonReader(reader)) { 158 jsonReader.beginArray(); 159 while (jsonReader.hasNext()) { 160 final PyLintResult pyLintResult = gson.fromJson(jsonReader, PyLintResult.class); 161 pyLintResults.add(pyLintResult); 162 } 163 } 164 165 // Create the module entity 166 final var moduleEntity = new Entity(projectEntity, "ModuleName", changed this line in version 4 of the diff
enabled an automatic merge when the pipeline for f0d9c0c4 succeeds
mentioned in commit 96b750d2
unassigned @eoudsen