Skip to content

Commit

Permalink
Prepare release of 0.4.0 (#56)
Browse files Browse the repository at this point in the history
* Removed SMBusWrapper class.
* Add Python 3.9 to Travis build.
* Updated readme, version- and docstrings.
  • Loading branch information
kplindegaard authored Dec 5, 2020
1 parent 12f7fc1 commit 013db7b
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ matrix:
env: TOXENV=py37
- python: 3.8
env: TOXENV=py38
- python: 3.9
env: TOXENV=py39
- python: 3.5
env: TOXENV=qa,doc

Expand Down
24 changes: 22 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,27 @@
Notable changes to the smbus2 project are recorded here.

## [Unreleased]

## [0.4.0] - 2020-12-05
### Added
- Support for SMBus PEC (Packet Error Checking).
- Support for Python 3 type hinting and mypy static type analysis. Type stubs added to the project.
- Added Python 3.8 to Travis-CI build config.

### Removed
As of this version the `SMBusWrapper` class is removed and must be replaced with `SMBus`:

```python
# No longer valid!
with SMBusWrapper(1) as bus:
...

# Replace with
with SMBus(1) as bus:
...
```

### General
- Added Python 3.8 and 3.9 to Travis-CI build config.
- Cleaner docs:
- Removed redundant `README.rst`.
- `README.md`, `CHANGELOG.md` and `LICENSE` added to dist package.
Expand Down Expand Up @@ -61,7 +80,8 @@ Notable changes to the smbus2 project are recorded here.
First published version.


[Unreleased]: https://github.com/kplindegaard/smbus2/compare/0.3.0...HEAD
[Unreleased]: https://github.com/kplindegaard/smbus2/compare/0.4.0...HEAD
[0.4.0]: https://github.com/kplindegaard/smbus2/compare/0.3.0...0.4.0
[0.3.0]: https://github.com/kplindegaard/smbus2/compare/0.2.3...0.3.0
[0.2.3]: https://github.com/kplindegaard/smbus2/compare/0.2.2...0.2.3
[0.2.2]: https://github.com/kplindegaard/smbus2/compare/0.2.1...0.2.2
Expand Down
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ A drop-in replacement for smbus-cffi/smbus-python in pure Python

[![Build Status](https://travis-ci.org/kplindegaard/smbus2.svg?branch=master)](https://travis-ci.org/kplindegaard/smbus2)
[![Documentation Status](https://readthedocs.org/projects/smbus2/badge/?version=latest)](http://smbus2.readthedocs.io/en/latest/?badge=latest)

![Python Verions](https://img.shields.io/pypi/pyversions/smbus2.svg)
[![PyPi Version](https://img.shields.io/pypi/v/smbus2.svg)](https://pypi.org/project/smbus2/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/smbus2)](https://pypi.org/project/smbus2/)

# Introduction
Expand All @@ -17,6 +20,7 @@ It was designed from the ground up with two goals in mind:
Currently supported features are:

* Get i2c capabilities (I2C_FUNCS)
* SMBus Packet Error Checking (PEC) support
* read_byte
* write_byte
* read_byte_data
Expand All @@ -34,6 +38,8 @@ Currently supported features are:

It is developed on Python 2.7 but works without any modifications in Python 3.X too.

More information about updates and general changes are recorded in the [change log](https://github.com/kplindegaard/smbus2/blob/master/CHANGELOG.md).

# SMBus code examples

smbus2 installs next to smbus as the package, so it's not really a 100% replacement. You must change the module name.
Expand All @@ -58,6 +64,17 @@ This is the very same example but safer to use since the smbus will be closed au
b = bus.read_byte_data(80, 0)
print(b)

## Example 1c: Read a byte with PEC enabled

Same example with Packet Error Checking enabled.

from smbus2 import SMBus

with SMBus(1) as bus:
bus.pec = 1 # Enable PEC
b = bus.read_byte_data(80, 0)
print(b)

## Example 2: Read a block of data

You can read up to 32 bytes at once.
Expand Down Expand Up @@ -149,10 +166,14 @@ All data is contained in the i2c_msg instances. Here are some data access altern

# Installation instructions

smbus2 is pure Python code and requires no compilation. Installation is easy:

python setup.py install

Or just use pip
From PyPi with `pip`:

pip install smbus2

From conda-forge using `conda`:

conda install -c conda-forge smbus2

Installation from source code is straight forward:

python setup.py install
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# The MIT License (MIT)
# Copyright (c) 2017 Karl-Petter Lindegaard
# Copyright (c) 2020 Karl-Petter Lindegaard
#
# smbus2 documentation build configuration file.
#
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ smbus2
:target: https://pypi.python.org/pypi/smbus2

.. automodule:: smbus2
:members: SMBus, SMBusWrapper, i2c_msg
:members: SMBus, i2c_msg
:undoc-members:

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def find_version(*file_paths):
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8"
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9"
],
)
6 changes: 3 additions & 3 deletions smbus2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""smbus2 - A drop-in replacement for smbus-cffi/smbus-python"""
# The MIT License (MIT)
# Copyright (c) 2017 Karl-Petter Lindegaard
# Copyright (c) 2020 Karl-Petter Lindegaard
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,6 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from .smbus2 import SMBus, SMBusWrapper, i2c_msg, I2cFunc # noqa: F401
from .smbus2 import SMBus, i2c_msg, I2cFunc # noqa: F401

__version__ = "0.3.0"
__version__ = "0.4.0"
33 changes: 2 additions & 31 deletions smbus2/smbus2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""smbus2 - A drop-in replacement for smbus-cffi/smbus-python"""
# The MIT License (MIT)
# Copyright (c) 2017 Karl-Petter Lindegaard
# Copyright (c) 2020 Karl-Petter Lindegaard
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -335,6 +335,7 @@ def enable_pec(self, enable=True):
ioctl(self.fd, I2C_PEC, self._pec)

pec = property(_get_pec, enable_pec) # Drop-in replacement for smbus member "pec"
"""Get and set SMBus PEC. 0 = disabled (default), 1 = enabled."""

def _set_address(self, address, force=None):
"""
Expand Down Expand Up @@ -655,33 +656,3 @@ def i2c_rdwr(self, *i2c_msgs):
"""
ioctl_data = i2c_rdwr_ioctl_data.create(*i2c_msgs)
ioctl(self.fd, I2C_RDWR, ioctl_data)


class SMBusWrapper:
"""
Wrapper class around the SMBus.
Deprecated as of version 0.3.0. Please replace with :py:class:`SMBus`.
Enables the user to wrap access to the :py:class:`SMBus` class in a
"with" statement. If auto_cleanup is True (default), the
:py:class:`SMBus` handle will be automatically closed
upon exit of the ``with`` block.
"""
def __init__(self, bus_number=0, auto_cleanup=True, force=False):
"""
:param auto_cleanup: Close bus when leaving scope.
:type auto_cleanup: Boolean
:param force: Force using the slave address even when driver is already using it.
:type force: Boolean
"""
self.bus_number = bus_number
self.auto_cleanup = auto_cleanup
self.force = force

def __enter__(self):
self.bus = SMBus(bus=self.bus_number, force=self.force)
return self.bus

def __exit__(self, exc_type, exc_val, exc_tb):
if self.auto_cleanup:
self.bus.close()
19 changes: 3 additions & 16 deletions smbus2/smbus2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ I2C_SLAVE_FORCE: int
I2C_FUNCS: int
I2C_RDWR: int
I2C_SMBUS: int
I2C_PEC: int
I2C_SMBUS_WRITE: int
I2C_SMBUS_READ: int
I2C_SMBUS_QUICK: int
Expand Down Expand Up @@ -83,6 +84,7 @@ class SMBus:
funcs: I2cFunc = ...
address: Optional[int] = ...
force: Optional[bool] = ...
pec: int = ...
def __init__(
self, bus: _UnionT[None, int, str] = ..., force: bool = ...
) -> None: ...
Expand All @@ -95,6 +97,7 @@ class SMBus:
) -> None: ...
def open(self, bus: _UnionT[int, str]) -> None: ...
def close(self) -> None: ...
def enable_pec(self, enable: bool) -> None: ...
def write_quick(self, i2c_addr: int, force: Optional[bool] = ...) -> None: ...
def read_byte(self, i2c_addr: int, force: Optional[bool] = ...) -> int: ...
def write_byte(
Expand Down Expand Up @@ -143,19 +146,3 @@ class SMBus:
force: Optional[bool] = ...,
) -> None: ...
def i2c_rdwr(self, *i2c_msgs: i2c_msg) -> None: ...

class SMBusWrapper:
bus_number: int = ...
auto_cleanup: bool = ...
force: bool = ...
bus: SMBus = ...
def __init__(
self, bus_number: int = ..., auto_cleanup: bool = ..., force: bool = ...
) -> None: ...
def __enter__(self): ...
def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> None: ...
2 changes: 1 addition & 1 deletion tests/test_datatypes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The MIT License (MIT)
# Copyright (c) 2017 Karl-Petter Lindegaard
# Copyright (c) 2020 Karl-Petter Lindegaard
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion tests/test_smbus2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The MIT License (MIT)
# Copyright (c) 2017 Karl-Petter Lindegaard
# Copyright (c) 2020 Karl-Petter Lindegaard
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{27,34,35,36,37,38},qa,doc
envlist = py{27,34,35,36,37,38,39},qa,doc
skip_missing_interpreters = True

[testenv]
Expand Down

0 comments on commit 013db7b

Please sign in to comment.