From 96f7e8cc22eaeaa5f7cb643b9033e0b9698a4aee Mon Sep 17 00:00:00 2001 From: Ian Foote Date: Mon, 16 Sep 2013 20:42:00 +0100 Subject: [PATCH] Add sitecustomize.py, copy into app_dir on build. --- buildozer/__init__.py | 21 ++++----------------- buildozer/sitecustomize.py | 3 +++ 2 files changed, 7 insertions(+), 17 deletions(-) create mode 100644 buildozer/sitecustomize.py diff --git a/buildozer/__init__.py b/buildozer/__init__.py index 22ecca5..c7a591d 100644 --- a/buildozer/__init__.py +++ b/buildozer/__init__.py @@ -529,7 +529,7 @@ class Buildozer(object): def build_application(self): self._copy_application_sources() self._copy_application_libs() - self._patch_application_sources() + self._add_sitecustomize() def _copy_application_sources(self): # XXX clean the inclusion/exclusion algo. @@ -617,22 +617,9 @@ class Buildozer(object): # copy also the libs copytree(self.applibs_dir, join(self.app_dir, '_applibs')) - def _patch_application_sources(self): - # patch the main.py - main_py = join(self.app_dir, 'main.py') - if not self.file_exists(main_py): - self.error('Unable to patch main_py to add applibs directory.') - return - - header = ('import sys, os; ' - 'sys.path = [os.path.join(os.path.dirname(__file__),' - '"_applibs")] + sys.path\n') - with open(main_py, 'rb') as fd: - data = fd.read() - data = header + data - with open(main_py, 'wb') as fd: - fd.write(data) - self.info('Patched main.py to include applibs') + def _add_sitecustomize(self): + copyfile(join(dirname(__file__), 'sitecustomize.py'), + join(self.app_dir, 'sitecustomize.py')) def namify(self, name): '''Return a "valid" name from a name with lot of invalid chars diff --git a/buildozer/sitecustomize.py b/buildozer/sitecustomize.py new file mode 100644 index 0000000..6650864 --- /dev/null +++ b/buildozer/sitecustomize.py @@ -0,0 +1,3 @@ +from os.path import join, dirname +import sys +sys.path.append(join(dirname(__file__), '_applibs'))