Skip to content
Snippets Groups Projects

Pylint

Merged
Erik Oudsenrequested to merge
pylint into development
7 open threads

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

Edited by Ewoud Ruighaver

Merge request reports

Pipeline #170975 passed

Pipeline passed for f0d9c0c4 on pylint

Approval is optional

Merged by Ewoud RuighaverEwoud Ruighaver May 23, 2019 (May 23, 2019 11:42am UTC)

Merge details

  • Changes merged into development with 96b750d2.
  • Deleted the source branch.
  • Auto-merge enabled

Pipeline #170988 passed

Pipeline passed for 96b750d2 on development

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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++) {
  • 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"
  • 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();
  • 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);
  • 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");
  • 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 )));
  • Luc Everse
  • Erik Oudsen added 1 commit

    added 1 commit

    Compare with previous version

  • 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",
  • Erik Oudsen added 1 commit

    added 1 commit

    Compare with previous version

  • Luc Everse approved this merge request

    approved this merge request

  • Ewoud Ruighaver approved this merge request

    approved this merge request

  • Ewoud Ruighaver enabled an automatic merge when the pipeline for f0d9c0c4 succeeds

    enabled an automatic merge when the pipeline for f0d9c0c4 succeeds

  • Ewoud Ruighaver marked the checklist item All of the methods are commented to expectation as completed

    marked the checklist item All of the methods are commented to expectation as completed

  • Ewoud Ruighaver marked the checklist item There are no unnecessary files present in the MR as completed

    marked the checklist item There are no unnecessary files present in the MR as completed

  • Ewoud Ruighaver marked the checklist item The continuous integration has no problems with the MR as completed

    marked the checklist item The continuous integration has no problems with the MR as completed

  • Ewoud Ruighaver marked the checklist item The MR is filled in as requested (including labels, milestones, and reviewers) as completed

    marked the checklist item The MR is filled in as requested (including labels, milestones, and reviewers) as completed

  • Ewoud Ruighaver marked the checklist item All nullable parameters are marked as such as completed

    marked the checklist item All nullable parameters are marked as such as completed

  • Ewoud Ruighaver marked the checklist item The methods are tested to satisfaction as completed

    marked the checklist item The methods are tested to satisfaction as completed

  • mentioned in commit 96b750d2

  • unassigned @eoudsen

  • Please register or sign in to reply
    Loading