Skip to content

Commit

Permalink
Auto-generate man pages using help2man.
Browse files Browse the repository at this point in the history
You need to use the build_man and install_man commands with setup.py,
since these man pages are not usually needed.
  • Loading branch information
QuLogic committed Aug 28, 2014
1 parent 01d95d8 commit 03b3537
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion setup.py
Expand Up @@ -36,7 +36,10 @@
"Please install numpy first, it is needed before installing ObsPy.")
raise ImportError(msg)

from numpy.distutils.core import setup
from numpy.distutils.core import setup, DistutilsSetupError
from numpy.distutils.command.build import build
from numpy.distutils.command.install import install
from numpy.distutils.exec_command import exec_command, find_executable
from numpy.distutils.misc_util import Configuration
from numpy.distutils.ccompiler import get_default_compiler

Expand Down Expand Up @@ -124,6 +127,9 @@
'obspy-xseed2dataless = obspy.xseed.scripts.xseed2dataless:main',
'obspy-dataless2resp = obspy.xseed.scripts.dataless2resp:main',
],
'distutils.commands': [
'build_man = Help2Man'
],
'obspy.plugin.waveform': [
'TSPAIR = obspy.core.ascii',
'SLIST = obspy.core.ascii',
Expand Down Expand Up @@ -545,6 +551,59 @@ def add_data_files(config):
dirs.remove(folder)


# Auto-generate man pages from --help output
class Help2ManBuild(build):
description = "Run help2man on scripts to produce man pages"

def finalize_options(self):
build.finalize_options(self)
self.help2man = find_executable('help2man')
if not self.help2man:
raise DistutilsSetupError('Building man pages requires help2man.')

def run(self):
mandir = os.path.join(self.build_base, 'man')
self.mkpath(mandir)

from pkg_resources import iter_entry_points
for entrypoint in iter_entry_points(group='console_scripts'):
if not entrypoint.module_name.startswith('obspy'):
continue

output = os.path.join(mandir, entrypoint.name + '.1')
print('Generating %s ...' % (output))
exec_command([self.help2man,
'--no-info', '--no-discard-stderr',
'--output', output,
'"%s -m %s"' % (sys.executable,
entrypoint.module_name)])


class Help2ManInstall(install):
description = 'Install man pages generated by help2man'
user_options = install.user_options + [
('manprefix=', None, 'MAN Prefix Path')
]

def initialize_options(self):
self.manprefix = None
install.initialize_options(self)

def finalize_options(self):
if self.manprefix is None:
self.manprefix = os.path.join('share', 'man')
install.finalize_options(self)

def run(self):
if not self.skip_build:
self.run_command('build_man')

srcdir = os.path.join(self.build_base, 'man')
mandir = os.path.join(self.install_base, self.manprefix, 'man1')
self.mkpath(mandir)
self.copy_tree(srcdir, mandir)


def setupPackage():
# setup package
setup(
Expand Down Expand Up @@ -587,6 +646,7 @@ def setupPackage():
include_package_data=True,
entry_points=ENTRY_POINTS,
ext_package='obspy.lib',
cmdclass={'build_man': Help2ManBuild, 'install_man': Help2ManInstall},
configuration=configuration)


Expand Down

0 comments on commit 03b3537

Please sign in to comment.