-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid using __file__ in places that matter
Assuming __file__ exists breaks packaging netaddr with PyOxidirzer[1]. Initially I wanted to use pkgutil.get_data()[2] as it's been in the Python standard library since Python 2.6 but it always reads and returns the whole resource and I decided I don't like reading whole out.txt and iab.txt in OUI and IAB constructors just to read few small bits of data. importlib.resources provides an API[3] that should in the usual cases cases[4] avoid loading whole resources into memory. Maybe IAB and OUI constructors shouldn't read files and the API needs to be rethought but that's an issue for another day. Granted, this is a tradeoff, as we have a dependency now which means slighly more network traffic and slightly more complexity, but all things considered I think that's better than the alternative. (Ironically this introduces a new piece of code using __file__ but this should be benign as it's not in the code that'll be present in a PyOxidizer-produced binary. It's necessary to have that setup.py hack as netaddr can't be imported without importlib_resources or importlib.resources present now so it can't be unconditionally imported from setup.py where importlib_resources may not be installed yet). Fixes GH-188. [1] indygreg/PyOxidizer#69 [2] https://docs.python.org/2/library/pkgutil.html#pkgutil.get_data [3] https://docs.python.org/3.9/library/importlib.html#importlib.resources.open_binary [4] https://gitlab.com/python-devs/importlib_resources/-/blob/2707fb7384e76cda715de14bea5956339969950f/importlib_resources/_py3.py#L24
- Loading branch information
Showing
7 changed files
with
49 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters