Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to pyproject.toml and centralized CI #147

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/release-drafter.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

# yamllint disable-line rule:truthy
on:
push:
pull_request: ~

jobs:
shared-ci:
uses: zigpy/workflows/.github/workflows/ci.yml@main
with:
CODE_FOLDER: zigpy_deconz
CACHE_VERSION: 2
PYTHON_VERSION_DEFAULT: 3.8.14
PRE_COMMIT_CACHE_PATH: ~/.cache/pre-commit
MINIMUM_COVERAGE_PERCENTAGE: 97
16 changes: 16 additions & 0 deletions .github/workflows/matchers/codespell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"problemMatcher": [
{
"owner": "codespell",
"severity": "warning",
"pattern": [
{
"regexp": "^(.+):(\\d+):\\s(.+)$",
"file": 1,
"line": 2,
"message": 3
}
]
}
]
}
30 changes: 30 additions & 0 deletions .github/workflows/matchers/flake8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"problemMatcher": [
{
"owner": "flake8-error",
"severity": "error",
"pattern": [
{
"regexp": "^(.*):(\\d+):(\\d+):\\s([EF]\\d{3}\\s.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
]
},
{
"owner": "flake8-warning",
"severity": "warning",
"pattern": [
{
"regexp": "^(.*):(\\d+):(\\d+):\\s([CDNW]\\d{3}\\s.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
]
}
]
}
18 changes: 18 additions & 0 deletions .github/workflows/matchers/python.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "python",
"pattern": [
{
"regexp": "^\\s*File\\s\\\"(.*)\\\",\\sline\\s(\\d+),\\sin\\s(.*)$",
"file": 1,
"line": 2
},
{
"regexp": "^\\s*raise\\s(.*)\\(\\'(.*)\\'\\)$",
"message": 2
}
]
}
]
}
39 changes: 9 additions & 30 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
name: Publish distributions to PyPI and TestPyPI
name: Publish distributions to PyPI

on:
push:
tags:
- "*"
release:
types:
- published

jobs:
build-and-publish:
name: Build and publish distributions to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
version: 3.8
- name: Install wheel
run: >-
pip install wheel
- name: Build
run: >-
python3 setup.py sdist
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_TOKEN }}
update_draft_release:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shared-build-and-publish:
uses: zigpy/workflows/.github/workflows/publish-to-pypi.yml@main
secrets:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
45 changes: 0 additions & 45 deletions .github/workflows/tests.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: debug-statements

- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
entry: pflake8
additional_dependencies:
- pyproject-flake8==6.1.0
- flake8-bugbear==23.1.20
- flake8-comprehensions==3.10.1
- flake8_2020==1.7.0
- mccabe==0.7.0
- pycodestyle==2.11.1
- pyflakes==3.1.0

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
hooks:
- id: mypy
additional_dependencies:
- zigpy
- types-setuptools

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade

- repo: https://github.com/fsouza/autoflake8
rev: v0.4.1
hooks:
- id: autoflake8
65 changes: 65 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[build-system]
requires = ["setuptools>=61.0.0", "wheel", "setuptools-git-versioning<2"]
build-backend = "setuptools.build_meta"

[project]
name = "zigpy-zigate"
dynamic = ["version"]
description = "A library which communicates with ZiGate radios for zigpy"
urls = {repository = "https://github.com/zigpy/zigpy-zigate"}
authors = [
{name = "Sébastien RAMAGE", email = "sebatien.ramage@gmail.com"}
]
readme = "README.md"
license = {text = "GPL-3.0"}
requires-python = ">=3.8"
dependencies = [
"voluptuous",
"zigpy>=0.60.0",
"pyusb>=1.1.0",
"gpiozero",
'async-timeout; python_version<"3.11"',
]

[tool.setuptools.packages.find]
exclude = ["tests", "tests.*"]

[project.optional-dependencies]
testing = [
"pytest>=7.1.2",
"pytest-asyncio>=0.19.0",
"pytest-timeout>=2.1.0",
"pytest-mock>=3.8.2",
"pytest-cov>=3.0.0",
]

[tool.setuptools-git-versioning]
enabled = true

[tool.isort]
profile = "black"
# will group `import x` and `from x import` of the same module.
force_sort_within_sections = true
known_first_party = ["zigpy_zigate", "tests"]
forced_separate = "tests"
combine_as_imports = true

[tool.mypy]
ignore_errors = true

[tool.pytest.ini_options]
asyncio_mode = "auto"

[tool.flake8]
exclude = [".venv", ".git", ".tox", "docs", "venv", "bin", "lib", "deps", "build"]
# To work with Black
max-line-length = 88
# W503: Line break occurred before a binary operator
# E203: Whitespace before ':'
# E501: line too long
# D202 No blank lines allowed after function docstring
ignore = [
"W503", "E203", "E501", "D202",
"D103", "D102", "D101", # TODO: remove these once docstrings are added
]
per-file-ignores = ["tests/*:F811,F401,F403"]
34 changes: 3 additions & 31 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
"""Setup module for zigpy-zigate"""
import setuptools

import pathlib

from setuptools import find_packages, setup
from zigpy_zigate import __version__

setup(
name="zigpy-zigate",
version=__version__,
description="A library which communicates with ZiGate radios for zigpy",
long_description=(pathlib.Path(__file__).parent / "README.md").read_text(),
long_description_content_type="text/markdown",
url="http://github.com/zigpy/zigpy-zigate",
author="Sébastien RAMAGE",
author_email="sebatien.ramage@gmail.com",
license="GPL-3.0",
packages=find_packages(exclude=['tests']),
install_requires=[
'pyserial>=3.5',
'pyserial-asyncio>=0.5; platform_system!="Windows"',
'pyserial-asyncio!=0.5; platform_system=="Windows"', # 0.5 broke writes
'pyusb>=1.1.0',
'zigpy>=0.51.0',
'gpiozero',
],
tests_require=[
'pytest',
'pytest-asyncio',
'mock'
],
)
if __name__ == "__main__":
setuptools.setup()
10 changes: 5 additions & 5 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import asyncio
import sys
from unittest.mock import AsyncMock, MagicMock, patch, sentinel

import pytest
import serial
import serial_asyncio
from unittest.mock import AsyncMock, MagicMock, patch, sentinel

from zigpy_zigate import api as zigate_api
import zigpy_zigate.config as config
import zigpy_zigate.uart
from zigpy_zigate import api as zigate_api

DEVICE_CONFIG = config.SCHEMA_DEVICE({config.CONF_DEVICE_PATH: "/dev/null"})



@pytest.fixture
def api():
api = zigate_api.ZiGate(DEVICE_CONFIG)
Expand Down Expand Up @@ -60,7 +59,7 @@ async def test_api_new(conn_mck):
@patch.object(zigate_api.ZiGate, "set_raw_mode", new_callable=AsyncMock)
@pytest.mark.parametrize(
"port",
('/dev/null', 'pizigate:/dev/ttyAMA0'),
("/dev/null", "pizigate:/dev/ttyAMA0"),
)
async def test_probe_success(mock_raw_mode, port, monkeypatch):
"""Test device probing."""
Expand All @@ -69,6 +68,7 @@ async def mock_conn(loop, protocol_factory, **kwargs):
protocol = protocol_factory()
loop.call_soon(protocol.connection_made, None)
return None, protocol

monkeypatch.setattr(serial_asyncio, "create_serial_connection", mock_conn)
DEVICE_CONFIG = zigpy_zigate.config.SCHEMA_DEVICE(
{zigpy_zigate.config.CONF_DEVICE_PATH: port}
Expand Down
Loading
Loading