diff --git a/Makefile b/Makefile index 49996eb..176c50a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -LIBRARY_VERSION=$(shell cat library/setup.py | grep version | awk -F"'" '{print $$2}') -LIBRARY_NAME=$(shell cat library/setup.py | grep name | awk -F"'" '{print $$2}') +LIBRARY_VERSION=$(shell grep version library/setup.cfg | awk -F" = " '{print $$2}') +LIBRARY_NAME=$(shell grep name library/setup.cfg | awk -F" = " '{print $$2}') .PHONY: usage install uninstall usage: @@ -9,7 +9,7 @@ usage: @echo "install: install the library locally from source" @echo "uninstall: uninstall the local library" @echo "check: peform basic integrity checks on the codebase" - @echo "python-readme: generate library/README.rst from README.md" + @echo "python-readme: generate library/README.md from README.md + library/CHANGELOG.txt" @echo "python-wheels: build python .whl files for distribution" @echo "python-sdist: build python source distribution" @echo "python-clean: clean python build and dist directories" @@ -36,12 +36,14 @@ check: tag: git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}" -python-readme: library/README.rst +python-readme: library/README.md python-license: library/LICENSE.txt -library/README.rst: README.md - pandoc --from=markdown --to=rst -o library/README.rst README.md +library/README.md: README.md library/CHANGELOG.txt + cp README.md library/README.md + printf "\n\n# Changelog\n\n" >> library/README.md + cat library/CHANGELOG.txt >> library/README.md library/LICENSE.txt: LICENSE cp LICENSE library/LICENSE.txt diff --git a/library/README.md b/library/README.md new file mode 100644 index 0000000..dbddcf6 --- /dev/null +++ b/library/README.md @@ -0,0 +1,39 @@ +# MCP9600 Thermocouple Temperature Sensor + +[![Build Status](https://travis-ci.com/pimoroni/mcp9600-python.svg?branch=master)](https://travis-ci.com/pimoroni/mcp9600-python) +[![Coverage Status](https://coveralls.io/repos/github/pimoroni/mcp9600-python/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/mcp9600-python?branch=master) +[![PyPi Package](https://img.shields.io/pypi/v/mcp9600.svg)](https://pypi.python.org/pypi/mcp9600) +[![Python Versions](https://img.shields.io/pypi/pyversions/mcp9600.svg)](https://pypi.python.org/pypi/mcp9600) + + +# Installing + +Stable library from PyPi: + +* Just run `sudo pip install mcp9600` + +Latest/development library from GitHub: + +* `git clone https://github.com/pimoroni/mcp9600-python` +* `cd mcp9600-python` +* `sudo ./install.sh` + + + +# Changelog + +0.0.3 +----- + +* Port to i2cdevice>=0.0.6 set/get API + +0.0.2 +----- + +* Added `get_altitude` method +* Corrected pressure to hPa + +0.0.1 +----- + +* Initial Release diff --git a/library/README.rst b/library/README.rst deleted file mode 100644 index 2d29e1d..0000000 --- a/library/README.rst +++ /dev/null @@ -1,26 +0,0 @@ -MCP9600 Thermocouple Temperature Sensor -======================================= - -|Build Status| |Coverage Status| |PyPi Package| |Python Versions| - -Installing -========== - -Stable library from PyPi: - -- Just run ``sudo pip install mcp9600`` - -Latest/development library from GitHub: - -- ``git clone https://github.com/pimoroni/mcp9600-python`` -- ``cd mcp9600-python`` -- ``sudo ./install.sh`` - -.. |Build Status| image:: https://travis-ci.com/pimoroni/mcp9600-python.svg?branch=master - :target: https://travis-ci.com/pimoroni/mcp9600-python -.. |Coverage Status| image:: https://coveralls.io/repos/github/pimoroni/mcp9600-python/badge.svg?branch=master - :target: https://coveralls.io/github/pimoroni/mcp9600-python?branch=master -.. |PyPi Package| image:: https://img.shields.io/pypi/v/mcp9600.svg - :target: https://pypi.python.org/pypi/mcp9600 -.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/mcp9600.svg - :target: https://pypi.python.org/pypi/mcp9600 diff --git a/library/mcp9600/__init__.py b/library/mcp9600/__init__.py index badf08c..3c29d75 100644 --- a/library/mcp9600/__init__.py +++ b/library/mcp9600/__init__.py @@ -200,6 +200,22 @@ def __init__(self, i2c_addr=I2C_ADDRESS_DEFAULT, i2c_dev=None): def setup(self): pass + def set_thermocouple_type(self, thermocouple_type): + """Set the type of thermocouple connected to the MCP9600. + + :param thermocouple_type: One of 'K', 'J', 'T', 'N', 'S', 'E', 'B' or 'R' + + """ + self._mcp9600.set('THERMOCOUPLE_CONFIG', type_select=thermocouple_type) + + def get_thermocouple_type(self): + """Get the type of thermocouple connected to the MCP9600. + + Returns one of 'K', 'J', 'T', 'N', 'S', 'E', 'B' or 'R' + + """ + return self._mcp9600.get('THERMOCOUPLE_CONFIG').type_select + def get_hot_junction_temperature(self): """Return the temperature measured by the attached thermocouple.""" return self._mcp9600.get('HOT_JUNCTION').temperature diff --git a/library/setup.cfg b/library/setup.cfg index 5c3c3ea..c88c63c 100644 --- a/library/setup.cfg +++ b/library/setup.cfg @@ -1,6 +1,39 @@ +# -*- coding: utf-8 -*- +[metadata] +name = mcp9600 +version = 0.0.3 +author = Philip Howard +author_email = phil@pimoroni.com +description = Python library for the MCP9600 thermocouple temperature sensor +long_description = file: README.md +long_description_content_type = text/markdown +keywords = Raspberry Pi +url = https://www.pimoroni.com +project_urls = + GitHub=https://github.com/pimoroni/mcp9600-pytho +license = MIT +# This includes the license file(s) in the wheel. +# https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file +license_files = LICENSE.txt +classifiers = + Development Status :: 4 - Beta + Operating System :: POSIX :: Linux + License :: OSI Approved :: MIT License + Intended Audience :: Developers + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Topic :: Software Development + Topic :: Software Development :: Libraries + Topic :: System :: Hardware + +[options] +python_requires = >= 2.7 +packages = mcp9600 +install_requires = + i2cdevice >= 0.0.6 + [flake8] exclude = - test.py .tox, .eggs, .git, @@ -9,3 +42,9 @@ exclude = dist ignore = E501 + +[pimoroni] +py2deps = +py3deps = +configtxt = +commands = diff --git a/library/setup.py b/library/setup.py index dc3f56c..454ecab 100755 --- a/library/setup.py +++ b/library/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python - +# -*- coding: utf-8 -*- """ -Copyright (c) 2016 Pimoroni +Copyright (c) 2020 Pimoroni Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -22,32 +22,12 @@ SOFTWARE. """ -try: - from setuptools import setup -except ImportError: - from distutils.core import setup +from setuptools import setup, __version__ +from pkg_resources import parse_version + +minimum_version = parse_version('30.4.0') -classifiers = ['Development Status :: 4 - Beta', - 'Operating System :: POSIX :: Linux', - 'License :: OSI Approved :: MIT License', - 'Intended Audience :: Developers', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Topic :: Software Development', - 'Topic :: System :: Hardware'] +if parse_version(__version__) < minimum_version: + raise RuntimeError("Package setuptools must be at least version {}".format(minimum_version)) -setup( - name='mcp9600', - version='0.0.3', - author='Philip Howard', - author_email='phil@pimoroni.com', - description="""Python library for the MCP9600 thermocouple temperature sensor""", - long_description=open('README.rst').read() + '\n' + open('CHANGELOG.txt').read(), - license='MIT', - keywords='Raspberry Pi', - url='http://www.pimoroni.com', - classifiers=classifiers, - packages=['mcp9600'], - install_requires=['i2cdevice>=0.0.6'] -) +setup() diff --git a/library/tests/test_features.py b/library/tests/test_features.py index db4f7b2..f578d1e 100644 --- a/library/tests/test_features.py +++ b/library/tests/test_features.py @@ -74,3 +74,27 @@ def test_alert_clear(): device.clear_alert(1) assert smbus.regs[0x08] & 0b10000000 == 0b10000000 + + +def test_set_thermocouple_type(): + import mcp9600 + smbus = MockSMBus(1, default_registers={ + 0x04: 0b00000101, + 0x05: 0b00000000, + 0x20: 0x40}) + device = mcp9600.MCP9600(i2c_dev=smbus) + + device.set_thermocouple_type('N') + + assert (smbus.regs[0x05] >> 4) & 0b111 == 0b011 + + +def test_get_thermocouple_type(): + import mcp9600 + smbus = MockSMBus(1, default_registers={ + 0x04: 0b00000101, + 0x05: 0b00110000, + 0x20: 0x40}) + device = mcp9600.MCP9600(i2c_dev=smbus) + + assert device.get_thermocouple_type() == 'N' diff --git a/library/tox.ini b/library/tox.ini index c3a18ec..a7ade4a 100644 --- a/library/tox.ini +++ b/library/tox.ini @@ -1,12 +1,12 @@ [tox] -envlist = py{27,35},qa +envlist = py{27,35,37},qa skip_missing_interpreters = True [testenv] commands = python setup.py install coverage run -m py.test -v -r wsx - coverage report + coverage report -m deps = mock pytest>=3.1 @@ -14,8 +14,11 @@ deps = [testenv:qa] commands = + check-manifest --ignore tox.ini,tests*,.coveragerc + python setup.py sdist bdist_wheel + twine check dist/* flake8 --ignore E501 - rstcheck README.rst deps = + check-manifest flake8 - rstcheck + twine