Codebase list argparse-manpage / 4749f37
Automatically install manual pages Pavel Raiskup 6 years ago
17 changed file(s) with 75 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
00 *.pyc
1 example.1
1 *.1
2 i
3 *.egg-info
44 - "3.5"
55 - "3.6"
66
7 # install:
8 # - "pip install -r requirements.txt"
7 install:
8 - "pip install -r requirements.txt"
99
10 script: "python$TRAVIS_PYTHON_VERSION setup.py build && python$TRAVIS_PYTHON_VERSION -m pytest unittests"
10 script: "python$TRAVIS_PYTHON_VERSION setup.py build && python$TRAVIS_PYTHON_VERSION -m pytest"
2929
3030 ```python
3131 [...]
32 from build_manpages import build_manpages, get_build_py
32 from build_manpages import build_manpages, get_build_py_cmd, get_install_cmd
3333 from setuptools.command.build_py import build_py
34 from setuptools.command.install import install
3435
3536 setup(
3637 [...]
3738 cmdclass={
3839 'build_manpages': build_manpages,
39 # Re-define build-py with new command also calling 'build_manpages'
40 'build': get_build_py(build_py),
40 # Re-define build_py and install commands so the manual pages
41 # are automatically re-generated and installed (optional)
42 'build_py': get_build_py_cmd(build_py),
43 'install': get_install_cmd(install),
4144 }
4245 )
4346 ```
22 command.
33 """
44
5 import os
6
57 DEFAULT_CMD_NAME = 'build_manpages'
68
79 from distutils.core import Command
810 from distutils.errors import DistutilsOptionError
11 import shutil
12
913 import configparser
1014 from .build_manpage import ManPageWriter, get_parser
1115
7074 mw.write(page)
7175
7276
73 def get_build_py(command):
77 def get_build_py_cmd(command):
7478 class build_py(command):
7579 def run(self):
7680 self.run_command(DEFAULT_CMD_NAME)
7781 command.run(self)
7882
7983 return build_py
84
85
86 def get_install_cmd(command):
87 class install(command):
88 def install_manual_pages(self):
89 config = configparser.ConfigParser()
90 config.read('setup.cfg')
91 spec = config[DEFAULT_CMD_NAME]['manpages']
92 data = parse_manpages_spec(spec)
93
94 mandir = os.path.join(self.install_data, 'share/man/man1')
95 if not os.path.exists(mandir):
96 os.makedirs(mandir)
97 for key, _ in data.items():
98 print ('installing {0}'.format(key))
99 shutil.copy(key, mandir)
100
101 def run(self):
102 command.run(self)
103 self.install_manual_pages()
104
105 return install
0 Hack to work-around missing stuff.
0 # Hack
1
2 class CoprClient(object):
3 pass
0 class Environment:
1 pass
00 [build_manpages]
11 manpages =
2 example.1:module=copr_cli.main:function=setup_parser
2 copr-cli.1:module=copr_cli.main:function=setup_parser
55 import os
66 import sys
77
8 from setuptools import setup
8 from setuptools import setup, find_packages
99
1010 # Just to make sure that build_manpage can be found.
1111 sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../..'))
12 sys.path.append(os.getcwd())
12 sys.path = [os.getcwd()] + sys.path
13 sys.path = [os.path.join(os.getcwd(), 'fake-deps')] + sys.path
1314
14 from build_manpages.build_manpages import build_manpages
15 from build_manpages.build_manpages \
16 import build_manpages, get_build_py_cmd, get_install_cmd
17
18 from setuptools.command.build_py import build_py
19 from setuptools.command.install import install
1520
1621 setup(
1722 name='example',
2126 author_email='jd@example.com',
2227 version='0.1.0',
2328 url='http://example.com',
24 py_modules=['example'],
25 cmdclass={'build_manpages': build_manpages}
29 cmdclass={
30 'build_manpages': build_manpages,
31 'build_py': get_build_py_cmd(build_py),
32 'install': get_install_cmd(install),
33 },
34 packages=find_packages(),
2635 )
0 configparser
6161 def test_copr(self):
6262 with on_syspath(os.getcwd()):
6363 with pushd('examples/copr'):
64 with change_argv(['setup.py', 'build_manpages']):
64 name = 'copr-cli.1'
65 prefix = '/usr'
66 idir = os.path.join(os.getcwd(), 'i')
67 with change_argv(['setup.py', 'install', '--root', idir, '--prefix', prefix]):
6568 try:
66 os.remove('example.1')
69 os.remove(name)
6770 except OSError:
6871 pass
6972 runpy.run_path('setup.py')
70 file_cmp('example.1', 'expected-output.1')
73 import subprocess
74 subprocess.call('find i', shell=True)
75 file_cmp('i/usr/share/man/man1/' + name, 'expected-output.1')
76 file_cmp(name, 'expected-output.1')