From 6c5f06a7e0765bd9b1b260a616c6d024439dbcfc Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Thu, 22 Feb 2018 23:17:18 +0100 Subject: [PATCH 01/11] structural changes to setup.py & added 'Deprecated' library --- requirements.txt | 3 ++- setup.py | 34 +++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index f6c1a1f57..2765eba2c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -pyserial +pyserial >= 3.0 +Deprecated >= 1.1.0 diff --git a/setup.py b/setup.py index 339daa2e3..c358e85bb 100644 --- a/setup.py +++ b/setup.py @@ -19,24 +19,44 @@ logging.basicConfig(level=logging.WARNING) setup( + + # Description name="python-can", url="https://github.com/hardbyte/python-can", + description="Controller Area Network interface module for Python", + long_description=long_description, + + # Code version=version, packages=find_packages(), + + # Author author="Brian Thorne", author_email="brian@thorne.link", - description="Controller Area Network interface module for Python", - long_description=long_description, + + # License license="LGPL v3", + + # Package data package_data={ "": ["CONTRIBUTORS.txt", "LICENSE.txt"], "doc": ["*.*"] }, - # Tests can be run using `python setup.py test` - test_suite="nose.collector", - tests_require=['mock', 'nose', 'pyserial'], + + # Installation + install_requires=[ + 'Deprecated >= 1.1.0', + ], extras_require={ - 'serial': ['pyserial'], + 'serial': ['pyserial >= 3.0'], 'neovi': ['python-ics'], - } + }, + + # Testing + test_suite="nose.collector", + tests_require=[ + 'mock', + 'nose', + 'pyserial >= 3.0' + ], ) From 54aa4fd02742b6ad944cdd6fde817b614e7ada95 Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Thu, 22 Feb 2018 23:57:20 +0100 Subject: [PATCH 02/11] @deprecated the name SqlReader --- can/io/sqlite.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/can/io/sqlite.py b/can/io/sqlite.py index 454a09f2a..243652aec 100644 --- a/can/io/sqlite.py +++ b/can/io/sqlite.py @@ -13,6 +13,8 @@ import logging import sqlite3 +from deprecated import deprecated + from can.listener import BufferedReader from can.message import Message @@ -22,7 +24,8 @@ buffer = memoryview -class SqliteReader: +@deprecated(version='2.1', reason="Use the name SqliteReader instead") +class SqlReader: """ Reads recorded CAN messages from a simple SQL database. @@ -65,10 +68,8 @@ def close(self): """Closes the connection to the database.""" self.conn.close() - -# Backward compatibility -# TODO remove in later releases? -SqlReader = SqliteReader +# SqliteReader is the newer name +SqliteReader = SqlReader class SqliteWriter(BufferedReader): From d610677f6f61858270656dc81129937c7ed0b0d2 Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 23 Feb 2018 00:05:40 +0100 Subject: [PATCH 03/11] removed the version attribute from the deprecated decorator --- can/io/sqlite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/io/sqlite.py b/can/io/sqlite.py index 243652aec..c1327f26e 100644 --- a/can/io/sqlite.py +++ b/can/io/sqlite.py @@ -24,7 +24,7 @@ buffer = memoryview -@deprecated(version='2.1', reason="Use the name SqliteReader instead") +@deprecated(reason="Use the name SqliteReader instead. (Replaced in v2.1)") class SqlReader: """ Reads recorded CAN messages from a simple SQL database. From f2a7fd9764ffaf203ff05dddb26968207c9556c4 Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 23 Feb 2018 00:13:02 +0100 Subject: [PATCH 04/11] fix wrong method call --- can/io/sqlite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/io/sqlite.py b/can/io/sqlite.py index c1327f26e..bbdfea71b 100644 --- a/can/io/sqlite.py +++ b/can/io/sqlite.py @@ -52,7 +52,7 @@ def _create_frame_from_db_tuple(frame_data): def __iter__(self): log.debug("Iterating through messages from sql db") for frame_data in self.cursor.execute(self._SELECT_ALL_COMMAND): - yield SqliteReader._create_frame_from_db_tuple(frame_data) + yield SqlReader._create_frame_from_db_tuple(frame_data) def __len__(self): # this might not run in constant time From 877acdec218357ddc310f08a2c01bd5a883005f0 Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 23 Feb 2018 00:33:17 +0100 Subject: [PATCH 05/11] try to enable useful tests with appveyor --- .appveyor.yml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 000000000..aab83f930 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,45 @@ +environment: + + matrix: + + # For Python versions available on Appveyor, see + # http://www.appveyor.com/docs/installed-software#python + + - PYTHON: "C:\\Python27" + - PYTHON: "C:\\Python33" + - PYTHON: "C:\\Python34" + - PYTHON: "C:\\Python35" + - PYTHON: "C:\\Python36" + - PYTHON: "C:\\Python27-x64" + - PYTHON: "C:\\Python33-x64" + - PYTHON: "C:\\Python34-x64" + - PYTHON: "C:\\Python35-x64" + - PYTHON: "C:\\Python36-x64" + +install: + # We need our usual libraries + - "%PYTHON%\\python.exe -m pip install -r requirements.txt" + # We need wheel installed to build wheels + - "%PYTHON%\\python.exe -m pip install wheel" + +build: off + +test_script: + # Put your test command here. + # Note that you must use the environment variable %PYTHON% to refer to + # the interpreter you're using - Appveyor does not do anything special + # to put the Python version you want to use on PATH. + - "%PYTHON%\\python.exe setup.py test" + +#after_test: +# # This step builds your wheels. +# - "%PYTHON%\\python.exe setup.py bdist_wheel" + +#artifacts: +# # bdist_wheel puts your built wheel in the dist directory +# - path: dist\* + +#on_success: +# You can use this step to upload your artifacts to a public website. +# See Appveyor's documentation for more details. Or you can simply +# access your wheels from the Appveyor "artifacts" tab for your build. From 311978e05038c8a5ce4f6464efe4dc316c80f234 Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 23 Feb 2018 00:41:32 +0100 Subject: [PATCH 06/11] try simplifying .appveyor.yml --- .appveyor.yml | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index aab83f930..caacf9134 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -20,26 +20,12 @@ install: # We need our usual libraries - "%PYTHON%\\python.exe -m pip install -r requirements.txt" # We need wheel installed to build wheels - - "%PYTHON%\\python.exe -m pip install wheel" + #- "%PYTHON%\\python.exe -m pip install wheel" build: off test_script: - # Put your test command here. # Note that you must use the environment variable %PYTHON% to refer to # the interpreter you're using - Appveyor does not do anything special # to put the Python version you want to use on PATH. - "%PYTHON%\\python.exe setup.py test" - -#after_test: -# # This step builds your wheels. -# - "%PYTHON%\\python.exe setup.py bdist_wheel" - -#artifacts: -# # bdist_wheel puts your built wheel in the dist directory -# - path: dist\* - -#on_success: -# You can use this step to upload your artifacts to a public website. -# See Appveyor's documentation for more details. Or you can simply -# access your wheels from the Appveyor "artifacts" tab for your build. From f097247beaed67d93cfe0dd8d4bbafd3ef10efc8 Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 23 Feb 2018 01:05:57 +0100 Subject: [PATCH 07/11] factored out common Travis skipping behaviour and replaced it with generic CI skipping behaviour --- .appveyor.yml | 4 ++-- test/__init__.py | 2 ++ test/back2back_test.py | 11 ++++------- test/config.py | 24 ++++++++++++++++++++++++ test/simplecyclic_test.py | 10 ++++------ 5 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 test/__init__.py create mode 100644 test/config.py diff --git a/.appveyor.yml b/.appveyor.yml index caacf9134..58b3eebe2 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -19,8 +19,8 @@ environment: install: # We need our usual libraries - "%PYTHON%\\python.exe -m pip install -r requirements.txt" - # We need wheel installed to build wheels - #- "%PYTHON%\\python.exe -m pip install wheel" + # We need to install the python-can library itself + - "%PYTHON%\\python.exe -m pip install ." build: off diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 000000000..394a0a067 --- /dev/null +++ b/test/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python +# coding: utf-8 diff --git a/test/back2back_test.py b/test/back2back_test.py index 85c4c2e4a..2b2f70198 100644 --- a/test/back2back_test.py +++ b/test/back2back_test.py @@ -3,22 +3,19 @@ """ This module tests two virtual busses attached to each other. - -Some tests are skipped when run on Travis CI because they are not -reproducible, see #243 (https://github.com/hardbyte/python-can/issues/243). """ -import os +from __future__ import absolute_import + import unittest import time import can -IS_TRAVIS = os.environ.get('TRAVIS', 'default') == 'true' +from .config import * BITRATE = 500000 TIMEOUT = 0.1 -TEST_CAN_FD = True INTERFACE_1 = 'virtual' CHANNEL_1 = 'vcan0' @@ -79,7 +76,7 @@ def _send_and_receive(self, msg): def test_no_message(self): self.assertIsNone(self.bus1.recv(0.1)) - @unittest.skipIf(IS_TRAVIS, "skip on Travis CI") + @unittest.skipIf(IS_CI, "the timing sensitive behaviour cannot be reproduced reliably on a CI server") def test_timestamp(self): self.bus2.send(can.Message()) recv_msg1 = self.bus1.recv(TIMEOUT) diff --git a/test/config.py b/test/config.py new file mode 100644 index 000000000..a25aff627 --- /dev/null +++ b/test/config.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# coding: utf-8 + +""" +This module contains some configuration for the tests. + +Some tests are skipped when run on a CI server because they are not +reproducible, see #243 (https://github.com/hardbyte/python-can/issues/243). +""" + +from os import environ as environment + +# see here for the environment variables that are set on the CI servers: +# - https://docs.travis-ci.com/user/environment-variables/ +# - https://www.appveyor.com/docs/environment-variables/ + +IS_TRAVIS = environment.get('TRAVIS', '').lower() == 'true' +IS_APPVEYOR = environment.get('APPVEYOR', '').lower() == 'true' + +IS_CI = IS_TRAVIS or IS_APPVEYOR or \ + environment.get('CI', '').lower() == 'true' or \ + environment.get('CONTINUOUS_INTEGRATION', '').lower() == 'true' + +TEST_CAN_FD = True diff --git a/test/simplecyclic_test.py b/test/simplecyclic_test.py index 362e89c2c..f4ab7cab2 100644 --- a/test/simplecyclic_test.py +++ b/test/simplecyclic_test.py @@ -3,22 +3,20 @@ """ This module tests cyclic send tasks. - -Some tests are skipped when run on Travis CI because they are not -reproducible, see #243 (https://github.com/hardbyte/python-can/issues/243). """ -import os +from __future__ import absolute_import + from time import sleep import unittest import can -IS_TRAVIS = os.environ.get('TRAVIS', 'default') == 'true' +from .config import * class SimpleCyclicSendTaskTest(unittest.TestCase): - @unittest.skipIf(IS_TRAVIS, "skip on Travis CI") + @unittest.skipIf(IS_CI, "the timing sensitive behaviour cannot be reproduced reliably on a CI server") def test_cycle_time(self): msg = can.Message(extended_id=False, arbitration_id=0x100, data=[0,1,2,3,4,5,6,7]) bus1 = can.interface.Bus(bustype='virtual') From 9a2d88010c87362f67b67b60e09aa8743e17b32e Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 23 Feb 2018 01:24:33 +0100 Subject: [PATCH 08/11] add appveyor badge to README.md --- README.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 8002997eb..a61ae9e6e 100644 --- a/README.rst +++ b/README.rst @@ -1,19 +1,23 @@ python-can ========== -|release| |docs| |build| +|release| |docs| |build_travis| |build_appveyor| .. |release| image:: https://img.shields.io/pypi/v/python-can.svg :target: https://pypi.python.org/pypi/python-can/ - :alt: Latest Version + :alt: Latest Version on PyPi .. |docs| image:: https://readthedocs.org/projects/python-can/badge/?version=stable :target: https://python-can.readthedocs.io/en/stable/ - :alt: Documentation Status + :alt: Documentation build Status -.. |build| image:: https://travis-ci.org/hardbyte/python-can.svg?branch=develop +.. |build_travis| image:: https://travis-ci.org/hardbyte/python-can.svg?branch=develop :target: https://travis-ci.org/hardbyte/python-can/branches - :alt: CI Server for develop branch + :alt: Travis CI Server for develop branch + +.. |build_appveyor| image:: https://ci.appveyor.com/api/projects/status/github/hardbyte/python-can?branch=develop&svg=true + :target: https://ci.appveyor.com/project/hardbyte/python-can/history + :alt: AppVeyor CI Server for develop branch The **C**\ ontroller **A**\ rea **N**\ etwork is a bus standard designed From 3728b1fd90ff174546fd6f9dbc38d6b89bcad163 Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 23 Feb 2018 01:47:02 +0100 Subject: [PATCH 09/11] Trigger CI build From 0a037687937cfa67b065531f00951658a24d24c0 Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 23 Feb 2018 01:57:06 +0100 Subject: [PATCH 10/11] fix problem from another branch so we can test here --- can/io/sqlite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/io/sqlite.py b/can/io/sqlite.py index bbdfea71b..56ff61b41 100644 --- a/can/io/sqlite.py +++ b/can/io/sqlite.py @@ -52,7 +52,7 @@ def _create_frame_from_db_tuple(frame_data): def __iter__(self): log.debug("Iterating through messages from sql db") for frame_data in self.cursor.execute(self._SELECT_ALL_COMMAND): - yield SqlReader._create_frame_from_db_tuple(frame_data) + yield self._create_frame_from_db_tuple(frame_data) def __len__(self): # this might not run in constant time From 148c65a24eccc8cca6fdf48e7182ee647052886f Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 23 Feb 2018 02:14:59 +0100 Subject: [PATCH 11/11] fix absolute imports --- test/listener_test.py | 4 +++- test/logformats_test.py | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/test/listener_test.py b/test/listener_test.py index 4f6d9baea..e9495c066 100755 --- a/test/listener_test.py +++ b/test/listener_test.py @@ -4,6 +4,8 @@ """ """ +from __future__ import absolute_import + from time import sleep import unittest import random @@ -14,7 +16,7 @@ import can -from data.example_data import generate_message +from .data.example_data import generate_message channel = 'vcan0' can.rc['interface'] = 'virtual' diff --git a/test/logformats_test.py b/test/logformats_test.py index 019ea7147..728d997e3 100644 --- a/test/logformats_test.py +++ b/test/logformats_test.py @@ -12,6 +12,7 @@ """ from __future__ import print_function +from __future__ import absolute_import import unittest import tempfile @@ -28,9 +29,9 @@ import can -from data.example_data import TEST_MESSAGES_BASE, TEST_MESSAGES_REMOTE_FRAMES, \ - TEST_MESSAGES_ERROR_FRAMES, TEST_COMMENTS, \ - generate_message +from .data.example_data import TEST_MESSAGES_BASE, TEST_MESSAGES_REMOTE_FRAMES, \ + TEST_MESSAGES_ERROR_FRAMES, TEST_COMMENTS, \ + generate_message def _test_writer_and_reader(test_case, writer_constructor, reader_constructor, sleep_time=None,