コード例 #1
0
def test_freezer_mpy_manifest(mpy_version: str, tmp_path: Path,
                              testrepo_micropython: Path,
                              testrepo_micropython_lib: Path):
    "test if we can freeze source using manifest.py files"
    # mpy_path = Path(testrepo_micropython)
    # mpy_lib = Path(testrepo_micropython_lib)
    mpy_path = testrepo_micropython.as_posix()
    mpy_lib = testrepo_micropython_lib.as_posix()

    version = git.get_tag(mpy_path)
    if not version or version < mpy_version:
        git.checkout_tag(mpy_version, mpy_path)
        version = git.get_tag(mpy_path)
        assert version == mpy_version, "prep: could not checkout version {} of {}".format(
            mpy_version, mpy_path)

    get_mpy.get_frozen(str(tmp_path),
                       version=mpy_version,
                       mpy_path=mpy_path,
                       lib_path=mpy_lib)
    scripts = list(tmp_path.rglob("*.py"))

    assert scripts is not None, "can freeze scripts from manifest"
    assert len(scripts) > 10, "expect at least 50 files, only found {}".format(
        len(scripts))
コード例 #2
0
def test_freezer_mpy_manifest(tmp_path, testrepo_micropython,
                              testrepo_micropython_lib):
    "test if we can freeze source using manifest.py files"
    # mpy_path = Path(testrepo_micropython)
    # mpy_lib = Path(testrepo_micropython_lib)
    mpy_path = testrepo_micropython
    mpy_lib = testrepo_micropython_lib
    # mpy version must be at 1.12 or newer
    mpy_version = 'v1.12'

    version = git.get_tag(mpy_path)
    if version < mpy_version:
        git.checkout_tag(mpy_version, mpy_path)
        version = git.get_tag(mpy_path)
        assert version == mpy_version, "prep: could not checkout version {} of {}".format(
            mpy_version, mpy_path)

    stub_path = Path(tmp_path)
    get_mpy.get_frozen(str(stub_path),
                       version=mpy_version,
                       mpy_path=mpy_path,
                       lib_path=mpy_lib)
    scripts = list(stub_path.rglob('*.py'))

    assert scripts is not None, "can freeze scripts from manifest"
    assert len(scripts) > 10, "expect at least 50 files, only found {}".format(
        len(scripts))
コード例 #3
0
def test_get_mpy(tmp_path):

    # Use Submodules
    mpy_path = "./micropython"
    lib_path = "./micropython-lib"
    try:
        version = clean_version(git.get_tag(mpy_path) or "0.0")
    except Exception:
        warnings.warn("Could not find the micropython version Tag - assuming v1.x")
        version = "v1.x"

    assert version, "could not find micropython version"
    print("found micropython version : {}".format(version))
    # folder/{family}-{version}-frozen
    family = "micropython"
    stub_path = "{}-{}-frozen".format(family, clean_version(version, flat=True))
    get_mpy.get_frozen(str(tmp_path / stub_path), version=version, mpy_path=mpy_path, lib_path=lib_path)

    modules_count = len(list((tmp_path / stub_path).glob("**/modules.json")))
    stub_count = len(list((tmp_path / stub_path).glob("**/*.py")))
    if version == "v1.x":
        assert modules_count >= 4, "there should at least 4 module manifests"
        assert stub_count >= 10, "there should > 10 frozen modules"

    elif version >= "v1.15":
        assert modules_count >= 7, "there should at least 7 module manifests"
        assert stub_count >= 100, "there should > 100 frozen modules"
コード例 #4
0
def get_all():
    "get all frozen modules for the current version of micropython"
    
    #
    get_cpython.get_core(stub_path=stubfolder('cpython_core'), requirements='./src/reqs-cpython-mpy.txt')

    mpy_path = '../micropython'
    version = clean_version(git.get_tag(mpy_path))

    if version:
        log.info("found micropython version : {}".format(version))
        # folder/{family}-{version}-frozen
        family = 'micropython'
        stub_path = stubfolder('{}-{}-frozen'.format(family, flat_version(version)))
        get_mpy.get_frozen(stub_path, version=version, mpy_path=mpy_path, lib_path='../micropython-lib')
    else:
        log.warning('Unable to find the micropython repo in folder : {}'.format(mpy_path))

    get_lobo.get_frozen(stub_path=STUB_FOLDER + '/loboris-esp32_lobo_3_2_24' + '-frozen')

    # now generate typeshed files for all scripts
    log.info("Generate type hint files (pyi) in folder: {}".format(STUB_FOLDER))
    utils.make_stub_files(STUB_FOLDER, levels=7)
コード例 #5
0
def get_all(
    stub_folder: str = STUB_FOLDER,
    mpy_folder: str = MPY_FOLDER,
    mpy_lib_folder: str = MPY_LIB_FOLDER,
    version: str = "",
    core: bool = False,
    core_type: str = "pycopy",  # pycopy or Micropython CPython stubs
    mpy: bool = False,
    lobo: bool = False,
    pyi: bool = True,
    black: bool = True,
    all: bool = False,
):
    "get all frozen modules for the current version of micropython"
    if not (core or mpy or lobo or all):
        log.warning("Nothing to do")
        exit(2)

    stub_paths: List[Path] = []
    if core or all:
        for core_type in ["pycopy", "micropython"]:
            log.info(f"::group:: Get Cpython core :{core_type}")
            req_filename = f"requirements-core-{core_type}.txt"
            stub_path = Path(stub_folder) / f"cpython_core-{core_type}"

            get_cpython.get_core(stub_path=str(stub_path),
                                 requirements=req_filename,
                                 family=core_type)
            stub_paths.append(stub_path)

    if len(version) == 0:
        version = utils.clean_version(git.get_tag(mpy_folder) or "0.0")
    if mpy or all:
        if version:
            log.info("MicroPython version : {}".format(version))
            # folder/{family}-{version}-frozen
            family = "micropython"
            stub_path = Path(
                stub_folder
            ) / f"{family}-{utils.clean_version(version, flat=True)}-frozen"
            stub_paths.append(stub_path)
            get_mpy.get_frozen(str(stub_path),
                               version=version,
                               mpy_path=mpy_folder,
                               lib_path=mpy_lib_folder)

        else:
            log.warning(
                "Unable to find the micropython repo in folder : {}".format(
                    mpy_folder))
    if lobo or all:
        family = "loboris"
        version = "v3.2.24"
        stub_path = Path(
            stub_folder
        ) / f"{family}-{utils.clean_version(version, flat=True)}-frozen"
        stub_paths.append(stub_path)
        get_lobo.get_frozen(str(stub_path))

    for pth in stub_paths:
        if pyi:
            log.info(
                "Generate type hint files (pyi) in folder: {}".format(pth))
            utils.generate_pyi_files(pth)
        if black:
            try:
                cmd = ["black", str(pth), "--include", "\\.py$"]

                if sys.version_info.major == 3 and sys.version_info.minor == 7:
                    # black on python 3.7 does not like some function defs
                    # def sizeof(struct, layout_type=NATIVE, /) -> int:
                    cmd += ["--fast"]
                # shell=false on ubuntu
                result = subprocess.run(cmd,
                                        capture_output=False,
                                        check=True,
                                        shell=False)
                if result.returncode != 0:
                    raise Exception(result.stderr.decode("utf-8"))
            except subprocess.SubprocessError:
                log.error("some of the files are not in a proper format")