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))
def test_checkout_sibling(testrepo_micropython):
    repo_path = testrepo_micropython
    x = git.get_tag(repo_path)

    for ver in ['v1.11', 'v1.9.4', 'v1.12']:
        git.checkout_tag(ver, repo=repo_path)
        assert git.get_tag(repo_path) == ver

    git.checkout_tag(x, repo=repo_path)
    assert git.get_tag(repo_path) == x, "can restore to prior version"
def test_get_tag_current():
    if not os.path.exists(".git"):
        pytest.skip("no git repo in current folder")
    else:
        # get tag of current repro
        tag = git.get_tag()
        common_tst(tag)
Esempio n. 4
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"
def test_get_tag_submodule(testrepo_micropython: Path):
    # get version of submodule repro
    for testcase in [
        testrepo_micropython.as_posix(),
        str(testrepo_micropython),
        ".\\micropython",
    ]:
        tag = git.get_tag(testcase)
        common_tst(tag)
def test_get_tag_latest():
    repo = Path("./micropython")
    if not (repo / ".git").exists():
        pytest.skip("no git repo in current folder")

    result = subprocess.run(["git", "switch", "main", "--force"], capture_output=True, check=True, cwd=repo.as_posix())

    assert result.stderr == 0
    # get tag of current repro
    tag = git.get_tag("./micropython")
    assert tag == "latest"
def test_freezer_mpy_folders(tmp_path, testrepo_micropython):
    "test if we can freeze source using modules folders"
    mpy_path = testrepo_micropython

    # mpy version must be older than 1.12 ( so use 1.10)
    mpy_version = 'v1.10'
    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 ../micropython".format(
            mpy_version)

    stub_path = tmp_path
    # freezer_mpy.get_frozen(stub_path, mpy_path, lib_path='../micropython-lib')
    get_mpy.get_frozen_folders(stub_path,
                               mpy_path,
                               lib_path='../micropython-lib',
                               version=mpy_version)
    assert True
Esempio n. 8
0
def test_freezer_mpy_folders(mpy_version, tmp_path, testrepo_micropython: Path,
                             testrepo_micropython_lib: Path):
    "test if we can freeze source using modules folders"
    mpy_path = testrepo_micropython.as_posix()

    version_x = 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 ./micropython".format(
            mpy_version)

    stub_path = tmp_path
    # freezer_mpy.get_frozen(stub_path, mpy_path, lib_path='./micropython-lib')
    get_mpy.get_frozen_folders(stub_path,
                               mpy_path,
                               lib_path=testrepo_micropython_lib.as_posix(),
                               version=mpy_version)
    # restore original version
    git.checkout_tag(version_x, mpy_path)  # type:ignore
    assert True
Esempio n. 9
0
def micropython_repo():
    "make sure a recent branch is checked out"
    git.switch_branch("master", MICROPYTHON_FOLDER)
    if TEST_DOCFIX:
        # run test against the proposed documentation fixes
        try:
            git.switch_branch("fix_lib_documentation", MICROPYTHON_FOLDER)
        except Exception:
            # git.switch_branch("master", MICROPYTHON_FOLDER)
            git.checkout_commit("micropython/master")

    v_tag = git.get_tag(MICROPYTHON_FOLDER) or "xx_x"
    yield v_tag
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)
Esempio n. 11
0
        # make a module manifest
        utils.make_manifest(Path(makemanifest.stub_dir),
                            FAMILY,
                            port=port_name,
                            board=board_name,
                            version=version,
                            stubtype="frozen")


if __name__ == "__main__":
    "just gather for the current version"
    logging.basicConfig(format="%(levelname)-8s:%(message)s",
                        level=logging.INFO)
    mpy_path = "./micropython"
    lib_path = "./micropython-lib"
    version = utils.clean_version(git.get_tag(mpy_path) or "0.0")

    if version:
        log.info("found micropython version : {}".format(version))
        # folder/{family}_{version}_frozen
        stub_path = utils.stubfolder("{}-{}-frozen".format(
            FAMILY, utils.clean_version(version, flat=True)))
        get_frozen(stub_path,
                   version=version,
                   mpy_path=mpy_path,
                   lib_path=lib_path)
        exit(0)
    else:
        log.warning(
            "Unable to find the micropython repo in folder : {}".format(
                mpy_path))
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")
Esempio n. 13
0
def test_get_failure_throws():
    with pytest.raises(Exception):
        git.get_tag(".not")
Esempio n. 14
0
    # get_frozen_folders(stub_path='./scratch/mpy_1_13_0_Frozen', mpy_path='../micropython', lib_path='../micropython-lib')

    #get_frozen(stub_path='./scratch/mpy_1_13_0_Frozen', mpy_path='../micropython', lib_path='../micropython-lib',version='1.13.0')
    get_frozen(stub_path='./scratch/mpy_1_10_0_Frozen',
               mpy_path='../micropython',
               lib_path='../micropython-lib',
               version='1.10.0')


if __name__ == "__main__":
    "just gather for the current version"
    logging.basicConfig(format='%(levelname)-8s:%(message)s',
                        level=logging.INFO)
    mpy_path = '../micropython'
    lib_path = '../micropython-lib'
    version = clean_version(git.get_tag(mpy_path))

    if version:
        log.info("found micropython version : {}".format(version))
        # folder/{family}_{version}_frozen
        family = 'mpy'
        stub_path = stubfolder('{}_{}_frozen'.format(family,
                                                     flat_version(version)))
        get_frozen(stub_path,
                   version=version,
                   mpy_path=mpy_path,
                   lib_path=lib_path)
        exit(0)
    else:
        log.warning(
            'Unable to find the micropython repo in folder : {}'.format(
def test_get_tag_sibling():
    # get version of sibling repro
    for testcase in ['../micropython', '..\\micropython']:
        tag = git.get_tag(testcase)
        common_tst(tag)