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

Add optional kasa-crypt dependency for speedups #464

Merged
merged 25 commits into from
Jun 30, 2023

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jun 16, 2023

If installed, use the optimized protocol encryption procedures implemented as a C extension by kasa-crypt (https://github.com/bdraco/kasa-crypt).

@bdraco
Copy link
Member Author

bdraco commented Jun 16, 2023

Still need to fix the string conversion in the lib as I forgot the null termination for the conversion

@codecov-commenter
Copy link

codecov-commenter commented Jun 16, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.21 🎉

Comparison is base (2d42ca3) 79.29% compared to head (b95a1e4) 79.50%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #464      +/-   ##
==========================================
+ Coverage   79.29%   79.50%   +0.21%     
==========================================
  Files          26       26              
  Lines        1946     1952       +6     
  Branches      598      598              
==========================================
+ Hits         1543     1552       +9     
+ Misses        362      359       -3     
  Partials       41       41              
Impacted Files Coverage Δ
kasa/protocol.py 86.25% <100.00%> (+0.65%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@bdraco
Copy link
Member Author

bdraco commented Jun 16, 2023

Had to be explicit about the length cython/cython#3189

@bdraco bdraco closed this Jun 16, 2023
@bdraco bdraco reopened this Jun 16, 2023
@bdraco bdraco marked this pull request as ready for review June 16, 2023 16:42
@bdraco bdraco closed this Jun 16, 2023
@bdraco bdraco reopened this Jun 16, 2023
@rytilahti
Copy link
Member

How about making this an optional dependency similar to what's done with the orjson support? That would keep the lib still usable even when binary wheels nor compiler is available on some odd platform.

@bdraco
Copy link
Member Author

bdraco commented Jun 17, 2023

The kasa-crypt lib will automatically fallback to pure-python if the cython version cannot be linked or is not loadable

The CI jobs verify it works both ways https://github.com/bdraco/kasa-crypt/actions/runs/5292093943 (skip_cython, use_cython)

@rytilahti
Copy link
Member

rytilahti commented Jun 18, 2023

Tbh, I would like to see the dependency being inversed as that will still keep working even if the kasa-crypt package installation fails (if that even is a possibility).

@bdraco
Copy link
Member Author

bdraco commented Jun 18, 2023

It shouldn't be possible for the package to fail installation more than any other pypi package as if anything goes wrong it will install the pure python version and skip the cython version.

Its the same logic used in dbus-fast, python-zeroconf, home-assistant-bluetooth, etc.

It will only raise on failure to build the cython version if REQUIRE_CYTHON is set in the env https://github.com/bdraco/kasa-crypt/blob/4d5a8e8b6c93672863db957ca507a96b4d3356be/build_ext.py#L47

Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Looks great, thanks! Would you mind adding a separate CI run for this? I suppose checking only against the newest python release would suffice.

@rytilahti rytilahti added the enhancement New feature or request label Jun 18, 2023
@bdraco
Copy link
Member Author

bdraco commented Jun 18, 2023

my if: isn't working as expected here. Have to go dig up the docs to see what I did wrong

@bdraco
Copy link
Member Author

bdraco commented Jun 18, 2023

That should do it. My github actions is a bit rusty so it took a few tries

@bdraco
Copy link
Member Author

bdraco commented Jun 18, 2023

that was way too much to get an conditional -> actions/runner#409 (comment)

actions/runner#409

Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Uhh, hah, I had thought it'd be much simpler and cleaner, so thanks for going the extra mile to make it work!

@bdraco I rewrote the description to make it clearer what was changed, and I'll prepare a release soon-ish. Do you happen to have some numbers to mention in the description and the release notes about the improvements this change provides?

@rytilahti rytilahti changed the title feat: use kasa-crypt for encrypt/decrypt Add optional kasa-crypt dependency for speedups Jun 19, 2023
@rytilahti rytilahti merged commit afd54d1 into python-kasa:master Jun 30, 2023
sdb9696 added a commit to sdb9696/python-kasa that referenced this pull request Jul 5, 2023
* Add optional kasa-crypt dependency for speedups (python-kasa#464)

If installed, use the optimized protocol encryption procedures implemented as a C extension by kasa-crypt (https://pypi.org/project/kasa-crypt/

* Add fixture for KP405 Smart Dimmer Plug (python-kasa#470)

* Add files via upload

* Add to KP405 to dimmers, update README

---------

Co-authored-by: Teemu Rytilahti <[email protected]>

* Add benchmarks for speedups (python-kasa#473)

* Add benchmarks for speedups

* Update README.md

* Update README.md

Co-authored-by: Teemu R. <[email protected]>

* relo

* Update README.md

* document benchmark

* Update README.md

---------

Co-authored-by: Teemu R. <[email protected]>

* Release 0.5.2 (python-kasa#475)

Besides some small improvements, this release:
* Adds optional dependency for for `orjson` and `kasa-crypt` to speed-up protocol handling by an order of magnitude.
* Drops Python 3.7 support as it is no longer maintained.

[Full Changelog](python-kasa/python-kasa@0.5.1...0.5.2)

* Merge

---------

Co-authored-by: J. Nick Koston <[email protected]>
Co-authored-by: xinud190 <[email protected]>
Co-authored-by: Teemu Rytilahti <[email protected]>
sdb9696 added a commit to sdb9696/python-kasa that referenced this pull request Jul 5, 2023
* Initial commit

* Update tests and some structure

* Update tests and discovery single logic

* Add more discovery tests

* pre-commit poetry black formatting

* Dev1 (#1)

* Initial commit

* Update tests and some structure

* Update tests and discovery single logic

* Add more discovery tests

* pre-commit poetry black formatting

* Latest changes from upstream

* Update comments

* Add changes from upstream2 (#5)

* Add optional kasa-crypt dependency for speedups (python-kasa#464)

If installed, use the optimized protocol encryption procedures implemented as a C extension by kasa-crypt (https://pypi.org/project/kasa-crypt/

* Add fixture for KP405 Smart Dimmer Plug (python-kasa#470)

* Add files via upload

* Add to KP405 to dimmers, update README

---------

Co-authored-by: Teemu Rytilahti <[email protected]>

* Add benchmarks for speedups (python-kasa#473)

* Add benchmarks for speedups

* Update README.md

* Update README.md

Co-authored-by: Teemu R. <[email protected]>

* relo

* Update README.md

* document benchmark

* Update README.md

---------

Co-authored-by: Teemu R. <[email protected]>

* Release 0.5.2 (python-kasa#475)

Besides some small improvements, this release:
* Adds optional dependency for for `orjson` and `kasa-crypt` to speed-up protocol handling by an order of magnitude.
* Drops Python 3.7 support as it is no longer maintained.

[Full Changelog](python-kasa/python-kasa@0.5.1...0.5.2)

* Merge

---------

Co-authored-by: J. Nick Koston <[email protected]>
Co-authored-by: xinud190 <[email protected]>
Co-authored-by: Teemu Rytilahti <[email protected]>

* get changes from upstream

* Move unauthenticated logic out of unauthenticated device

---------

Co-authored-by: J. Nick Koston <[email protected]>
Co-authored-by: xinud190 <[email protected]>
Co-authored-by: Teemu Rytilahti <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants