Skip to content

Commit

Permalink
Convert to use pyproject.toml and poetry, extend tests to more platfo…
Browse files Browse the repository at this point in the history
…rms (#674)

* first step to convert to poetry

* Adjust azure-pipelines to install deps using poetry

* add missing pyproject.toml ..

* Remove poetry develop call, install should be enough

* use poetry run to run checks in correct environment

* test against windows & osx for python 3.6-3.8

* separate linting from tests

* Fix job naming

* add cffi to dev requirements, update development environment documentation, remove obsolete setuptools and pip updates from docs

* add sphinx to CI builds, remove obsoleted sphinx-autodoc-typehints as sphinx supports type hints starting from version 3.0

* Fix display->displayName

* use poetry run for running sphinx, remove the autodoc ext from pyproject dependencies
  • Loading branch information
rytilahti authored May 1, 2020
1 parent b368507 commit 7a27314
Show file tree
Hide file tree
Showing 23 changed files with 1,429 additions and 256 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
exclude = .git,.tox,__pycache__
max-line-length = 88
select = C,E,F,W,B,B950
ignore = E501,W503,E203
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ __pycache__

.coverage

docs/_build/
docs/_build/
16 changes: 11 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: check-ast

- repo: https://github.com/ambv/black
rev: stable
hooks:
Expand All @@ -15,6 +25,7 @@ repos:
rev: v4.3.21
hooks:
- id: isort
additional_dependencies: [toml]

- repo: https://github.com/PyCQA/doc8
rev: 0.8.1rc2
Expand All @@ -26,8 +37,3 @@ repos:
# hooks:
# - id: mypy
# args: [--no-strict-optional, --ignore-missing-imports]

- repo: https://github.com/mgedmin/check-manifest
rev: "0.40"
hooks:
- id: check-manifest
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ New supported devices:
* Xiaomi Water Purifier
* Xiaomi Air Humidifier
* Xiaomi Smart Wifi Speaker (incomplete, help wanted)

[Full Changelog](https://github.com/rytilahti/python-miio/compare/0.2.0...0.3.0)

**Implemented enhancements:**
Expand Down Expand Up @@ -1056,7 +1056,7 @@ Considering how far this project has evolved from being just an interface for th

This release brings support to a couple of new devices, and contains fixes for some already supported ones.
All thanks for the improvements in this release go to syssi!

* Extended mDNS discovery to support more devices (@syssi)
* Improved support for the following devices:
* Air purifier (@syssi)
Expand Down Expand Up @@ -1120,7 +1120,7 @@ Fix dependencies
* Xiaomi Philips LED Ball Lamp (@kuduka)

* Discovery now uses mDNS instead of handshake protocol. Old behavior still available with `--handshake true`

[Full Changelog](https://github.com/rytilahti/python-miio/compare/0.1.2...0.1.3)

**Closed issues:**
Expand Down
1 change: 0 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,3 @@ it more useful to permit linking proprietary applications with the library. If
this is what you want to do, use the GNU Lesser General Public License instead
of this License. But first, please read
[http://www.gnu.org/philosophy/why-not-lgpl.html](http://www.gnu.org/philosophy/why-not-lgpl.html).

11 changes: 0 additions & 11 deletions MANIFEST.in

This file was deleted.

150 changes: 104 additions & 46 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,107 @@ trigger:
pr:
- master

pool:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Python36:
python.version: '3.6'
Python37:
python.version: '3.7'
# Python38:
# python.version: '3.8'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'

- script: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-azurepipelines pytest-cov pytest-mock
displayName: 'Install dependencies'

- script: |
pre-commit run black --all-files
displayName: 'Code formating (black)'

- script: |
pre-commit run flake8 --all-files
displayName: 'Code formating (flake8)'

#- script: |
# pre-commit run mypy --all-files
# displayName: 'Typing checks (mypy)'

- script: |
pre-commit run isort --all-files
displayName: 'Order of imports (isort)'

- script: |
pytest --cov miio --cov-report html
displayName: 'Tests'

- script: |
pre-commit run check-manifest --all-files
displayName: 'Check MANIFEST.in'

stages:
- stage: "Linting"
jobs:
- job: "LintChecks"
pool:
vmImage: "ubuntu-latest"
strategy:
matrix:
Python 3.8:
python.version: '3.8'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'

- script: |
python -m pip install --upgrade pip poetry
poetry install
displayName: 'Install dependencies'
- script: |
poetry run pre-commit run black --all-files
displayName: 'Code formating (black)'
- script: |
poetry run pre-commit run flake8 --all-files
displayName: 'Code formating (flake8)'
#- script: |
# pre-commit run mypy --all-files
# displayName: 'Typing checks (mypy)'

- script: |
poetry run pre-commit run isort --all-files
displayName: 'Order of imports (isort)'
- script: |
poetry run sphinx-build docs/ generated_docs
displayName: 'Documentation build (sphinx)'
- stage: "Tests"
jobs:
- job: "Tests"
strategy:
matrix:
Python 3.6 Ubuntu:
python.version: '3.6'
vmImage: 'ubuntu-latest'

Python 3.7 Ubuntu:
python.version: '3.7'
vmImage: 'ubuntu-latest'

Python 3.8 Ubuntu:
python.version: '3.8'
vmImage: 'ubuntu-latest'

PyPy Ubuntu:
python.version: pypy3
vmImage: 'ubuntu-latest'

Python 3.6 Windows:
python.version: '3.6'
vmImage: 'windows-latest'

Python 3.7 Windows:
python.version: '3.7'
vmImage: 'windows-latest'

Python 3.8 Windows:
python.version: '3.8'
vmImage: 'windows-latest'

Python 3.6 OSX:
python.version: '3.6'
vmImage: 'macOS-latest'

Python 3.7 OSX:
python.version: '3.7'
vmImage: 'macOS-latest'

Python 3.8 OSX:
python.version: '3.8'
vmImage: 'macOS-latest'

pool:
vmImage: $(vmImage)

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'

- script: |
python -m pip install --upgrade pip poetry
poetry install
displayName: 'Install dependencies'
- script: |
poetry run pytest --cov miio --cov-report html
displayName: 'Tests'
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx_autodoc_typehints",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
Expand Down
16 changes: 0 additions & 16 deletions docs/discovery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ do this on Debian-based systems (like Rasperry Pi) with
apt-get install libffi-dev libssl-dev
Depending on your installation, the setuptools version may be too old
for some dependencies so before reporting an issue please try to update
the setuptools package with

.. code-block:: bash
pip3 install -U setuptools
In case you get an error similar like
``ImportError: No module named 'packaging'`` during the installation,
you need to upgrade pip and setuptools:

.. code-block:: bash
pip3 install -U pip setuptools
Device discovery
================
Devices already connected on the same network where the command-line tool
Expand Down
22 changes: 6 additions & 16 deletions docs/new_devices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ Development environment
-----------------------

This section will shortly go through how to get you started with a working development environment.
We assume that you are familiar with virtualenv_ and are using it somehow (be it a manual setup, pipenv_, ..).
The easiest way to start is to use pip_ to install dependencies::
We use `poetry <https://python-poetry.org/>`__ for managing the dependencies and packaging, so simply execute:

pip install -r requirements.txt

followed by installing the package in `development mode <https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs>`__ ::

pip install -e .
poetry install

To verify the installation, simply launch tox_ to run all the checks::

Expand Down Expand Up @@ -52,17 +47,12 @@ please do not forget to create tests for your code.
Generating documentation
~~~~~~~~~~~~~~~~~~~~~~~~

To install necessary packages to compile the documentation, run::

pip install -r requirements_docs.txt

After that, you can compile the documentation and open it locally in your browser::
You can compile the documentation and open it locally in your browser::

cd docs
make html
$BROWSER _build/html/index.html
sphinx docs/ generated_docs
$BROWSER generated_docs/index.html

Replace `$BROWSER` with your preferred browser if the environment variable is not set.
Replace `$BROWSER` with your preferred browser, if the environment variable is not set.

Adding support for new devices
------------------------------
Expand Down
3 changes: 3 additions & 0 deletions miio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# flake8: noqa
from importlib_metadata import version # type: ignore
from miio.airconditioningcompanion import (
AirConditioningCompanion,
AirConditioningCompanionV3,
Expand Down Expand Up @@ -47,3 +48,5 @@
from miio.yeelight import Yeelight

from miio.discovery import Discovery

__version__ = version("python-miio")
2 changes: 1 addition & 1 deletion miio/tests/test_airconditioningcompanion.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@
"out": "0100002573120016A1"
}
]
}
}
2 changes: 1 addition & 1 deletion miio/tests/test_chuangmi_ir.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@
]
}
]
}
}
24 changes: 12 additions & 12 deletions miio/tests/test_toiletlid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
"""Unit tests for toilet lid.
Response instance
>> status
Work: False
State: 1
Ambient Light: Yellow
Filter remaining: 100%
Filter remaining time: 180
"""
from unittest import TestCase

import pytest
Expand All @@ -12,18 +24,6 @@
from .dummies import DummyDevice


"""
Response instance
>> status
Work: False
State: 1
Ambient Light: Yellow
Filter remaining: 100%
Filter remaining time: 180
"""


class DummyToiletlidV1(DummyDevice, Toiletlid):
def __init__(self, *args, **kwargs):
self.model = MODEL_TOILETLID_V1
Expand Down
Loading

0 comments on commit 7a27314

Please sign in to comment.