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

Update project and CI #221

Merged
merged 13 commits into from
Sep 26, 2023
Merged
4 changes: 1 addition & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ updates:
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: pip
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
24 changes: 21 additions & 3 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
name-template: '$RESOLVED_VERSION'
tag-template: '$RESOLVED_VERSION'
change-template: '- #$NUMBER - $TITLE (@$AUTHOR)'
categories:
- title: "⬆️ Dependencies"
- title: "⚠ Breaking Changes"
labels:
- 'breaking-change'
- title: '⬆️ Dependencies'
collapse-after: 1
labels:
- "dependencies"
- 'dependencies'
- 'ci'
template: |
## What's Changed
## Whats Changed

$CHANGES
version-resolver:
major:
labels:
- 'breaking-change'
minor:
labels:
- 'new-feature'
- 'new-provider'
- 'enhancement'
- 'refactor'
default: patch
23 changes: 23 additions & 0 deletions .github/workflows/pr-labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: PR Labels

# yamllint disable-line rule:truthy
on:
pull_request:
types:
- synchronize
- labeled
- unlabeled
branches:
- main

jobs:
pr_labels:
name: Verify
runs-on: ubuntu-latest
steps:
- name: 🏷 Verify PR has a valid label
uses: ludeeus/action-require-labels@1.0.0
with:
labels: >-
breaking-change, bugfix, refactor, new-feature, maintenance, ci, dependencies, new-provider
28 changes: 28 additions & 0 deletions .github/workflows/pre-commit-updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Pre-commit auto-update
on:
schedule:
- cron: '0 0 * * *'
jobs:
auto-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4.7.0
with:
python-version: '3.10'
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit autoupdate
run: pre-commit autoupdate
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-autoupdate
title: Auto-update pre-commit hooks
commit-message: Auto-update pre-commit hooks
body: |
Update versions of tools in pre-commit
configs to latest version
labels: dependencies
31 changes: 0 additions & 31 deletions .github/workflows/pythonpublish.yml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish releases

on:
release:
types: [published]

jobs:
build-and-publish-pypi:
name: Builds and publishes releases to PyPI
runs-on: ubuntu-latest
outputs:
version: ${{ steps.vars.outputs.tag }}
steps:
- uses: actions/checkout@v4.0.0
- name: Get tag
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Set up Python 3.10
uses: actions/setup-python@v4.7.0
with:
python-version: "3.10"
- name: Install build
run: >-
pip install build tomli tomli-w
- name: Set Python project version from tag
shell: python
run: |-
import tomli
import tomli_w

with open("pyproject.toml", "rb") as f:
pyproject = tomli.load(f)

pyproject["project"]["version"] = "${{ steps.vars.outputs.tag }}"

with open("pyproject.toml", "wb") as f:
tomli_w.dump(pyproject, f)
- name: Build
run: >-
python3 -m build
- name: Publish release to PyPI
uses: pypa/gh-action-pypi-publish@v1.8.10
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could directly switch to Trusted Publisher to improve security

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, can we do that in a follow up? I'm not sure how to do that with the libs org and I think the PYPI account linked is still from @balloob

23 changes: 8 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4.1.0
- name: Set up Python 3.8
- uses: actions/checkout@v4.0.0
- name: Set up Python 3.10
uses: actions/setup-python@v4.7.0
with:
python-version: 3.8
python-version: "3.10"
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Lint with flake8
run: |
flake8 aiohue tests
- name: Check formatting with black
run: |
black aiohue tests --check
- name: Run tests
run: |
pytest tests
run: pip install . .[test]
- name: Lint/test with pre-commit
run: pre-commit run --all-files
- name: Pytest
run: pytest tests
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.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: no-commit-to-branch
args:
- --branch=main
- id: debug-statements
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.284'
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
args:
- --safe
- --quiet
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
- id: codespell
args: []
exclude_types: [csv, json]
exclude: ^tests/fixtures/
additional_dependencies:
- tomli

# - repo: local
# hooks:
# - id: pylint
# name: pylint
# entry: script/run-in-env.sh pylint -j 0
# language: script
# types: [python]
# files: ^aiohue/.+\.py$

# - id: mypy
# name: mypy
# entry: script/run-in-env.sh mypy
# language: script
# types: [python]
# files: ^aiohue/.+\.py$
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
}
},
"python.formatting.provider": "black",
}
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ include README.md
include requirements.txt
include LICENSE
graft aiohue
recursive-exclude * *.py[co]
recursive-exclude * *.py[co]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Asynchronous library to control Philips Hue

Requires Python 3.8+ and uses asyncio and aiohttp.
Requires Python 3.10+ and uses asyncio and aiohttp.

For usage examples, see the examples folder.

Expand Down
16 changes: 5 additions & 11 deletions aiohue/discovery.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Various helper utility for Hue bridge discovery."""
from __future__ import annotations

import contextlib
from dataclasses import dataclass
from typing import List

from aiohttp import ClientConnectionError, ClientError, ClientSession

Expand Down Expand Up @@ -43,7 +43,7 @@ async def discover_bridge(

async def discover_nupnp(
websession: ClientSession | None = None,
) -> List[DiscoveredHueBridge]:
) -> list[DiscoveredHueBridge]:
"""Discover bridges via NUPNP."""
result = []
websession_provided = websession is not None
Expand All @@ -55,10 +55,8 @@ async def discover_nupnp(
host = item["internalipaddress"]
# the nupnp discovery might return items that are not in local network
# connect to each bridge to find out if it's alive.
try:
with contextlib.suppress(Exception):
result.append(await discover_bridge(host, websession))
except Exception: # noqa
pass
return result
except ClientError:
return result
Expand Down Expand Up @@ -86,9 +84,7 @@ async def is_hue_bridge(host: str, websession: ClientSession | None = None) -> s
# there are some emulator projects out there that emulate a Hue bridge
# in a sloppy way, ignore them.
# https://github.com/home-assistant-libs/aiohue/issues/134
raise ClientConnectionError(
"Invalid API response, not a real Hue bridge?"
)
raise ClientConnectionError("Invalid API response, not a real Hue bridge?")
return normalize_bridge_id(data["bridgeid"])
finally:
if not websession_provided:
Expand All @@ -103,9 +99,7 @@ async def is_v2_bridge(host: str, websession: ClientSession | None = None) -> bo
try:
# v2 api is https only and returns a 403 forbidden when no key provided
url = f"https://{host}/clip/v2/resource"
async with websession.get(
url, ssl=False, raise_for_status=False, timeout=30
) as res:
async with websession.get(url, ssl=False, raise_for_status=False, timeout=30) as res:
return res.status == 403
except Exception: # pylint: disable=broad-except
# all other status/exceptions means the bridge is not v2 or not reachable at this time
Expand Down
Loading