From 7849e23eb537de973c93c972d3377720324d9c83 Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Fri, 16 Sep 2016 16:04:25 +0200 Subject: [PATCH] setup.py: take potential "--build-base=" option into account For instance, if osc is build and installed like this: python setup.py build --build-base= ... install ... The patch is based on Roman Neuhauser's (neuhauser@sigpipe.cz) PR (see https://github.com/openSUSE/osc/pull/229). --- setup.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 1aaca6bf..bdb9d365 100755 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ class build_osc(distutils.command.build.build, object): """ """ import gzip - man_path = os.path.join('build', 'osc.1.gz') + man_path = os.path.join(self.build_base, 'osc.1.gz') distutils.log.info('generating %s' % man_path) outfile = gzip.open(man_path, 'w') osccli = commandline.Osc(stdout=outfile) @@ -47,10 +47,10 @@ class build_docs(distutils.command.build.Command): user_options = [] def initialize_options(self): - pass + self.built_docs = None def finalize_options(self): - pass + self.set_undefined_options('build', ('build_base', 'built_docs')) def run(self): # metadata contains information supplied in setup() @@ -61,7 +61,29 @@ class build_docs(distutils.command.build.Command): import sphinx sphinx.main(['runme', '-D', 'version=%s' % metadata.get_version(), - os.path.join('docs',), os.path.join('build', 'docs')]) + os.path.join('docs',), os.path.join(self.built_docs, 'docs')]) + + +# take a potential build-base option into account (for instance, if osc is +# build and installed like this: +# python setup.py build --build-base= ... install ...) +class install_data(distutils.command.install_data.install_data, object): + def initialize_options(self): + super(install_data, self).initialize_options() + self.built_data = None + + def finalize_options(self): + super(install_data, self).finalize_options() + self.set_undefined_options('build', ('build_base', 'built_data')) + data_files = [] + for f in self.data_files: + # f is either a str or a (dir, files) pair + # (see distutils.command.install_data.install_data.run) + if isinstance(f, str): + data_files.append(os.path.join(self.built_data, f)) + else: + data_files.append((f[0], [os.path.join(self.built_data, i) for i in f[1]])) + self.data_files = data_files addparams = {} @@ -72,7 +94,7 @@ if HAVE_PY2EXE: data_files = [] if sys.platform[:3] != 'win': - data_files.append((os.path.join('share', 'man', 'man1'), [os.path.join('build', 'osc.1.gz')])) + data_files.append((os.path.join('share', 'man', 'man1'), ['osc.1.gz'])) setup(name='osc', version = osc.core.__version__, @@ -93,6 +115,7 @@ setup(name='osc', cmdclass = { 'build': build_osc, 'build_docs' : build_docs, + 'install_data': install_data }, **addparams )