Пример #1
0
def _install_with_pip(specs: List[str], target_dir: str,
                      index_urls: List[str]):
    logger.info("Installing with pip: %s", specs)

    suitable_indexes = [url for url in index_urls if url != MP_ORG_INDEX]
    if not suitable_indexes:
        raise UserError("No suitable indexes for pip")

    index_args = ["--index-url", suitable_indexes.pop(0)]
    while suitable_indexes:
        index_args += ["--extra-index-url", suitable_indexes.pop(0)]
    if index_args == ["--index-url", "https://pypi.org/pypi"]:
        # for some reason, this form does not work for some versions of some packages
        # (eg. micropython-os below 0.4.4)
        index_args = []

    args = [
        "--no-input",
        "--disable-pip-version-check",
        "install",
        "--no-compile",
        "--upgrade",
        "--target",
        target_dir,
    ] + index_args

    pip_cmd = ([
        sys.executable,
        "-m",
        "pip",
    ] + args + specs)
    logger.debug("Calling pip: %s", shlex_join(pip_cmd))
    subprocess.check_call(pip_cmd)
Пример #2
0
def open_macosx_terminal(
    cmd: Union[str, Iterable[str]],
    app: Optional[str] = 'Terminal.app',
    wait: bool = True,
    with_tempfile: bool = False,
    tempfile_suffix: str = '.command',
    shebang: str = '#!/bin/sh',
) -> CompletedProcess:
    open_cmd = ['open']
    if wait:
        open_cmd.append('-W')
    if app:
        open_cmd.extend(('-a', app))
    if with_tempfile:
        with NamedTemporaryFile(suffix=tempfile_suffix, mode='w') as f:
            sprun(['chmod', '+x', f.name], check=True)
            if not isinstance(cmd, str):
                cmd = shlex_join(cmd)
                cmd = cast(str, cmd)
            f.write('%s\n%s\n' % (shebang, cmd))
            f.flush()
            open_cmd.append(f.name)
            return sprun(open_cmd, check=True)
    else:
        if isinstance(cmd, str):
            open_cmd.append(cmd)
        else:
            open_cmd.extend(cmd)
        return sprun(open_cmd, check=True)
Пример #3
0
def start_macosx_terminal(
    cmd: Union[str, Iterable[str]],
    app: str = 'Terminal.app',
    wait: bool = True,
    wait_event: Union[int, str,
                      AppleScriptWaitEvent] = AppleScriptWaitEvent.exists,
    with_tempfile: bool = False,
    tempfile_suffix: str = '.command',
    shebang: str = '#!/bin/sh',
) -> CompletedProcess:
    if not isinstance(cmd, str):
        cmd = shlex_join(cmd)
        cmd = cast(str, cmd)
    if wait:
        tpl_command = '''
tell application "{app}"
    activate
    set w to do script "{script}"
    repeat while w %s
        delay 0.1
    end repeat
end tell''' % _get_wait_for_str(wait_event)
    else:
        tpl_command = 'tell application "{app}" to do script "{script}"'
    if with_tempfile:
        with NamedTemporaryFile(suffix=tempfile_suffix, mode='w') as f:
            sprun(['chmod', '+x', f.name], check=True)
            f.write('%s\n%s\n' % (shebang, cmd))
            f.flush()
            command = tpl_command.format(app=app, script=f.name)
            return sprun(['osascript', '-e', command], check=True)
    else:
        command = tpl_command.format(app=app, script=cmd.replace('"', '\\"'))
        return sprun(['osascript', '-e', command], check=True)
Пример #4
0
def _copy_to_micropython_over_serial(source_dir: str, port: str,
                                     target_dir: str):
    assert target_dir.startswith("/")

    cmd = _get_rshell_command() + [
        "-p", port, "rsync", source_dir, "/pyboard" + target_dir
    ]
    logger.debug("Uploading with rsync: %s", shlex_join(cmd))
    subprocess.check_call(cmd)
Пример #5
0
def _install_with_pip(specs: List[str], target_dir: str,
                      index_urls: List[str]):
    logger.info("Installing with pip: %s", specs)

    suitable_indexes = [url for url in index_urls if url != MP_ORG_INDEX]
    if not suitable_indexes:
        raise UserError("No suitable indexes for pip")

    index_args = ["--index-url", suitable_indexes.pop(0)]
    while suitable_indexes:
        index_args += ["--extra-index-url", suitable_indexes.pop(0)]
    if index_args == ["--index-url", "https://pypi.org/pypi"]:
        # for some reason, this form does not work for some versions of some packages
        # (eg. micropython-os below 0.4.4)
        index_args = []

    args = [
        "--no-input",
        "--disable-pip-version-check",
        "install",
        "--upgrade",
        "--target",
        target_dir,
    ] + index_args

    pip_cmd = ([
        sys.executable,
        "-m",
        "pip",
    ] + args + specs)
    logger.debug("Calling pip: %s", shlex_join(pip_cmd))
    subprocess.check_call(pip_cmd)

    # delete files not required for MicroPython
    for root, dirs, files in os.walk(target_dir):
        for dir_name in dirs:
            if (dir_name.endswith(".dist-info")
                    or dir_name.endswith(".egg-info")
                    or dir_name == "__pycache__"):
                shutil.rmtree(os.path.join(root, dir_name))

        for file_name in files:
            if file_name.endswith(".pyc"):
                os.remove(os.path.join(root, file_name))