Automatically install manual pages
Pavel Raiskup
6 years ago
4 | 4 | - "3.5" |
5 | 5 | - "3.6" |
6 | 6 | |
7 | # install: | |
8 | # - "pip install -r requirements.txt" | |
7 | install: | |
8 | - "pip install -r requirements.txt" | |
9 | 9 | |
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" |
29 | 29 | |
30 | 30 | ```python |
31 | 31 | [...] |
32 | from build_manpages import build_manpages, get_build_py | |
32 | from build_manpages import build_manpages, get_build_py_cmd, get_install_cmd | |
33 | 33 | from setuptools.command.build_py import build_py |
34 | from setuptools.command.install import install | |
34 | 35 | |
35 | 36 | setup( |
36 | 37 | [...] |
37 | 38 | cmdclass={ |
38 | 39 | '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), | |
41 | 44 | } |
42 | 45 | ) |
43 | 46 | ``` |
2 | 2 | command. |
3 | 3 | """ |
4 | 4 | |
5 | import os | |
6 | ||
5 | 7 | DEFAULT_CMD_NAME = 'build_manpages' |
6 | 8 | |
7 | 9 | from distutils.core import Command |
8 | 10 | from distutils.errors import DistutilsOptionError |
11 | import shutil | |
12 | ||
9 | 13 | import configparser |
10 | 14 | from .build_manpage import ManPageWriter, get_parser |
11 | 15 | |
70 | 74 | mw.write(page) |
71 | 75 | |
72 | 76 | |
73 | def get_build_py(command): | |
77 | def get_build_py_cmd(command): | |
74 | 78 | class build_py(command): |
75 | 79 | def run(self): |
76 | 80 | self.run_command(DEFAULT_CMD_NAME) |
77 | 81 | command.run(self) |
78 | 82 | |
79 | 83 | 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 | build |
0 | Hack to work-around missing stuff. |
0 | HACK⏎ |
0 | 0 | [build_manpages] |
1 | 1 | manpages = |
2 | example.1:module=copr_cli.main:function=setup_parser | |
2 | copr-cli.1:module=copr_cli.main:function=setup_parser |
5 | 5 | import os |
6 | 6 | import sys |
7 | 7 | |
8 | from setuptools import setup | |
8 | from setuptools import setup, find_packages | |
9 | 9 | |
10 | 10 | # Just to make sure that build_manpage can be found. |
11 | 11 | 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 | |
13 | 14 | |
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 | |
15 | 20 | |
16 | 21 | setup( |
17 | 22 | name='example', |
21 | 26 | author_email='jd@example.com', |
22 | 27 | version='0.1.0', |
23 | 28 | 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(), | |
26 | 35 | ) |
0 | configparser |
61 | 61 | def test_copr(self): |
62 | 62 | with on_syspath(os.getcwd()): |
63 | 63 | 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]): | |
65 | 68 | try: |
66 | os.remove('example.1') | |
69 | os.remove(name) | |
67 | 70 | except OSError: |
68 | 71 | pass |
69 | 72 | 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') |