Git Product home page Git Product logo

Comments (3)

tannewt avatar tannewt commented on July 24, 2024

Whats the specific problem? Is it time.monotonic?

Is it possible to always do the monkey patch on import of blinka?

from adafruit_blinka.

cefn avatar cefn commented on July 24, 2024

Definitely an option, but tradeoffs.

Other than this monkey-patch, you don't have to import adafruit_blinka in your source at all, as it is seamlessly imported by the circuitpython-compatibility modules (digitalio etc.). You don't need to know when in the sequence to import it, and you can't really get it wrong.

However, once there is a need to monkey-patch, you need to be sure you have explicitly called on adafruit_blinka before any other imports might access monkey-patched modules. Waiting on import from a dependent library is likely too late in the sequence. So this issue will need to be documented fairly well and can't be implicit.

Once we are committed that it's not implicit and authors have to trigger the monkey-patch, we have the freedom to expose explicit and selective monkey-patching. This helps us avoid automatically and monolithically load all the compatibility implementations you aren't using the moment you use any adafruit_blinka at all. This could be critical given the very low memory ceilings on the target platforms.

For example we could advise something like...

from adafruit_blinka import compatibility
compatibility("time", "adafruit_register")
import time
import adafruit_register

As regards time, I needed time.monotonic() since utime.ticks_ms() and friends couldn't be cross-platform, and adafruit_gps needed struct_time. See https://github.com/cefn/Adafruit_Micropython_Blinka/blob/master/src/adafruit_blinka/agnostic/time.py for a quick hack which worked for adafruit_gps and for testing#await_true() at least.

from adafruit_blinka.

tannewt avatar tannewt commented on July 24, 2024

Your example looks reasonable to me. Monkey-patching is ok by me on an as-needed basis.

Thanks for the in-depth explanation.

from adafruit_blinka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.