From e319a9c2c9c8eb83d62934d5142a8e5d285df534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20M=C3=BCller?= Date: Mon, 29 Oct 2018 10:02:31 +0100 Subject: [PATCH 1/2] Allow for flat install of python files via `py` feature --- waflib/Tools/python.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/waflib/Tools/python.py b/waflib/Tools/python.py index 63a8917d..5885b499 100644 --- a/waflib/Tools/python.py +++ b/waflib/Tools/python.py @@ -79,14 +79,19 @@ def process_py(self, node): """ Add signature of .py file, so it will be byte-compiled when necessary """ - assert(hasattr(self, 'install_path')), 'add features="py"' + assert(hasattr(self, 'install_path')), 'add features="py" for target "%s" in "%s/wscript".' % (self.target, self.path.nice_path()) + self.install_from = getattr(self, 'install_from', None) + relative_trick = getattr(self, 'relative_trick', True) + if self.install_from: + assert isinstance(self.install_from, Node.Node), \ + 'add features="py" for target "%s" in "%s/wscript" (%s).' % (self.target, self.path.nice_path(), type(self.install_from)) # where to install the python file if self.install_path: if self.install_from: - self.add_install_files(install_to=self.install_path, install_from=node, cwd=self.install_from, relative_trick=True) + self.add_install_files(install_to=self.install_path, install_from=node, cwd=self.install_from, relative_trick=relative_trick) else: - self.add_install_files(install_to=self.install_path, install_from=node, relative_trick=True) + self.add_install_files(install_to=self.install_path, install_from=node, relative_trick=relative_trick) lst = [] if self.env.PYC: @@ -96,9 +101,11 @@ def process_py(self, node): if self.install_path: if self.install_from: - pyd = Utils.subst_vars("%s/%s" % (self.install_path, node.path_from(self.install_from)), self.env) + target_dir = node.path_from(self.install_from) if relative_trick else node.name + pyd = Utils.subst_vars("%s/%s" % (self.install_path, target_dir), self.env) else: - pyd = Utils.subst_vars("%s/%s" % (self.install_path, node.path_from(self.path)), self.env) + target_dir = node.path_from(self.path) if relative_trick else node.name + pyd = Utils.subst_vars("%s/%s" % (self.install_path, target_dir), self.env) else: pyd = node.abspath() @@ -115,7 +122,7 @@ def process_py(self, node): tsk.pyd = pyd if self.install_path: - self.add_install_files(install_to=os.path.dirname(pyd), install_from=pyobj, cwd=node.parent.get_bld(), relative_trick=True) + self.add_install_files(install_to=os.path.dirname(pyd), install_from=pyobj, cwd=node.parent.get_bld(), relative_trick=relative_trick) class pyc(Task.Task): """ From 8353c5ebfb5c7da9cf46a4fbe80074b88ab9ef6e Mon Sep 17 00:00:00 2001 From: Yannik Stradmann Date: Wed, 19 Jun 2019 23:46:27 +0200 Subject: [PATCH 2/2] Add demo for nested/flat python file installation --- demos/python/nested_scripts/bar/nested_bar.py | 3 +++ demos/python/nested_scripts/foo/nested_foo.py | 3 +++ demos/python/wscript | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 demos/python/nested_scripts/bar/nested_bar.py create mode 100644 demos/python/nested_scripts/foo/nested_foo.py diff --git a/demos/python/nested_scripts/bar/nested_bar.py b/demos/python/nested_scripts/bar/nested_bar.py new file mode 100644 index 00000000..f74f2b5a --- /dev/null +++ b/demos/python/nested_scripts/bar/nested_bar.py @@ -0,0 +1,3 @@ +""" +Nested file in bar/ +""" diff --git a/demos/python/nested_scripts/foo/nested_foo.py b/demos/python/nested_scripts/foo/nested_foo.py new file mode 100644 index 00000000..ba64dcb6 --- /dev/null +++ b/demos/python/nested_scripts/foo/nested_foo.py @@ -0,0 +1,3 @@ +""" +Nested file in foo/ +""" diff --git a/demos/python/wscript b/demos/python/wscript index 07b5b666..07b071d5 100644 --- a/demos/python/wscript +++ b/demos/python/wscript @@ -50,3 +50,21 @@ def build(bld): source = 'test.c', target = 'test') + # Install files keeping their directory structure (default: relative_trick=True) + # + # This will create two files: + # * lib/python2.7/site-packages/nested_scripts/bar/nested_bar.py + # * lib/python2.7/site-packages/nested_scripts/foo/nested_foo.py + bld(features='py', + source=bld.path.ant_glob('nested_scripts/**/*.py'), + install_from='.') + + # Install files flatting the directory structure (relative_trick=False) + # + # This will create two files: + # * lib/python2.7/site-packages/nested_bar.py + # * lib/python2.7/site-packages/nested_foo.py + bld(features='py', + source=bld.path.ant_glob('nested_scripts/**/*.py'), + relative_trick=False, + install_from='.')