def get_frozen_folders(stub_path: str, mpy_path: str, lib_path: str, version: str): """ get and parse the to-be-fozen .py modules for micropython to extract the static type information - locates the to-be-frozen files in modules folders ports/<port>/modules/*.py ports/<port>/boards/<board>/modules/*.py """ targets = [] scripts = glob.glob(mpy_path + '/ports/**/modules/*.py', recursive=True) for script in scripts: mpy_port, mpy_board = get_target_names(script) if not mpy_board: mpy_board = "GENERIC" dest_path = os.path.join(stub_path, mpy_port, mpy_board) log.info("freezedry : {:<30} to {}".format(script, dest_path)) # ensure folder, including possible path prefix for script todo: os.makedirs(dest_path, exist_ok=True) # copy file shutil.copy2(script, dest_path) if not dest_path in targets: targets.append(dest_path) for dest_path in targets: # make a module manifest port = dest_path.split(os.path.sep)[-2] #todo: add board / variant into manifest files ? utils.make_manifest(dest_path, family=family, port=port, fmly=fmly, version=version)
def get_frozen_folders(stub_path: str, mpy_path: str, lib_path: str, version: str): """ get and parse the to-be-frozen .py modules for micropython to extract the static type information locates the to-be-frozen files in modules folders - 'ports/<port>/modules/*.py' - 'ports/<port>/boards/<board>/modules/*.py' """ micropython_lib_commits = read_micropython_lib_commits() # Make sure that the correct micropython-lib release is checked out log.info( f"Matching repo's: Micropython {version} needs micropython-lib:{micropython_lib_commits[version]}" ) git.checkout_commit(micropython_lib_commits[version], lib_path) targets = [] scripts = glob.glob(mpy_path + "/ports/**/modules/*.py", recursive=True) if len(scripts) > 0: # clean target folder shutil.rmtree(stub_path, ignore_errors=True) for script in scripts: mpy_port, mpy_board = get_target_names(script) if not mpy_board: mpy_board = "GENERIC" dest_path = os.path.join(stub_path, mpy_port, mpy_board) log.info("freeze_internal : {:<30} to {}".format(script, dest_path)) # ensure folder, including possible path prefix for script os.makedirs(dest_path, exist_ok=True) # copy file try: shutil.copy2(script, dest_path) if not dest_path in targets: targets.append(dest_path) except OSError as e: ## Ignore errors that are caused by reorganisation of Micropython-lib # print(e) warnings.warn("unable to freeze {} due to error {}".format( e.filename, str(e))) for dest_path in targets: # make a module manifest port = dest_path.split(os.path.sep)[-2] # todo: add board / variant into manifest files ? utils.make_manifest( Path(dest_path), family=FAMILY, port=port, version=version, stubtype="frozen", ) return targets
def get_frozen(stub_path=None, *, repo=None, version='3.2.24'): "Loboris frozen modules" if not stub_path: stub_path = Path('./all-stubs') / "{}-{}-frozen".format(FAMILY, utils.flat_version(version) ) else: stub_path = Path(stub_path) if not repo: repo = 'https://raw.githubusercontent.com/loboris/MicroPython_ESP32_psRAM_LoBo/master/MicroPython_BUILD/components/micropython/esp32/modules/{}' frozen_modules = ["README.md", "ak8963.py", "freesans20.py", "functools.py", "logging.py", "microWebSocket.py", "microWebSrv.py", "microWebTemplate.py", "mpu6500.py", "mpu9250.py", "pye.py", "ssd1306.py", "tpcalib.py", "upip.py", "upip_utarfile.py", "upysh.py", "urequests.py", "writer.py"] #download downloader.download_files(repo, frozen_modules, stub_path) # make a manifest utils.make_manifest(stub_path, FAMILY, "frozen", version=version)
def get_frozen_from_manifest( manifests, stub_path: str, mpy_path: str, lib_path: str, version: str, ): """ get and parse the to-be-frozen .py modules for micropython to extract the static type information locates the to-be-frozen files through the manifest.py introduced in MicroPython 1.12 - manifest.py is used for board specific and daily builds - manifest_release.py is used for the release builds """ stub_path = os.path.abspath(stub_path) makemanifest.path_vars["MPY_DIR"] = mpy_path makemanifest.path_vars["MPY_LIB_DIR"] = lib_path # https://regexr.com/4rh39 # but with an extra P for Python named groups... regex_port = r"(?P<port>.*[\\/]+ports[\\/]+\w+)[\\/]+boards[\\/]+\w+" # port regex_port_board = r"(?P<board>(?P<port>.*[\\/]+ports[\\/]+\w+)[\\/]+boards[\\/]+\w+)" # port & board # todo: variants # regex_3 = r"(?P<board>(?P<port>.*[\\/]+ports[\\/]+\w+)[\\/]+variants[\\/]+\w+)" # port & variant # matches= re.search(regex, 'C:\\develop\\MyPython\\micropython\\ports\\esp32\\boards\\TINYPICO\\manifest.py') # print( matches.group('port'), matches.group('board')) micropython_lib_commits = read_micropython_lib_commits() # Make sure that the correct micropython-lib release is checked out log.info( f"Matching repo's: Micropython {version} needs micropython-lib:{micropython_lib_commits[version]}" ) git.checkout_commit(micropython_lib_commits[version], lib_path) # Include top-level inputs, to generate the manifest for manifest in manifests: log.info("Manifest: {}".format(manifest)) makemanifest.path_vars["PORT_DIR"] = "" makemanifest.path_vars["BOARD_DIR"] = "" # check BOARD AND PORT pattern matches = re.search(regex_port_board, manifest) if matches: # port and board makemanifest.path_vars["PORT_DIR"] = matches.group("port") or "" makemanifest.path_vars["BOARD_DIR"] = matches.group("board") or "" if os.path.basename(matches.group("board")) == "manifest": makemanifest.path_vars["BOARD_DIR"] = "" else: # TODO: Variants matches = re.search(regex_port_board, manifest) # BOARD AND VARIANT if matches: # port and variant makemanifest.path_vars["PORT_DIR"] = matches.group( "port") or "" makemanifest.path_vars["BOARD_DIR"] = matches.group( "board") or "" if os.path.basename(matches.group("board")) == "manifest": makemanifest.path_vars["BOARD_DIR"] = "" else: # just port matches = re.search(regex_port, manifest) if matches: makemanifest.path_vars["PORT_DIR"] = matches.group( "port") or "" port_name = os.path.basename(makemanifest.path_vars["PORT_DIR"]) board_name = os.path.basename(makemanifest.path_vars["BOARD_DIR"]) if board_name == "": board_name = "GENERIC" if board_name == "manifest_release": board_name = "RELEASE" # set global for later use - must be an absolute path. freeze_path = (Path(stub_path) / port_name / board_name).absolute() makemanifest.stub_dir = freeze_path.as_posix() # clean target folder shutil.rmtree(freeze_path, ignore_errors=True) try: makemanifest.include(manifest) except makemanifest.FreezeError as er: log.error('freeze error executing "{}": {}'.format( manifest, er.args[0])) # make a module manifest utils.make_manifest(Path(makemanifest.stub_dir), FAMILY, port=port_name, board=board_name, version=version, stubtype="frozen")
def get_frozen_manifest(manifests, stub_path: str, mpy_path: str, lib_path: str, version: str): """ get and parse the to-be-fozen .py modules for micropython to extract the static type information - locates the to-be-frozen files through the manifest.py introduced in MicroPython 1.12 manifest.py is used for board specific and daily builds manifest_release.py is used for the release builds """ global path_vars # pylint: disable=global-statement global stub_dir # pylint: disable=global-statement stub_path = os.path.abspath(stub_path) path_vars['MPY_DIR'] = mpy_path path_vars['MPY_LIB_DIR'] = lib_path # https://regexr.com/4rh39 # but with an extry P for Python named groups... regex_1 = r"(?P<port>.*[\\/]+ports[\\/]+\w+)[\\/]+boards[\\/]+\w+" # port regex_2 = r"(?P<board>(?P<port>.*[\\/]+ports[\\/]+\w+)[\\/]+boards[\\/]+\w+)" # port & board # todo: variants regex_3 = r"(?P<board>(?P<port>.*[\\/]+ports[\\/]+\w+)[\\/]+variants[\\/]+\w+)" # port & variant # matches= re.search(regex, 'C:\\develop\\MyPython\\micropython\\ports\\esp32\\boards\\TINYPICO\\manifest.py') # print( matches.group('port'), matches.group('board')) # Include top-level inputs, to generate the manifest for manifest in manifests: log.info('Manifest: {}'.format(manifest)) path_vars['PORT_DIR'] = "" path_vars['BOARD_DIR'] = "" matches = re.search(regex_2, manifest) # BOARD AND PORT if matches: # port and board path_vars['PORT_DIR'] = matches.group('port') or "" path_vars['BOARD_DIR'] = matches.group('board') or "" if os.path.basename(matches.group('board')) == "manifest": path_vars['BOARD_DIR'] = "" else: # TODO: Variants matches = re.search(regex_2, manifest) # BOARD AND VARIANT if matches: # port and variant path_vars['PORT_DIR'] = matches.group('port') or "" path_vars['BOARD_DIR'] = matches.group('board') or "" if os.path.basename(matches.group('board')) == "manifest": path_vars['BOARD_DIR'] = "" else: #just port matches = re.search(regex_1, manifest) if matches: path_vars['PORT_DIR'] = matches.group('port') or "" port_name = os.path.basename(path_vars['PORT_DIR']) board_name = os.path.basename(path_vars['BOARD_DIR']) if board_name == "": board_name = "GENERIC" if board_name == "manifest_release": board_name = "RELEASE" # set global for later use - must be an absolute path. stub_dir = os.path.abspath( os.path.join(stub_path, port_name, board_name)) try: include(manifest) except FreezeError as er: log.error('freeze error executing "{}": {}'.format( manifest, er.args[0])) # make a module manifest utils.make_manifest(stub_dir, family, "frozen", fmly, version)