Add a setup.py command for cleaning built code.

This commit is contained in:
Jennifer Taylor 2021-05-31 18:12:38 +00:00
parent b022149d28
commit 1b4b5256eb

View File

@ -1,5 +1,6 @@
import os
from setuptools import setup
import shutil
from setuptools import Command, setup
def extensions():
@ -92,6 +93,28 @@ def extensions():
]
class CleanExtCommand(Command):
description = 'Clean all compiled python extensions from the current directory.'
user_options = []
def initialize_options(self) -> None:
pass
def finalize_options(self) -> None:
pass
def run(self) -> None:
print("Removing build directory...")
shutil.rmtree(os.path.abspath("build/"), ignore_errors=True)
for dirname, subdirList, fileList in os.walk(os.path.abspath("bemani/")):
for filename in fileList:
if filename[-3:] == ".so":
fullname = os.path.join(dirname, filename)
print(f"Removing {fullname}")
os.remove(fullname)
setup(
name='bemani',
version='1.0',
@ -170,6 +193,9 @@ setup(
# remove the ext_modules line and run setuptools again. Everything should work, but
# it will run slower.
ext_modules=extensions(),
cmdclass={
'clean_ext': CleanExtCommand,
},
include_package_data=True,
zip_safe=False,
)