Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade CI to python3 #480

Merged
merged 4 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 23 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ jobs:
strategy:
matrix:
os: [ubuntu, macos]
boost: [1_60, 1_66]
boost: ['1_60', '1_66', '1_73']
geos: ['3.8.1', 'none']
compiler: ['g++', 'g++-8', 'clang++']
exclude:
- os: macos
boost: 1_66
boost: '1_60'
- os: macos
boost: '1_66'
- os: ubuntu
boost: '1_73'
- os: macos
compiler: 'g++-8'
include:
Expand All @@ -37,20 +41,20 @@ jobs:
run: |
mkdir -p $HOME/.local/bin
mkdir -p $HOME/.local/lib/pkgconfig
echo "::set-env name=PKG_CONFIG_PATH::$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH"
echo "::set-env name=LD_LIBRARY_PATH::$HOME/.local/lib:$LD_LIBRARY_PATH"
echo "::set-env name=PATH::$HOME/.local/bin:$PATH"
echo "PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
- name: Linux specific setup
if: matrix.os == 'ubuntu'
run: |
sudo apt-get update
sudo apt-get install libgtkmm-2.4-dev moreutils autopoint libc6-dbg
echo "::set-env name=NUM_CPUS::$((`nproc --all` * 4))"
echo "NUM_CPUS=$((`nproc --all` * 4))" >> $GITHUB_ENV
- name: Set clang as default compiler
if: matrix.compiler == 'clang++'
run: |
echo "::set-env name=CC::`which clang`"
echo "::set-env name=CXX::`which clang++`"
echo "CC=`which clang`" >> $GITHUB_ENV
echo "CXX=`which clang++`" >> $GITHUB_ENV
- name: g++-8 specific setup
if: matrix.compiler == 'g++-8'
run: |
Expand All @@ -62,20 +66,21 @@ jobs:
if: matrix.os == 'macos'
run: |
brew update
brew upgrade python@2
brew upgrade python@3
brew reinstall -s libtool
brew unlink parallel
brew install boost@1.60 gtkmm moreutils gettext librsvg autoconf automake pkg-config
brew install boost@1.73 gtkmm moreutils gettext librsvg autoconf automake pkg-config
brew upgrade wget
hash -r
ln -f -s `which glibtoolize` $HOME/.local/bin/libtoolize
ln -f -s `which glibtool` $HOME/.local/bin/libtool
hash -r
echo "::set-env name=BOOST_ROOT::/usr/local/opt/boost@1.60"
echo "::set-env name=NUM_CPUS::$((`sysctl -n hw.logicalcpu` * 4))"
echo "::set-env name=PKG_CONFIG_PATH::$PKG_CONFIG_PATH:/usr/local/opt/libffi/lib/pkgconfig"
echo "::set-env name=CPPFLAGS_gerbv::-DQUARTZ"
echo "::set-env name=PATH::/usr/local/opt/gettext/bin:$PATH"
echo "BOOST_ROOT=/usr/local/opt/boost@1.73" >> $GITHUB_ENV
echo "NUM_CPUS=$((`sysctl -n hw.logicalcpu` * 4))" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opt/libffi/lib/pkgconfig" >> $GITHUB_ENV
echo "CPPFLAGS_gerbv=-DQUARTZ" >> $GITHUB_ENV
echo "PATH=/usr/local/opt/gettext/bin:$PATH" >> $GITHUB_ENV
rm /usr/local/include/boost
- name: Macos geos
if: matrix.geos != 'none' && matrix.os == 'macos'
run:
Expand Down Expand Up @@ -106,7 +111,7 @@ jobs:
popd
popd
fi
echo "::set-env name=BOOST_ROOT::$(echo ${HOME}/.local)"
echo "BOOST_ROOT=$(echo ${HOME}/.local)" >> $GITHUB_ENV
- name: Build and install geos
if: matrix.os == 'ubuntu' && matrix.geos != 'none'
env:
Expand Down Expand Up @@ -242,7 +247,8 @@ jobs:
- name: Run integration tests
if: matrix.boost == '1_66' && matrix.geos == '3.8.1'
run: |
pip install --user wheel colour_runner unittest2 termcolor concurrencytest in_place
sudo apt-get install python3-setuptools
pip3 install --user wheel colour_runner unittest2 termcolor concurrencytest in_place
./integration_tests.py -j ${NUM_CPUS}
- name: Gather coverage
if: matrix.code_coverage
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ACLOCAL_AMFLAGS = -I m4
GIT_VERSION = `git describe --dirty --always --tags`
GERBV_VERSION = `pkg-config --modversion libgerbv`

AM_CPPFLAGS = $(BOOST_CPPFLAGS_SYSTEM) $(glibmm_CFLAGS) $(gdkmm_CFLAGS_SYSTEM) $(gerbv_CFLAGS) $(CODE_COVERAGE_CPPFLAGS) -DGIT_VERSION=\"$(GIT_VERSION)\" -Wall -Wpedantic -Wextra $(pcb2gcode_CPPFLAGS_EXTRA) $(GEOS_CFLAGS) $(GEOS_EXTRA)
AM_CPPFLAGS = $(BOOST_CPPFLAGS_SYSTEM) $(glibmm_CFLAGS) $(gdkmm_CFLAGS_SYSTEM) $(gerbv_CFLAGS_SYSTEM) $(CODE_COVERAGE_CPPFLAGS) -DGIT_VERSION=\"$(GIT_VERSION)\" -Wall -Wpedantic -Wextra $(pcb2gcode_CPPFLAGS_EXTRA) $(GEOS_CFLAGS) $(GEOS_EXTRA)
AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS) -DGIT_VERSION=\"$(GIT_VERSION)\" -DGERBV_VERSION=\"$(GERBV_VERSION)\"
AM_LDFLAGS = $(BOOST_PROGRAM_OPTIONS_LDFLAGS)
LIBS = $(gerbv_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) $(CODE_COVERAGE_LIBS) $(GEOS_LIBS)
Expand Down
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ AC_ARG_VAR([pcb2gcode_CPPFLAGS_EXTRA], [Additional flags when compiling pcb2gcod
CFLAGS+=" ${gerbv_CFLAGS}"
AX_C_COMPILE_VALUE(GERBV_INTERPOLATION_LINEARx10,NEW_LINEARX10,[#include "gerbv.h"])

# Ignore GTK 2.0 warnings for linux and macos.
AC_SUBST([gerbv_CFLAGS_SYSTEM1], ['$(subst -I/usr/include/gtk-2.0,-isystem /usr/include/gtk-2.0,$(gerbv_CFLAGS))'])
AC_SUBST([gerbv_CFLAGS_SYSTEM], ['$(subst -I/usr/local/Cellar/gtk+/2.24.32_3/include/gtk-2.0,-isystem /usr/local/Cellar/gtk+/2.24.32_3/include/gtk-2.0,$(gerbv_CFLAGS_SYSTEM1))'])

# Checks for header files.
AC_HEADER_STDC

Expand Down
93 changes: 52 additions & 41 deletions integration_tests.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#!/usr/bin/python
#!/usr/bin/python3

"""Run integration tests on pcb2gcode."""

from __future__ import print_function
import unittest2
import subprocess
import os
import tempfile
import shutil
import argparse
import collections
import difflib
import filecmp
import sys
import argparse
import multiprocessing
import os
import re
import collections
import termcolor
import shutil
import subprocess
import sys
import tempfile
import xml.etree.ElementTree

import colour_runner.runner
import in_place
import xml.etree.ElementTree
import multiprocessing
import termcolor
import unittest2

from concurrencytest import ConcurrentTestSuite, fork_for_tests

Expand Down Expand Up @@ -139,12 +142,13 @@
)

def colored(text, **color):
"""Colorize text if supported."""
if hasattr(sys.stderr, "isatty") and sys.stderr.isatty():
return termcolor.colored(text, **color)
else:
return text
return text

class IntegrationTests(unittest2.TestCase):
"""Run integration tests."""
def rotate_pathstring(self, pathstring):
"""Parse a string representing an SVG path.

Expand All @@ -161,8 +165,11 @@ def string_to_paths(pathstring):
(M) and the rest are absolute lineTo (L) until the next moveTo (M).
"""
pathstring = pathstring[2:-3] # Remove the first M and the final z
paths = [[tuple(point.split(",")) for point in p.strip().split(" L ")] for p in pathstring.split("M ")]
# Now paths is a list. Each element is an array of points. Each point is a pair of strings, x,y.
paths = [[tuple(point.split(","))
for point in pathstring_text.strip().split(" L ")]
for pathstring_text in pathstring.split("M ")]
# Now paths is a list. Each element is an array of points.
# Each point is a pair of strings, x,y.
return paths

def rotate_path(path):
Expand All @@ -178,7 +185,8 @@ def rotate_path(path):

def paths_to_string(paths):
"""Return the path string that represents these paths."""
return "M " + "M ".join(" L ".join(','.join(point) for point in path) for path in paths) + " z "
return "M " + "M ".join(" L ".join(','.join(point) for point in path)
for path in paths) + " z "
self.assertEqual(pathstring, paths_to_string(string_to_paths(pathstring)))
return paths_to_string(rotate_path(p) for p in string_to_paths(pathstring))

Expand All @@ -199,26 +207,26 @@ def bigger(matchobj):
while width < 1000 or height < 1000:
width *= 10
height *= 10
return 'width="' + str(width) + '" height="' + str(height) + '" '
for root, subdirs, files in os.walk(path):
return 'width="{:.12g}" height="{:.12g}" '.format(width, height)
for root, _, files in os.walk(path):
for current_file in files:
with in_place.InPlace(os.path.join(root, current_file)) as f:
for line in f:
with in_place.InPlace(os.path.join(root, current_file)) as svg_file:
for line in svg_file:
if line.startswith("<svg"):
f.write("<!-- original:\n" +
line +
"-->\n" +
re.sub('width="(?P<width>[^"]*)" height="(?P<height>[^"]*)" ',
bigger,
line))
svg_file.write("<!-- original:\n" +
line +
"-->\n" +
re.sub('width="(?P<width>[^"]*)" height="(?P<height>[^"]*)" ',
bigger,
line))
elif line.startswith('<g fill-rule="evenodd"><path d="M '):
etree = xml.etree.ElementTree.fromstring(line)
pathstring = etree[0].attrib['d']
f.write(line.replace(pathstring, self.rotate_pathstring(pathstring)))
svg_file.write(line.replace(pathstring, self.rotate_pathstring(pathstring)))
else:
f.write(line)
svg_file.write(line)

def pcb2gcode_one_directory(self, input_path, cwd, args=[], exit_code=0):
def pcb2gcode_one_directory(self, input_path, cwd, args=None, exit_code=0):
"""Run pcb2gcode once in one directory.

Current working directory remains unchanged at the end.
Expand All @@ -230,11 +238,11 @@ def pcb2gcode_one_directory(self, input_path, cwd, args=[], exit_code=0):
actual_output_path = tempfile.mkdtemp()
os.chdir(input_path)
try:
cmd = [pcb2gcode, "--output-dir", actual_output_path] + args
cmd = [pcb2gcode, "--output-dir", actual_output_path] + (args or [])
print("Running {}".format(" ".join("'{}'".format(x) for x in cmd)))
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = p.communicate()
self.assertEqual(p.returncode, exit_code)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = proc.communicate()
self.assertEqual(proc.returncode, exit_code)
self.fix_up_expected(actual_output_path)
finally:
print(result[0], file=sys.stderr)
Expand Down Expand Up @@ -326,6 +334,9 @@ def do_test_one(self, test_case, cwd):
diff_text = self.run_one_directory(input_path, cwd, expected_output_path, test_prefix, test_case.args, test_case.exit_code)
self.assertFalse(bool(diff_text), 'Files don\'t match\n' + diff_text)

def cmp(x,y):
return (x>y) - (x<y)

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Integration test of pcb2gcode.')
parser.add_argument('--fix', action='store_true', dest='fix',
Expand Down Expand Up @@ -356,19 +367,19 @@ def test_method(self):
output = None
try:
subprocess.check_output(sys.argv + ['--no-fix'], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError, e:
output = str(e.output)
except subprocess.CalledProcessError as e:
output = e.output
if not output:
print("No diffs, nothing to do.")
exit(0)
p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
result = p.communicate(input=output)
files_patched = []
for l in result[0].split('\n'):
if l.startswith("patching file '"):
files_patched.append(l[len("patching file '"):-1])
elif l.startswith("patching file "):
files_patched.append(l[len("patching file "):])
for l in result[0].split(b'\n'):
if l.startswith(b"patching file '"):
files_patched.append(str(l[len("patching file '"):-1]))
elif l.startswith(b"patching file "):
files_patched.append(str(l[len("patching file "):]))
print(result[0])
if args.add:
subprocess.call(["git", "add"] + files_patched)
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.