From 741308c93f115acd84e8350af0f02cc947e65fec Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 19 Oct 2023 14:00:36 -1000 Subject: [PATCH] Add basic pre-commit to handle eol space (#592) --- .github/workflows/ci.yml | 8 ++++---- .github/workflows/matchers/pytest.json | 3 +-- .github/workflows/release.yml | 2 +- .pre-commit-config.yaml | 9 +++++++++ LICENSE | 2 +- MAINTAINERS.md | 1 - README.rst | 20 ++++++++++---------- aioesphomeapi/_frame_helper/base.pxd | 2 +- aioesphomeapi/_frame_helper/noise.pxd | 6 +++--- aioesphomeapi/_frame_helper/plain_text.pxd | 4 ++-- aioesphomeapi/connection.pxd | 2 +- pyproject.toml | 1 - 12 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ddc9ed..0065930 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,12 +24,12 @@ jobs: - "3.9" - "3.10" - "3.11" - - "3.12" + - "3.12" os: - - ubuntu-latest + - ubuntu-latest extension: - "skip_cython" - - "use_cython" + - "use_cython" steps: - uses: actions/checkout@v4 - name: Set up Python @@ -90,7 +90,7 @@ jobs: name: Run tests with pytest - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 - - run: | + - run: | docker run \ -v "$PWD":/aioesphomeapi \ ghcr.io/esphome/aioesphomeapi-proto-builder:latest diff --git a/.github/workflows/matchers/pytest.json b/.github/workflows/matchers/pytest.json index c087f3a..0eb8f05 100644 --- a/.github/workflows/matchers/pytest.json +++ b/.github/workflows/matchers/pytest.json @@ -14,7 +14,6 @@ "message": 1 } ] - } + } ] } - \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cb48a6e..a71d52e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -58,4 +58,4 @@ jobs: - uses: pypa/gh-action-pypi-publish@release/v1 with: - password: ${{ secrets.PYPI_TOKEN }} \ No newline at end of file + password: ${{ secrets.PYPI_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..596558e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files diff --git a/LICENSE b/LICENSE index 7db4cd5..fbd2dbb 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 1ab9aae..77e3b81 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -13,4 +13,3 @@ Before creating a release: Check the latest commit passes continuous integration When the release button on the draft is clicked, GitHub Actions will publish the release to PyPi. After any push to the main branch, the "protoc-update" workflow is run which updates the generated python protobuf files. This is to ensure that if a contributor has a newer protoc version installed than the protobuf python package, we won't run into any issues. - diff --git a/README.rst b/README.rst index 1c92317..f9561b4 100644 --- a/README.rst +++ b/README.rst @@ -43,25 +43,25 @@ The sample code below will connect to the device and retrieve details. import aioesphomeapi import asyncio - + async def main(): """Connect to an ESPHome device and get details.""" - # Establish connection + # Establish connection api = aioesphomeapi.APIClient("api_test.local", 6053, "MyPassword") await api.connect(login=True) - + # Get API version of the device's firmware print(api.api_version) - + # Show device details device_info = await api.device_info() print(device_info) - + # List all entities of the device entities = await api.list_entities_services() print(entities) - + loop = asyncio.get_event_loop() loop.run_until_complete(main()) @@ -71,20 +71,20 @@ Subscribe to state changes of an ESPHome device. import aioesphomeapi import asyncio - + async def main(): """Connect to an ESPHome device and wait for state changes.""" cli = aioesphomeapi.APIClient("api_test.local", 6053, "MyPassword") - + await cli.connect(login=True) def change_callback(state): """Print the state changes of the device..""" print(state) - + # Subscribe to the state changes await cli.subscribe_states(change_callback) - + loop = asyncio.get_event_loop() try: asyncio.ensure_future(main()) diff --git a/aioesphomeapi/_frame_helper/base.pxd b/aioesphomeapi/_frame_helper/base.pxd index 29559cb..96a2afb 100644 --- a/aioesphomeapi/_frame_helper/base.pxd +++ b/aioesphomeapi/_frame_helper/base.pxd @@ -25,4 +25,4 @@ cdef class APIFrameHelper: cdef _add_to_buffer(self, bytes data) @cython.locals(end_of_frame_pos=cython.uint) - cdef _remove_from_buffer(self) \ No newline at end of file + cdef _remove_from_buffer(self) diff --git a/aioesphomeapi/_frame_helper/noise.pxd b/aioesphomeapi/_frame_helper/noise.pxd index 0734c9c..eab40a9 100644 --- a/aioesphomeapi/_frame_helper/noise.pxd +++ b/aioesphomeapi/_frame_helper/noise.pxd @@ -19,10 +19,10 @@ cdef class APINoiseFrameHelper(APIFrameHelper): @cython.locals( header=bytes, - preamble=cython.uint, - msg_size_high=cython.uint, + preamble=cython.uint, + msg_size_high=cython.uint, msg_size_low=cython.uint, - ) + ) cpdef data_received(self, bytes data) @cython.locals( diff --git a/aioesphomeapi/_frame_helper/plain_text.pxd b/aioesphomeapi/_frame_helper/plain_text.pxd index 994804f..5175e5e 100644 --- a/aioesphomeapi/_frame_helper/plain_text.pxd +++ b/aioesphomeapi/_frame_helper/plain_text.pxd @@ -21,8 +21,8 @@ cdef class APIPlaintextFrameHelper(APIFrameHelper): add_length=bytes, end_of_frame_pos=cython.uint, length_int=cython.uint, - preamble=cython.uint, - length_high=cython.uint, + preamble=cython.uint, + length_high=cython.uint, maybe_msg_type=cython.uint ) cpdef data_received(self, bytes data) diff --git a/aioesphomeapi/connection.pxd b/aioesphomeapi/connection.pxd index 981f5e1..51d9cb1 100644 --- a/aioesphomeapi/connection.pxd +++ b/aioesphomeapi/connection.pxd @@ -88,4 +88,4 @@ cdef class APIConnection: cpdef add_message_callback(self, object on_message, tuple msg_types) @cython.locals(handlers=set) - cpdef _remove_message_callback(self, object on_message, tuple msg_types) \ No newline at end of file + cpdef _remove_message_callback(self, object on_message, tuple msg_types) diff --git a/pyproject.toml b/pyproject.toml index fe9b15c..f01be14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,4 +32,3 @@ disable = [ [build-system] requires = ['setuptools>=65.4.1', 'wheel', 'Cython>=3.0.2'] -