From a6afd0a3f240676925e974a8bba05fed5822c35a Mon Sep 17 00:00:00 2001 From: mataotao Date: Tue, 3 Sep 2024 11:19:47 +0800 Subject: [PATCH] Add exception capture to the OS operation in the run method of the Clean class in the setup. py file Signed-off-by: mataotao --- setup.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index b9f608bbbd..32bcae611e 100755 --- a/setup.py +++ b/setup.py @@ -76,12 +76,19 @@ def run(self): cleaning_list += list(Path("./docs/source/api/").rglob("*.rst")) for e in cleaning_list: - if not os.path.exists(e): - continue - if os.path.isfile(e): - os.remove(e) - if os.path.isdir(e): - shutil.rmtree(e) + try: + if not os.path.exists(e): + continue + if os.path.isfile(e): + os.remove(e) + if os.path.isdir(e): + shutil.rmtree(e) + except FileNotFoundError: + print(f"File not found: {e}, unable to delete.") + except PermissionError: + print(f"Permission denied for {e}, unable to delete.") + except Exception as ex: + print(f"An error occurred while deleting {e}: {ex}") self.clean_optional_plugins()