Giter Club home page Giter Club logo

Comments (1)

Josverl avatar Josverl commented on June 25, 2024

working propotype

mpremote COM16 mount . get-port

"stubber: get-port"
import gc
import os
import sys

try:
    from collections import OrderedDict
except ImportError:
    from ucollections import OrderedDict  # type: ignore

info = OrderedDict(
    {
        "family": sys.implementation.name,
        "version": "",
        "port": "stm32" if sys.platform.startswith("pyb") else sys.platform,  # port: esp32 / win32 / linux / stm32
        "board": "GENERIC",
        "cpu": "",
        "build": "",
        "board_d": "",
    }
)
try:
    info["version"] = ".".join([str(n) for n in sys.implementation.version])
except AttributeError:
    pass
try:
    machine = sys.implementation._machine if "_machine" in dir(sys.implementation) else os.uname().machine
    info["board"] = machine.strip()
    info["cpu"] = machine.split("with")[1].strip()
except (AttributeError, IndexError):
    pass

gc.collect()
try:
    # look up the board name in the board_info.csv file
    with open("board_info.csv", "r") as f:
        b = info["board"]
        for line in f:
            descr_, board_ = line.split(",")[1].strip(), line.split(",")[0].strip()
            if board_ == b:
                info["board_d"] = board_
                info["board"] = descr_
                break
    info["board"] = info["board"].replace(" ", "_")
except (AttributeError, IndexError, OSError):
    pass
gc.collect()


try:
    info["build"] = sys.version.split(";")[1].strip().split(" ")[1].split("-")[1]
except (AttributeError, IndexError):
    pass

if info["version"] == "" and sys.platform not in ("unix", "win32"):
    try:
        u = os.uname()
        info["version"] = u.release
    except (IndexError, AttributeError, TypeError):
        pass

try:  # families
    from pycopy import const as _t  # type: ignore

    info["family"] = "pycopy"
    del _t
except (ImportError, KeyError):
    pass
try:  # families
    from pycom import FAT as _t  # type: ignore

    info["family"] = "pycom"
    del _t
except (ImportError, KeyError):
    pass

if info["family"] == "micropython":
    if (
        info["version"]
        and info["version"].endswith(".0")
        and info["version"] >= "1.10.0"  # versions from 1.10.0 to 1.20.0 do not have a micro .0
        and info["version"] <= "1.20.0"
    ):
        # drop the .0 for newer releases
        info["version"] = info["version"][:-2]

# output the info dict as a string with the OrderedDict() removed
print(str(info).replace("OrderedDict(", "").rstrip(")"))

from micropython-stubber.

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.