scientifichackers / ampy

MicroPython Tool - Utility to interact with a MicroPython board over a serial connection.
MIT License
723 stars 157 forks source link

import binascii if ubinascii not found #111

Open jerryneedell opened 2 years ago

jerryneedell commented 2 years ago

addresses #110 Circuitpython now uses binascii so the "get" command fails trying to import ubinascii. This PR adds a try/except to import binascii as ubinascii if ubinascii is not present.

cameronbunce commented 2 years ago

I have no authority here, but issue #110 is something that has been annoying in ampy for some time. I have implemented the above fix locally and confirm that it works and is non-breaking for micropython devices as well. I would like to see this merged.

wyattearp commented 1 year ago

For what it's worth, I tested this on an HUZZAH32 V2 running:

I was unable to make this work, it appears that the left over item is now:

# files.py
    def get(self, filename):
        """Retrieve the contents of the specified file and return its contents
        as a byte string.
        """
        # Open the file and read it a few bytes at a time and print out the
        # raw bytes.  Be careful not to overload the UART buffer so only write
        # a few bytes at a time, and don't use print since it adds newlines and
        # expects string data.
        command = """
            import sys
            import binascii
            with open('{0}', 'rb') as infile:
                while True:
                    result = infile.read({1})
                    if result == b'':
                        break
                    # len = sys.stdout.write(ubinascii.hexlify(result))
                    # use actual binascii
                    len = sys.stdout.write(binascii.hexlify(result))

The above patch correct it for me, which I assume is just a missed merge between your changes and the circuit python project.