From d50178f1f85ecb64fb88cbac13391863aaf730fd Mon Sep 17 00:00:00 2001 From: liuluobin Date: Thu, 8 Jul 2021 16:01:06 +0800 Subject: [PATCH] Resolved an issue with incorrect permissions when installing again through setup.py --- setup.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/setup.py b/setup.py index f369bc5..4b2d5f7 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ import os import stat import shlex +import shutil import subprocess from setuptools import find_packages from setuptools import setup @@ -25,6 +26,17 @@ cur_dir = os.path.dirname(os.path.realpath(__file__)) pkg_dir = os.path.join(cur_dir, 'build') +def clean(): + # pylint: disable=unused-argument + def readonly_handler(func, path, execinfo): + os.chmod(path, stat.S_IWRITE) + func(path) + if os.path.exists(os.path.join(cur_dir, 'build')): + shutil.rmtree(os.path.join(cur_dir, 'build'), onerror=readonly_handler) + if os.path.exists(os.path.join(cur_dir, 'mindarmour.egg-info')): + shutil.rmtree(os.path.join(cur_dir, 'mindarmour.egg-info'), onerror=readonly_handler) + + def write_version(file): file.write("__version__ = '{}'\n".format(version)) @@ -36,6 +48,7 @@ def build_depends(): write_version(f) +clean() build_depends()