Skip to content

Commit

Permalink
setup.py: take potential "--build-base=<dir>" option into account
Browse files Browse the repository at this point in the history
For instance, if osc is build and installed like this:
python setup.py build --build-base=<dir> ... install ...

The patch is based on Roman Neuhauser's (neuhauser@sigpipe.cz)
PR (see #229).
  • Loading branch information
marcus-h committed Sep 16, 2016
1 parent 2816f32 commit 7849e23
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions setup.py
Expand Up @@ -25,7 +25,7 @@ def build_man_page(self):
"""
"""
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)
Expand All @@ -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()
Expand All @@ -61,7 +61,29 @@ def run(self):
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=<dir> ... 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 = {}
Expand All @@ -72,7 +94,7 @@ def run(self):

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__,
Expand All @@ -93,6 +115,7 @@ def run(self):
cmdclass = {
'build': build_osc,
'build_docs' : build_docs,
'install_data': install_data
},
**addparams
)

0 comments on commit 7849e23

Please sign in to comment.