adafruit / adafruit/Adafruit_CircuitPython_PortalBase

Thoughts on turning adafruit_bitmap_font / adafruit_fakerequests into a soft dependency?

Open
#55 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
17
Forks
21
PR merge metrics
No merged PRs in 30d

Description

It looks like adafruit_bitmap_font ([repo](https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font)) is used as a convenience function to `_load_font`:

https://github.com/adafruit/Adafruit_CircuitPython_PortalBase/blob/64ea98df0386f3a629b2135086ceeb9d956ce0dc/adafruit_portalbase/__init__.py#L112-L113

This could be turned into an inline import. For example:

```python
if font not in self._fonts:
from adafruit_bitmap_font import bitmap_font # <-- Inline import
self._fonts[font] = bitmap_font.load_font(font)
```

Turning this into an inline import would make this a soft dependency. If it's not used it's not required. I was working up a small demo on the MagTag but not using anything about the display or Wi-Fi. I noticed that I still needed quite a few libraries. Some of these, like adafruit_fakerequests, aren't used even if I was using the full capabilities on the device. For example, this line could also use an inline import:

https://github.com/adafruit/Adafruit_CircuitPython_PortalBase/blob/64ea98df0386f3a629b2135086ceeb9d956ce0dc/adafruit_portalbase/network.py#L470

Making these inline imports would reduce the number of hard dependencies here. This would also provide some space savings and improve the speed at which the code starts up. This also shouldn't functionally impact any existing example code which makes use of functions requiring these libraries. They would still require the library to be installed.

Is this worth submitting a PR for?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in adafruit_portalbase/__init__.py at _load_font and in adafruit_portalbase/network.py around the referenced line. Review how adafruit_bitmap_font and adafruit_fakerequests are imported and used, then check the existing examples that depend on these functions. Done means the dependencies are loaded only when their functionality is used without changing existing example behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.