Skip to content

Commit 1bee1dc

Browse files
sfo2001claude
andcommitted
chore: modernize development infrastructure and build configuration
This commit modernizes the project's development infrastructure while maintaining backward compatibility. Rebased on top of PR1 (netifaces dependency fix). Key improvements: - Add PEP 621 [project] section to pyproject.toml for dual Poetry/standard packaging support - Enhance CI/CD workflow with improved Python 3.10-3.13 testing matrix and caching - Make tests optional in CI when tests directory doesn't exist (tests added in future PR) - Add comprehensive development tooling: pytest-asyncio, pytest-cov, mypy, pylint-protobuf - Improve pylint configuration with protobuf support and netifaces C extension handling - Add pytest configuration with asyncio mode and coverage reporting - Update Makefile with coverage reporting and enhanced pylint integration - Fix code quality issues: specific exception handling and black formatting - Update poetry.lock to include all dependencies (netifaces + new dev tools) All quality checks pass with 10.00/10 pylint score and proper black formatting. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7bcd5af commit 1bee1dc

File tree

5 files changed

+406
-38
lines changed

5 files changed

+406
-38
lines changed

.github/workflows/ci.yml

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,77 @@
11
name: CI
22

33
on:
4-
# Run action when pushed to master, or for commits in a pull request.
54
push:
6-
branches:
7-
- master
5+
branches: [main, master]
86
pull_request:
9-
branches:
10-
- master
7+
branches: [main, master]
118

129
defaults:
1310
run:
1411
shell: bash
1512

1613
jobs:
17-
checks:
18-
name: Code checks
19-
runs-on: ${{ matrix.os }}
14+
build-and-test:
15+
runs-on: ubuntu-latest
2016
strategy:
2117
fail-fast: false
2218
matrix:
23-
os: [ ubuntu-latest ]
2419
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
2520
steps:
26-
- name: Check out ${{ github.sha }} from repository ${{ github.repository }}
21+
- name: Check out code
2722
uses: actions/checkout@v4
2823

29-
- name: Install poetry
30-
run: pipx install poetry
24+
- name: Show GitHub context variables
25+
run: |
26+
echo "GITHUB_SHA: $GITHUB_SHA"
27+
echo "GITHUB_REPOSITORY: $GITHUB_REPOSITORY"
3128
3229
- name: Set up Python ${{ matrix.python-version }}
3330
uses: actions/setup-python@v5
3431
with:
3532
python-version: ${{ matrix.python-version }}
36-
cache: 'poetry'
33+
# ensure activation of poetry cache after poetry installation
3734

38-
- name: Install dependencies
39-
run: poetry install --no-interaction
35+
- name: Install Poetry
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install poetry
4039
41-
- name: Run checks
42-
run: make check
40+
- name: Configure Poetry
41+
run: |
42+
poetry config virtualenvs.create true
43+
poetry config virtualenvs.in-project true
44+
45+
- name: Cache Poetry dependencies
46+
uses: actions/cache@v4
47+
with:
48+
path: ~/.cache/pypoetry
49+
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
50+
restore-keys: |
51+
${{ runner.os }}-poetry-
52+
53+
- name: Install dependencies (with dev)
54+
run: poetry install --with dev --no-interaction
55+
56+
- name: Run code quality checks
57+
run: |
58+
echo "Running pylint..."
59+
make check-pylint
60+
echo "Running black format check..."
61+
make check-black
62+
63+
- name: Run tests with coverage (if tests exist)
64+
run: |
65+
if [ -d "tests" ] && find tests -name "test_*.py" | grep -q .; then
66+
echo "Running tests..."
67+
make test
68+
else
69+
echo "No test files found, skipping tests"
70+
fi
71+
72+
- name: Upload coverage to Codecov (optional)
73+
if: matrix.python-version == '3.12'
74+
uses: codecov/codecov-action@v4
75+
with:
76+
file: ./coverage.xml
77+
fail_ci_if_error: false

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
check: check-pylint check-black
22

33
check-pylint:
4-
@poetry run pylint aiocomfoconnect/*.py
4+
@poetry run pylint --load-plugins=pylint_protobuf aiocomfoconnect/*.py
55

66
check-black:
77
@poetry run black --check aiocomfoconnect/*.py
@@ -11,7 +11,7 @@ codefix:
1111
@poetry run black aiocomfoconnect/*.py
1212

1313
test:
14-
@poetry run pytest
14+
@poetry run pytest --cov=aiocomfoconnect --cov-report=term --cov-report=xml
1515

1616
build:
1717
docker build -t aiocomfoconnect .

aiocomfoconnect/discovery.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def connection_made(self, transport: asyncio.transports.DatagramTransport):
3838
# Determine broadcast address programmatically
3939
try:
4040
gws = netifaces.gateways()
41-
default_iface = gws['default'][netifaces.AF_INET][1]
41+
default_iface = gws["default"][netifaces.AF_INET][1]
4242
addrs = netifaces.ifaddresses(default_iface)
43-
broadcast_addr = addrs[netifaces.AF_INET][0].get('broadcast', '255.255.255.255')
44-
except Exception as e:
43+
broadcast_addr = addrs[netifaces.AF_INET][0].get("broadcast", "255.255.255.255")
44+
except (KeyError, ValueError, OSError) as e:
4545
_LOGGER.warning("Could not determine broadcast address, using 255.255.255.255: %s", e)
46-
broadcast_addr = '255.255.255.255'
46+
broadcast_addr = "255.255.255.255"
4747
_LOGGER.debug("Sending discovery request to broadcast:%d (%s)", Bridge.PORT, broadcast_addr)
4848
self.transport.sendto(b"\x0a\x00", (broadcast_addr, Bridge.PORT))
4949

@@ -60,7 +60,7 @@ def datagram_received(self, data: Union[bytes, str], addr: tuple[str | Any, int]
6060
parser.ParseFromString(data)
6161

6262
self._bridges.append(Bridge(host=parser.searchGatewayResponse.ipaddress, uuid=parser.searchGatewayResponse.uuid.hex()))
63-
except Exception as exc:
63+
except (ValueError, AttributeError, TypeError) as exc:
6464
_LOGGER.error("Failed to parse discovery response from %s: %s", addr, exc)
6565
return
6666

0 commit comments

Comments
 (0)