Skip to content

Commit 8f88204

Browse files
committed
Implement 'clean' command.
1 parent f3da0e5 commit 8f88204

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

‎graalpython/com.oracle.graal.python.cext/setup.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,5 +324,16 @@ def build(capi_home, capi_module_home):
324324
build_builtin_exts(capi_module_home)
325325

326326

327+
def clean(capi_home, capi_module_home):
328+
libpython_path = os.path.join(capi_home, libpython_name + so_ext)
329+
if os.path.exists(libpython_path):
330+
logger.info("Cleaning %s", libpython_path)
331+
os.unlink(libpython_path)
332+
if os.path.exists(capi_module_home):
333+
for f in [os.path.join(capi_module_home, f) for f in os.listdir(capi_module_home) if f.endswith(so_ext)]:
334+
logger.info("Cleaning %s", f)
335+
os.unlink(f)
336+
337+
327338
if __name__ == "__main__":
328339
build()

‎graalpython/lib-python/3/build_capi.py‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@
4747
capi_home = site.getusersitepackages()
4848
capi_module_home = site.getusersitepackages()
4949

50-
def build(args=[]):
50+
51+
def load_setup():
52+
spec = importlib.util.spec_from_file_location("setup.py", os.path.join(sys.graal_python_cext_src, "setup.py"))
53+
setup_module = importlib.util.module_from_spec(spec)
54+
spec.loader.exec_module(setup_module)
55+
return setup_module
56+
57+
58+
def configure_logging(args):
5159
if "-v" in args or "--verbose" in args:
5260
dlog.set_verbosity(dlog.DEBUG)
5361
logging.basicConfig(level=logging.DEBUG)
@@ -56,11 +64,20 @@ def build(args=[]):
5664
logging.basicConfig(level=logging.ERROR)
5765
else:
5866
logging.basicConfig(level=logging.INFO)
59-
spec = importlib.util.spec_from_file_location("setup.py", os.path.join(sys.graal_python_cext_src, "setup.py"))
60-
setup_module = importlib.util.module_from_spec(spec)
61-
spec.loader.exec_module(setup_module)
62-
return setup_module.build(capi_home, capi_module_home)
67+
68+
69+
def build(args=[]):
70+
configure_logging(args)
71+
return load_setup().build(capi_home, capi_module_home)
72+
73+
74+
def clean(args=[]):
75+
configure_logging(args)
76+
return load_setup().clean(capi_home, capi_module_home)
6377

6478

6579
if __name__ == "__main__":
66-
build(sys.argv)
80+
if "clean" in sys.argv:
81+
clean(sys.argv)
82+
else:
83+
build(sys.argv)

0 commit comments

Comments
 (0)