clean cache by default

This commit is contained in:
subframe7536 2024-08-02 09:22:52 +08:00
parent 83e2d8638b
commit 965a0a3c8e
2 changed files with 41 additions and 51 deletions

View file

@ -27,10 +27,7 @@ if not package_installed:
# =========================================================================================
# whether to archieve fonts
release_mode = '--release' in sys.argv
# whether to clean built fonts
clean_cache = '--clean-cache' in sys.argv
release_mode = "--release" in sys.argv
# =========================================================================================
@ -166,6 +163,7 @@ skip_subfamily_list = ["Regular", "Bold", "Italic", "BoldItalic"]
def pool_size():
return build_config["pool_size"] if not getenv("CODESPACE_NAME") else 1
# run command
def run(cli: str | list[str], extra_args: list[str] = []) -> None:
subprocess.run((cli.split(" ") if isinstance(cli, str) else cli) + extra_args)
@ -218,17 +216,13 @@ def check_font_patcher() -> bool:
print("FontPatcher version not match, delete it")
shutil.rmtree("FontPatcher", ignore_errors=True)
url = f"https://github.com/ryanoasis/nerd-fonts/releases/download/v{build_config['nerd_font']['version']}/FontPatcher.zip"
try:
zip_path = "FontPatcher.zip"
if not path.exists(zip_path):
url = f"https://github.com/ryanoasis/nerd-fonts/releases/download/v{build_config['nerd_font']['version']}/FontPatcher.zip"
try:
print(f"NerdFont Patcher does not exist, download from {url}")
with urlopen(url) as response, open(zip_path, "wb") as out_file:
shutil.copyfileobj(response, out_file)
with ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall("FontPatcher")
remove(zip_path)
return True
except Exception as e:
print(
f"\nFail to fetch NerdFont Patcher. Please download it manually from {url}, then put downloaded 'FontPatcher.zip' into project's root and run this script again. \n\tError: {e}"
@ -236,6 +230,11 @@ def check_font_patcher() -> bool:
print("use prebuilt Nerd Font instead")
return False
with ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall("FontPatcher")
remove(zip_path)
return True
def get_nerd_font_patcher_args():
# full args: https://github.com/ryanoasis/nerd-fonts?tab=readme-ov-file#font-patcher
@ -512,7 +511,6 @@ def build_cn(f: str):
def main():
if clean_cache:
print("=== [Clean Cache] ===")
shutil.rmtree(output_dir, ignore_errors=True)
shutil.rmtree(output_woff2, ignore_errors=True)
@ -533,7 +531,6 @@ def main():
# =================================== build basic =====================================
# =========================================================================================
if (clean_cache and path.exists(output_ttf)) or not path.exists(output_ttf):
input_files = [
f"{src_dir}/MapleMono-Italic[wght]-VF.ttf",
f"{src_dir}/MapleMono[wght]-VF.ttf",
@ -557,9 +554,7 @@ def main():
# ==================================== build NF =======================================
# =========================================================================================
if (
(clean_cache and path.exists(output_nf)) or not path.exists(output_nf)
) and build_config["nerd_font"]["enable"]:
if build_config["nerd_font"]["enable"]:
use_font_patcher = (
len(build_config["nerd_font"]["extra_args"]) > 0
@ -590,11 +585,7 @@ def main():
# ==================================== build CN =======================================
# =========================================================================================
if (
((clean_cache and path.exists(output_cn)) or not path.exists(output_nf_cn))
and build_config["cn"]["enable"]
and path.exists(f"{src_dir}/cn")
):
if build_config["cn"]["enable"] and path.exists(f"{src_dir}/cn"):
if not path.exists(cn_static_path) or build_config["cn"]["clean_cache"]:
print("====================================")

View file

@ -1,7 +1,6 @@
import os
import subprocess
subprocess.run(["python", "build.py", "--release", "--clean-cache"])
subprocess.run(["python", "build.py", "--release"])
subprocess.run(
[
"ftcli",