diff options
author | Paul Vinciguerra <pvinci@vinciconsulting.com> | 2019-02-01 19:37:45 -0800 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2019-02-02 07:33:35 +0000 |
commit | 7e0c48e3a941ce874361b442a02624e586db810b (patch) | |
tree | 263dee49f92dacc27b1960a5ac2a185164d86901 | |
parent | 652d2e139443cea073da9b7bef8ee21e41a14111 (diff) |
Python3: Move vppapigen to python3.
Change-Id: I26846d0c12211a29ccfca7c269b9094f6fdbd95c
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
-rw-r--r-- | Makefile | 14 | ||||
-rwxr-xr-x | src/tools/vppapigen/test_vppapigen.py | 5 | ||||
-rwxr-xr-x | src/tools/vppapigen/vppapigen.py | 19 |
3 files changed, 22 insertions, 16 deletions
@@ -65,7 +65,7 @@ DEB_DEPENDS += debhelper dkms git libtool libapr1-dev dh-systemd DEB_DEPENDS += libconfuse-dev git-review exuberant-ctags cscope pkg-config DEB_DEPENDS += lcov chrpath autoconf indent clang-format libnuma-dev DEB_DEPENDS += python-all python-dev python-virtualenv python-pip libffi6 check -DEB_DEPENDS += libboost-all-dev libffi-dev python-ply libmbedtls-dev +DEB_DEPENDS += libboost-all-dev libffi-dev python3-ply libmbedtls-dev DEB_DEPENDS += cmake ninja-build uuid-dev ifeq ($(OS_VERSION_ID),14.04) DEB_DEPENDS += openjdk-8-jdk-headless @@ -95,7 +95,7 @@ ifeq ($(OS_ID),fedora) RPM_DEPENDS += dnf-utils RPM_DEPENDS += subunit subunit-devel RPM_DEPENDS += compat-openssl10-devel - RPM_DEPENDS += python2-devel python2-ply + RPM_DEPENDS += python2-devel python34-ply RPM_DEPENDS += python2-virtualenv RPM_DEPENDS += mbedtls-devel RPM_DEPENDS += cmake @@ -103,7 +103,7 @@ ifeq ($(OS_ID),fedora) else RPM_DEPENDS += yum-utils RPM_DEPENDS += openssl-devel - RPM_DEPENDS += python-devel python-ply + RPM_DEPENDS += python-devel python34-ply RPM_DEPENDS += python-virtualenv RPM_DEPENDS += devtoolset-7 RPM_DEPENDS += cmake3 @@ -117,7 +117,7 @@ RPM_DEPENDS += chrpath libffi-devel rpm-build SUSE_NAME= $(shell grep '^NAME=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g' | cut -d' ' -f2) SUSE_ID= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g' | cut -d' ' -f2) RPM_SUSE_BUILDTOOLS_DEPS = autoconf automake ccache check-devel chrpath -RPM_SUSE_BUILDTOOLS_DEPS += clang cmake indent libtool make ninja python-ply +RPM_SUSE_BUILDTOOLS_DEPS += clang cmake indent libtool make ninja python3-ply RPM_SUSE_DEVEL_DEPS = glibc-devel-static java-1_8_0-openjdk-devel libnuma-devel RPM_SUSE_DEVEL_DEPS += libopenssl-devel openssl-devel mbedtls-devel libuuid-devel @@ -130,11 +130,11 @@ RPM_SUSE_PLATFORM_DEPS = distribution-release shadow rpm-build ifeq ($(OS_ID),opensuse) ifeq ($(SUSE_NAME),Tumbleweed) RPM_SUSE_DEVEL_DEPS = libboost_headers1_68_0-devel-1.68.0 libboost_thread1_68_0-devel-1.68.0 gcc - RPM_SUSE_PYTHON_DEPS += python2-ply python2-virtualenv + RPM_SUSE_PYTHON_DEPS += python3-ply python2-virtualenv endif ifeq ($(SUSE_ID),15.0) RPM_SUSE_DEVEL_DEPS = libboost_headers1_68_0-devel-1.68.0 libboost_thread1_68_0-devel-1.68.0 gcc6 - RPM_SUSE_PYTHON_DEPS += python2-ply python2-virtualenv + RPM_SUSE_PYTHON_DEPS += python3-ply python2-virtualenv else RPM_SUSE_DEVEL_DEPS += libboost_headers1_68_0-devel-1.68.0 gcc6 RPM_SUSE_PYTHON_DEPS += python-virtualenv @@ -144,7 +144,7 @@ endif ifeq ($(OS_ID),opensuse-leap) ifeq ($(SUSE_ID),15.0) RPM_SUSE_DEVEL_DEPS = libboost_headers-devel libboost_thread-devel gcc6 - RPM_SUSE_PYTHON_DEPS += python2-ply python2-virtualenv + RPM_SUSE_PYTHON_DEPS += python3-ply python2-virtualenv endif endif diff --git a/src/tools/vppapigen/test_vppapigen.py b/src/tools/vppapigen/test_vppapigen.py index 09187f4c965..a8a0a49a8db 100755 --- a/src/tools/vppapigen/test_vppapigen.py +++ b/src/tools/vppapigen/test_vppapigen.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import unittest from vppapigen import VPPAPI, Option, ParseError @@ -60,7 +60,8 @@ class TestDefine(unittest.TestCase): test_string = ''' nonexisting_flag define foo { u8 foo; }; ''' - self.assertRaises(ParseError, self.parser.parse_string, test_string) + with self.assertRaises(ParseError): + self.parser.parse_string(test_string) class TestService(unittest.TestCase): diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py index 4ca9b954e67..431a9dc7f93 100755 --- a/src/tools/vppapigen/vppapigen.py +++ b/src/tools/vppapigen/vppapigen.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from __future__ import print_function import ply.lex as lex @@ -133,11 +133,11 @@ def crc_block(block): class Service(): - def __init__(self, caller, reply, events=[], stream=False): + def __init__(self, caller, reply, events=None, stream=False): self.caller = caller self.reply = reply self.stream = stream - self.events = events + self.events = [] if events is None else events class Typedef(): @@ -170,8 +170,8 @@ class Using(): else: a = { 'type': alias.fieldtype } self.alias = a - self.crc = binascii.crc32(str(alias)) & 0xffffffff - global_crc = binascii.crc32(str(alias), global_crc) + self.crc = binascii.crc32(str(alias).encode()) & 0xffffffff + global_crc = binascii.crc32(str(alias).encode(), global_crc) global_type_add(name) def __repr__(self): @@ -759,12 +759,17 @@ def main(): if sys.version[0] == '2': cliparser.add_argument('--input', type=argparse.FileType('r'), default=sys.stdin) + cliparser.add_argument('--output', nargs='?', + type=argparse.FileType('w'), + default=sys.stdout) + else: cliparser.add_argument('--input', type=argparse.FileType('r', encoding='UTF-8'), default=sys.stdin) - cliparser.add_argument('--output', nargs='?', type=argparse.FileType('w'), - default=sys.stdout) + cliparser.add_argument('--output', nargs='?', + type=argparse.FileType('w', encoding='UTF-8'), + default=sys.stdout) cliparser.add_argument('output_module', nargs='?', default='C') cliparser.add_argument('--debug', action='store_true') |