esphome icon indicating copy to clipboard operation
esphome copied to clipboard

[image] Remove dependency on libmagic

Open clydebarrow opened this issue 1 year ago • 3 comments

What does this implement/fix?

Use of libmagic is problematic on windows and requires native libraries installed on other host systems, and running the codeowners script requires it to be installed due to it being used by image. It's only used to detect an SVG file and in any case does so solely by searching for a string. This PR replicates that behaviour without bringing in a heavyweight external library.

Also change display from a dependency to an auto-load since image does not depend on having a display configured, only the header file available.

Types of changes

  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [x] Other

Related issue or feature (if applicable): fixes

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#<esphome-docs PR number goes here>

Test Environment

  • [x] ESP32
  • [ ] ESP32 IDF
  • [ ] ESP8266
  • [ ] RP2040
  • [ ] BK72xx
  • [ ] RTL87xx
  • [ ] host

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • [x] The code change is tested and works locally.
  • [x] Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

clydebarrow avatar Aug 28 '24 03:08 clydebarrow

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 53.96%. Comparing base (4d8b5ed) to head (7042e3a). Report is 1311 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #7365      +/-   ##
==========================================
+ Coverage   53.70%   53.96%   +0.25%     
==========================================
  Files          50       50              
  Lines        9408     9670     +262     
  Branches     1654     1707      +53     
==========================================
+ Hits         5053     5218     +165     
- Misses       4056     4128      +72     
- Partials      299      324      +25     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Aug 28 '24 03:08 codecov-commenter

Did you intended to push 2 changes in this PR :D

nielsnl68 avatar Aug 28 '24 08:08 nielsnl68

Did you intended to push 2 changes in this PR

Yes, without those it fails CI.

clydebarrow avatar Aug 28 '24 09:08 clydebarrow

@clydebarrow can you add issue 5896 to the "fixes" line in the description? As far as I can see, that issue is exactly what you are trying to fix here

guillempages avatar Sep 01 '24 14:09 guillempages

IMHO the invert_colors changes on the tests belong in a separate PR... They are unrelated to this change, but to the one that made it mandatory

guillempages avatar Sep 01 '24 14:09 guillempages

IMHO the invert_colors changes on the tests belong in a separate PR

True, but without those (actually now only one) this PR won't pass CI. I'm not going to raise a separate PR to change a single line, sorry Jesse, but I'm drawing a line here :-)

clydebarrow avatar Sep 01 '24 21:09 clydebarrow

True, but without those (actually now only one) this PR won't pass CI. I'm not going to raise a separate PR to change a single line, sorry Jesse, but I'm drawing a line here :-)

Your PR is adding invert_colors to the spi config :thinking: It already exists on the display for this test...

And its not failing becuase the 8266 commmon file is not used anywhere :see_no_evil:

2024-09-02_15-56-42

jesserockz avatar Sep 02 '24 03:09 jesserockz

Another alternative is https://pypi.org/project/puremagic/ Especially if other file types are added and need to be identified before some code runs in the future.

jesserockz avatar Sep 03 '24 00:09 jesserockz

Another alternative is https://pypi.org/project/puremagic/ Especially if other file types are added and need to be identified before some code runs in the future.

I like this option! I want to determine the type of an audio file (wav, flac, or mp3), and I'm currently using libmagic for it. Puremagic is pretty much a straight drop in replacement.

kahrendt avatar Sep 11 '24 13:09 kahrendt

Since there seems to be no movement here, I've implemented the "puremagic" version in #7536. So probably only one of the two PRs should be merged, since they address the same issue in two different ways

guillempages avatar Oct 03 '24 19:10 guillempages