Skip to content

Commit

Permalink
Merge branch 'codacy'
Browse files Browse the repository at this point in the history
* codacy:
  Dockerfile: clean apt-get
  lint: Java (codacy)
  lint: shell style (codacy): use $() command substitution style
  lint: Java style (codacy): method DiffImage --> diffImage
  lint: Java style (codacy)
  migrate-from-ppy.py: jinja2 autoescape
  migrate-from-ppy.py: use defusedxml instead of lxml
  generate-e2e-test.py: change yaml.load() --> yaml.safe_load()
  migrate-from-ppy: unused code
  • Loading branch information
jeremydouglass committed Aug 8, 2019
2 parents 121c0fc + 4b0abb3 commit e13afbe
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .docker/run-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Input:
# $1 Log string.
function log {
echo -e "[`date`] ${1}"
echo -e "[$(date)] ${1}"
}

root=$(dirname "${BASH_SOURCE}")/..
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ RUN mkdir -p /code/runner

# Install base package.
RUN apt-get update && \
apt-get install -y \
apt-get install -y --no-install-recommends \
curl \
ant

ant \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Download Processing.
# Dev operation: copy processing into the image.
# COPY processing-3.3.3-linux64.tgz /code/processing.tgz
Expand Down
6 changes: 3 additions & 3 deletions hack/generate-e2e-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Generator(object):
def __init__(self):
self.output_dir = e2e_test_dir
self.reference_dir = reference_dir

def generate(self):
for dirname in os.listdir(self.reference_dir):
item_dir = os.path.join(self.reference_dir, dirname)
Expand All @@ -35,7 +35,7 @@ def generate(self):
if os.path.isfile(yaml_file) is not True:
return
with open(yaml_file, 'r') as f:
config = yaml.load(f.read())
config = yaml.safe_load(f.read())
print(config)
builder.set_reference_url(config['test']['reference'])

Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(self, name):
def set_core_code(self, code):
self.coreCode = code
return self

def set_reference_url(self, url):
self.referenceURL = url
return self
Expand Down
6 changes: 2 additions & 4 deletions hack/migrate-from-ppy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import click
import os
import lxml
from lxml import etree
from defusedxml import ElementTree as etree
import jinja2
import copy

property_file_name = '.property.yml'
property_template_dir = 'hack/templates'
Expand Down Expand Up @@ -31,7 +29,7 @@ def migrateItem(self, filename):

def render(self, tree):
property_template = jinja2.Environment(
loader=jinja2.FileSystemLoader(
autoescape=True, loader=jinja2.FileSystemLoader(
property_template_dir), trim_blocks='true')\
.get_template(property_template_file_name)
subcategory = ''
Expand Down
4 changes: 2 additions & 2 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ numberOfParams=2
# Input:
# $1 Log string.
function log {
echo -e "[`date`] ${1}"
echo -e "[$(date)] ${1}"
}

function help {
Expand All @@ -41,7 +41,7 @@ function deploy {
commitid=$(git log -n1 --format="%h")
version=${1}
full_version=${2}
date=`date "+%Y/%m/%d %R"`
date=$(date "+%Y/%m/%d %R")

perl -i -pe "s|\@\@mode-version\@\@|${version}|g" docs/RLangMode.txt
perl -i -pe "s|\@\@pretty-version\@\@|${full_version}|g" docs/RLangMode.txt
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils/generator-util.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Input:
# $1 Log string.
function log {
echo -e "[`date`] ${1}"
echo -e "[$(date)] ${1}"
}

function help {
Expand Down
12 changes: 6 additions & 6 deletions src/rprocessing/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public boolean accept(final File dir, final String name) {
});
if (dlls != null && dlls.length > 0) {
entries.add(dir.getAbsolutePath());
} else {
// log("No DLLs in ", dir);
// } else {
// log("No DLLs in ", dir);
}

final File[] jars = dir.listFiles(new FilenameFilter() {
Expand All @@ -145,8 +145,8 @@ public boolean accept(final File dir, final String name) {
for (final File jar : jars) {
entries.add(jar.getAbsolutePath());
}
} else {
// log("No JARs in ", dir);
// } else {
// log("No JARs in ", dir);
}

final File[] dirs = dir.listFiles(new FileFilter() {
Expand All @@ -159,8 +159,8 @@ public boolean accept(final File f) {
for (final File d : dirs) {
searchForExtraStuff(d, entries);
}
} else {
// log("No dirs in ", dir);
// } else {
// log("No dirs in ", dir);
}
}
}
8 changes: 4 additions & 4 deletions src/rprocessing/TreeCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@

class TreeCopier implements FileVisitor<Path> {

private final Path source;
private final Path target;

/**
* Copy source file to target location.
*/
static void copyFile(final Path source, final Path target) {
private static void copyFile(final Path source, final Path target) {
try {
Files.copy(source, target, COPY_ATTRIBUTES, REPLACE_EXISTING);
} catch (final IOException ioException) {
System.err.format("Unable to copy: %s: %s%n", source, ioException);
}
}

private final Path source;
private final Path target;

TreeCopier(final Path source, final Path target) {
this.source = source;
this.target = target;
Expand Down
3 changes: 2 additions & 1 deletion src/rprocessing/exception/RSketchError.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public String toString() {
}

// TODO: Support the line and column.
public static RSketchError toSketchException(Throwable t) {
public static RSketchError toSketchException(Throwable terr) {
Throwable t = terr;
log(t.getClass().toString());
if (t instanceof RuntimeException && t.getCause() != null) {
t = t.getCause();
Expand Down
9 changes: 5 additions & 4 deletions src/rprocessing/mode/RLangKeywordMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,16 @@ protected int getSegmentMapKey(final Segment s, final int off, final int len) {

// private members
class Keyword {

public char[] keyword;
public byte id;
public Keyword next;

public Keyword(final char[] keyword, final byte id, final Keyword next) {
this.keyword = keyword;
this.id = id;
this.next = next;
}

public char[] keyword;
public byte id;
public Keyword next;
}

}
2 changes: 1 addition & 1 deletion src/test/e2e/core/E2eTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected String referenceImage(String path) throws MalformedURLException {
}

protected float diffImage(File file, String fileURL) throws MalformedURLException, IOException {
return ImageUtils.DiffImage(file, new URL(fileURL));
return ImageUtils.diffImage(file, new URL(fileURL));
}

protected float diffImageWithProcessingReference(File file, String referenceURL)
Expand Down
9 changes: 6 additions & 3 deletions src/test/e2e/util/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* @author github.com/gaocegege
*/
public class ImageUtils {
public static float DiffImage(File actualFile, URL testURL) throws IOException {

public static float diffImage(File actualFile, URL testURL) throws IOException {
PImage actualImage = new PImage(ImageIO.read(actualFile));
PImage testImage = new PImage(ImageIO.read(testURL));

Expand All @@ -28,11 +29,13 @@ private static float imgDifference(PImage i0, PImage i1) {
i1.loadPixels();
int[] ip1 = i1.pixels;
for (int n = 0; n < ip0.length; n++) {
int pxl0 = ip0[n], r0, g0, b0;
int pxl1 = ip1[n], r1, g1, b1;
int pxl0 = ip0[n]
int r0, g0, b0;
r0 = (pxl0 >> 20) & 0xF;
g0 = (pxl0 >> 12) & 0xF;
b0 = (pxl0 >> 4) & 0xF;
int pxl1 = ip1[n]
int r1, g1, b1;
r1 = (pxl1 >> 20) & 0xF;
g1 = (pxl1 >> 12) & 0xF;
b1 = (pxl1 >> 4) & 0xF;
Expand Down

0 comments on commit e13afbe

Please sign in to comment.