Uses cd context manager in Python3Recipe.reduce_python()

This commit is contained in:
Andre Miras 2020-05-06 19:36:50 +02:00
parent 6d42fe3132
commit b1bdfcd028

View file

@ -1,4 +1,4 @@
from kivy_ios.toolchain import Recipe, shprint from kivy_ios.toolchain import Recipe, shprint, cd
from os.path import join from os.path import join
import sh import sh
import shutil import shutil
@ -149,29 +149,28 @@ class Python3Recipe(Recipe):
def reduce_python(self): def reduce_python(self):
logger.info("Reduce python") logger.info("Reduce python")
oldpwd = os.getcwd()
try:
logger.info("Remove files unlikely to be used") logger.info("Remove files unlikely to be used")
os.chdir(join(self.ctx.dist_dir, "root", "python3")) with cd(join(self.ctx.dist_dir, "root", "python3")):
sh.rm("-rf", "bin", "share") sh.rm("-rf", "bin", "share")
# platform binaries and configuration # platform binaries and configuration
os.chdir(join( with cd(join(
self.ctx.dist_dir, "root", "python3", "lib", self.ctx.dist_dir, "root", "python3", "lib",
"python3.8", "config-3.8-darwin")) "python3.8", "config-3.8-darwin")):
sh.rm("libpython3.8.a") sh.rm(
sh.rm("python.o") "libpython3.8.a",
sh.rm("config.c.in") "python.o",
sh.rm("makesetup") "config.c.in",
sh.rm("install-sh") "makesetup",
"install-sh",
)
# cleanup pkgconfig and compiled lib # cleanup pkgconfig and compiled lib
os.chdir(join(self.ctx.dist_dir, "root", "python3", "lib")) with cd(join(self.ctx.dist_dir, "root", "python3", "lib")):
sh.rm("-rf", "pkgconfig") sh.rm("-rf", "pkgconfig", "libpython3.8.a")
sh.rm("-f", "libpython3.8.a")
# cleanup python libraries # cleanup python libraries
os.chdir(join( with cd(join(
self.ctx.dist_dir, "root", "python3", "lib", "python3.8")) self.ctx.dist_dir, "root", "python3", "lib", "python3.8")):
sh.rm("-rf", "wsgiref", "curses", "idlelib", "lib2to3", sh.rm("-rf", "wsgiref", "curses", "idlelib", "lib2to3",
"ensurepip", "turtledemo", "lib-dynload", "venv", "ensurepip", "turtledemo", "lib-dynload", "venv",
"pydoc_data") "pydoc_data")
@ -199,8 +198,6 @@ class Python3Recipe(Recipe):
sh.rm("-rf", sh.glob("*")) sh.rm("-rf", sh.glob("*"))
sh.mv("../config-3.8-darwin", ".") sh.mv("../config-3.8-darwin", ".")
sh.mv("../site-packages", ".") sh.mv("../site-packages", ".")
finally:
os.chdir(oldpwd)
recipe = Python3Recipe() recipe = Python3Recipe()