不想熬夜的猪 2021-06-10 22:46 采纳率: 0%
浏览 264

鸿蒙配置上的问题(prompt_toolkit)

根据Hispark的教程一路走下来,执行python build.py -h 指令时突然报了个缺少prompt_toolkit的module,后来用pip install prompt_toolkit 安装后再执行python build.py -h 指令,就发现上边的报错,后来打开了common.py也只是看到一句简单的导入,点不开看不到里边的信息。不知道是哪里的问题了(小白失声痛哭),附带common.py在代码段。希望有大神或者遇到相似问题的同志能指点迷津!

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import json
try:
    from queue import Queue
except ImportError:
    from Queue import Queue
from collections import defaultdict

from prompt_toolkit.styles import style_from_dict
from prompt_toolkit.token import Token
from prompt_toolkit.mouse_events import MouseEventTypes

from hb.common.utils import read_json_file


def get_style(style_type):
    if style_type == 'terminal':
        return style_from_dict({
            Token.Separator: '#6C6C6C',
            Token.QuestionMark: '#5F819D',
            Token.Selected: '',  # default
            Token.Pointer: '#FF9D00 bold',  # AWS orange
            Token.Instruction: '',  # default
            Token.Answer: '#FF9D00 bold',  # AWS orange
            Token.Question: 'bold',
        })
    if style_type == 'answer':
        return style_from_dict({
            Token.Separator: '#cc5454',
            Token.QuestionMark: '#E91E63 bold',
            Token.Selected: '#cc5454',  # default
            Token.Pointer: '#ed9164 bold',
            Token.Instruction: '',  # default
            Token.Answer: '#f44336 bold',
            Token.Question: '',
        })

    return None


def if_mousedown(handler):
    def handle_if_mouse_down(cli, mouse_event):
        if mouse_event.event_type == MouseEventTypes.MOUSE_DOWN:
            return handler(cli, mouse_event)
        else:
            return NotImplemented

    return handle_if_mouse_down


def get_deps(platform_json):
    platform = read_json_file(platform_json)
    subsystem_dict = {}
    component_deps = defaultdict(list)
    component_targets = {}
    component_dirs = {}
    for subsystem in platform['subsystems']:
        subsystem_dict[subsystem['subsystem']] = []
        for component in subsystem['components']:
            cname = component['component']
            subsystem_dict[subsystem['subsystem']].append(cname)
            if 'components' in component['deps']:
                deps = component['deps']['components']
                if cname in deps:
                    deps.remove(cname)
            else:
                deps = []
            component_deps[cname] = deps
            component_targets[cname] = component['targets']
            component_dirs[cname] = [
                os.path.join(os.path.dirname(platform_json),
                    os.pardir, os.pardir, os.pardir, os.pardir, path)
                        for path in component['dirs']]

    return subsystem_dict, component_deps, component_targets, component_dirs


def select_node(node, selected, nodes_from, deps):
    queue = Queue()
    queue.put(node)
    nodes_from[node].append(node)

    while not queue.empty():
        now_node = queue.get()
        if now_node not in selected:
            selected.append(now_node)
        for dep in deps.get(now_node, []):
            if now_node != dep and dep not in selected:
                queue.put(dep)
            nodes_from[dep].append(node)


def deselect_node(node, selected, nodes_from, deps):
    queue = Queue()
    queue.put(node)
    node_list = []

    while not queue.empty():
        now_node = queue.get()
        for each_node in nodes_from[now_node]:
            queue.put(each_node)
        nodes_from[now_node].clear()
        if now_node in selected:
            selected.remove(now_node)
            node_list.append(now_node)

    [queue.put(n) for n in node_list]
    while not queue.empty():
        now_node = queue.get()
        for dep in deps.get(now_node, []):
            if dep not in selected:
                continue
            nodes_from[dep] = [n for n in nodes_from[dep] if n in selected]
            if not len(nodes_from[dep]):
                selected.remove(dep)
                queue.put(dep)


def get_deps_list(comp, deps):
    queue = Queue()
    visited = set()
    deps_list = [comp]
    queue.put(comp)

    while not queue.empty():
        node = queue.get()
        for index, dep_comp in enumerate(deps[node]):
            if dep_comp in visited:
                continue
            deps_list.append(dep_comp)
            queue.put(dep_comp)
            visited.add(dep_comp)

    return deps_list


def get_support_product(product_path):
    product_dict = defaultdict(list)
    for product in os.listdir(product_path):
        product_json = os.path.join(product_path, product)
        product_content = read_json_file(product_json)
        board = product_content.get('board')
        kernel = product_content.get('kernel')
        platform = "{}_{}".format(board, kernel)
        product_dict[platform].append(product.strip('.json'))

    return product_dict


def check_path(dep, path):
    dep = dep[:-1] if dep.endswith("/") else dep
    path = path[:-1] if path.endswith("/") else path

    if len(dep) > len(path):
        path_max = dep
        path_min = path
    else:
        path_max = path
        path_min = dep

    if path_min in path_max:
        path_sub = path_max.replace(path_min, "")
        if path_sub == "":
            return True
        if path_sub.startswith('/') or path_sub.startswith(':'):
            return True
    return False


class Separator(object):
    line = '-' * 15

    def __init__(self, line=None):
        if line:
            self.line = line

    def __str__(self):
        return self.line
  • 写回答

3条回答 默认 最新

  • saikutoo 2021-06-15 11:27
    关注

    同样的问题卡着了,apt装上prompt_toolkit后继续报错,不轻易敢动common.py代码。

    首先是要装prompt_toolkit。

    但直接sudo apt-get prompt_toolkit装上后的版本是3点几的,库导入的方式不兼容了,所以得回到一个旧版本, 试过sudo pip3 install prompt-toolkit==1.0.15这个可以。

    编译成功

    评论

报告相同问题?

悬赏问题

  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)