Skip to content

Commit ce87580

Browse files
author
Ailing Zhang
committed
[misc] Support clean command to setup.py.
``` $ python setup.py clean running clean removing '/Users/ailzhang/github/taichi/build' (and everything under it) removing 'bin' (and everything under it) removing 'python/taichi/assets' (and everything under it) removing 'python/taichi/lib' (and everything under it) removing 'python/taichi/examples' (and everything under it) removing 'python/taichi/tests' (and everything under it) removing 'python/taichi.egg-info' (and everything under it) removing generated file taichi/common/commit_hash.h removing generated file taichi/common/version.h removing generated file taichi/runtime/llvm/runtime_arm64.bc removing generated file taichi/runtime/llvm/runtime_arm64.ll $ python setup.py clean --dry-run ``` Note this command only cleans up local information of your previous builds. It mainly allows a fresh build without any cache from previous builds. This is a different use case than `pip uninstall taichi` which uninstalls taichi package from your python environment. ghstack-source-id: e36eb05 Pull Request resolved: taichi-dev/taichi#2962
1 parent 57e84de commit ce87580

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[metadata]
2-
description-file = README
2+
description_file = README

setup.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import shutil
1313
import subprocess
1414
import sys
15+
from distutils.command.clean import clean
16+
from distutils.dir_util import remove_tree
1517

1618
from setuptools import Extension, find_packages, setup
1719
from setuptools.command.build_ext import build_ext
@@ -46,6 +48,8 @@
4648
# Our python package root dir is python/
4749
package_dir = 'python'
4850

51+
root_dir = os.path.abspath(os.path.dirname(__file__))
52+
4953

5054
def get_python_executable():
5155
return sys.executable.replace('\\', '/')
@@ -113,7 +117,7 @@ def run(self):
113117
", ".join(e.name for e in self.extensions))
114118

115119
# CMakeLists.txt is in the same directory as this setup.py file
116-
cmake_list_dir = os.path.abspath(os.path.dirname(__file__))
120+
cmake_list_dir = root_dir
117121
self.build_temp = os.path.join(cmake_list_dir, 'build')
118122

119123
build_directory = os.path.abspath(self.build_temp)
@@ -192,6 +196,30 @@ def prepare_package(self):
192196
shutil.copy(os.path.join(llvm_runtime_dir, f), target)
193197

194198

199+
class Clean(clean):
200+
def run(self):
201+
super().run()
202+
self.build_temp = os.path.join(root_dir, 'build')
203+
if os.path.exists(self.build_temp):
204+
remove_tree(self.build_temp, dry_run=self.dry_run)
205+
generated_folders = ('bin', 'dist', 'python/taichi/assets',
206+
'python/taichi/lib', 'python/taichi/examples',
207+
'python/taichi/tests', 'python/taichi.egg-info')
208+
for d in generated_folders:
209+
if os.path.exists(d):
210+
remove_tree(d, dry_run=self.dry_run)
211+
generated_files = [
212+
'taichi/common/commit_hash.h', 'taichi/common/version.h'
213+
]
214+
generated_files += glob.glob('taichi/runtime/llvm/runtime_*.bc')
215+
generated_files += glob.glob('taichi/runtime/llvm/runtime_*.ll')
216+
for f in generated_files:
217+
if os.path.exists(f):
218+
print(f'removing generated file {f}')
219+
if not self.dry_run:
220+
os.remove(f)
221+
222+
195223
setup(name=project_name,
196224
packages=packages,
197225
package_dir={"": package_dir},
@@ -218,5 +246,8 @@ def prepare_package(self):
218246
},
219247
classifiers=classifiers,
220248
ext_modules=[CMakeExtension('taichi_core')],
221-
cmdclass=dict(egg_info=EggInfo, build_py=BuildPy, build_ext=CMakeBuild),
249+
cmdclass=dict(egg_info=EggInfo,
250+
build_py=BuildPy,
251+
build_ext=CMakeBuild,
252+
clean=Clean),
222253
has_ext_modules=lambda: True)

0 commit comments

Comments
 (0)