File: clean.py

package info (click to toggle)
jupyterlab 4.0.11%2Bds1%2B~cs11.25.27-7
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 43,496 kB
  • sloc: javascript: 18,395; python: 8,932; sh: 399; makefile: 95; perl: 33; xml: 1
file content (43 lines) | stat: -rw-r--r-- 1,323 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import os
import subprocess

here = os.path.abspath(os.path.dirname(__file__))


# Workaround for https://github.com/git-for-windows/git/issues/607
if os.name == "nt":
    for root, dnames, _ in os.walk(here):
        if "node_modules" in dnames:
            subprocess.check_call(
                ["rmdir", "/s", "/q", "node_modules"],  # noqa S602 S607
                cwd=root,
                shell=True,  # noqa S602 S607
            )
            dnames.remove("node_modules")


subprocess.check_call("python -m pip uninstall -y jupyterlab".split(), cwd=here)  # noqa S603


def resolve_pattern(pat):
    """handle a leading `#` or `@` in a pattern"""
    pat = pat.strip()

    if not pat or pat.startswith("#"):
        return []
    elif pat.startswith("@"):
        raw = pat[1:]
        return [raw, f"!packages/**/{raw}", f"!**/node_modules/**/{raw}"]
    else:
        return [pat]


# get the exclude patterns listed in .cleanignore
with open(os.path.join(here, ".cleanignore")) as f:
    git_clean_exclude = [f"--exclude={pat}" for line in f for pat in resolve_pattern(line)]

git_clean_command = ["git", "clean", "-dfx", *git_clean_exclude]
subprocess.check_call(git_clean_command, cwd=here)  # noqa S603