From fa5516aad662b2c07946af016fe45bc23d6e5991 Mon Sep 17 00:00:00 2001 From: unclecode Date: Tue, 9 Jul 2024 13:25:00 +0800 Subject: [PATCH] chore: Refactor setup.py to use pathlib and shutil for folder creation and removal, to remove cache folder in cross platform manner. --- setup.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 4a2c346d..bee477d7 100644 --- a/setup.py +++ b/setup.py @@ -1,18 +1,18 @@ from setuptools import setup, find_packages import os from pathlib import Path -import subprocess -from setuptools.command.install import install +import shutil # Create the .crawl4ai folder in the user's home directory if it doesn't exist # If the folder already exists, remove the cache folder -crawl4ai_folder = os.path.join(Path.home(), ".crawl4ai") -if os.path.exists(f"{crawl4ai_folder}/cache"): - subprocess.run(["rm", "-rf", f"{crawl4ai_folder}/cache"]) -os.makedirs(crawl4ai_folder, exist_ok=True) -os.makedirs(f"{crawl4ai_folder}/cache", exist_ok=True) +crawl4ai_folder = Path.home() / ".crawl4ai" +cache_folder = crawl4ai_folder / "cache" +if cache_folder.exists(): + shutil.rmtree(cache_folder) +crawl4ai_folder.mkdir(exist_ok=True) +cache_folder.mkdir(exist_ok=True) # Read the requirements from requirements.txt with open("requirements.txt") as f: