Exemple #1
0
def index():
    files = sorted(all_file_paths())
    prefix = os.path.commonprefix(files)
    files = zip(
        files,
        [strip_required_prefix(f, prefix) or path_leaf(f) for f in files])
    return render_template('index.html', files=files)
Exemple #2
0
def short_path(path, all_paths):
    # type: (str, List[str]) -> str
    if path == IPYTHON_FILE_PATH:
        return path

    all_paths = [f for f in all_paths if f != IPYTHON_FILE_PATH]
    prefix = common_ancestor(all_paths)
    if prefix in r'\/':
        prefix = ''
    return strip_required_prefix(path, prefix) or path_leaf(path)
Exemple #3
0
    def run(self, root):
        for node in root.findall(".//pre/code"):
            text = unescape(node.text)

            prefix = "__copyable__\n"
            if copyable := text.startswith(prefix):
                text = strip_required_prefix(text, prefix)

            if (is_valid_syntax(text) or is_valid_syntax(text + "\n 0")
                    or is_valid_syntax(dedent(text))):
                self.highlight_node(node, text)

            if copyable:
                node.append(
                    etree.fromstring(
                        '<button class="btn btn-primary">Copy</button>'))
                node.set("class", node.get("class") + " copyable")
def get_roots():
    run_steps()
    roots = set()
    mod_names = []
    for module in list(sys.modules.values()):
        try:
            f = module.__file__ or ""
        except AttributeError:
            continue

        if not f.startswith(site_packages):
            continue

        relative = strip_required_prefix(f, site_packages)
        root = relative.split(os.path.sep)[0]
        roots.add(root)

        mod_names.append(module.__name__)

    return sorted(roots)
Exemple #5
0
    def update_without_prefix(self, prefix: str, *functions: Callable,
                              **kwargs: Callable) -> Composer:
        """
        Given a prefix and a list of (named) functions, this adds the functions
        to the composer but first strips the prefix from their name. This is very
        useful to stop name shadowing.

        Args:
            prefix: The prefix to strip off the function names
            functions: functions to add while stripping the prefix
            kwargs: named functions to add
        Returns:
            A new composer with the functions added
        """

        args_with_names = {
            strip_required_prefix(arg.__name__, prefix): arg
            for arg in functions
        }
        return self.update(**args_with_names, **kwargs)
Exemple #6
0
def unwrapped_markdown(s):
    s = markdown(s)
    s = strip_required_prefix(s, "<p>")
    s = strip_required_suffix(s, "</p>")
    return s
Exemple #7
0
def short_path(path):
    return strip_required_prefix(path, os.path.commonprefix(
        all_file_paths())) or path_leaf(path)
Exemple #8
0
def check_and_remove_prefix(string, prefix):
    if startswith := string.startswith(prefix):
        string = strip_required_prefix(string, prefix)