-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
executable file
·123 lines (99 loc) · 4.3 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/python3
# Copyright (C) 2019-2022, Benjamin Drung <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""Setup for bdebstrap"""
import logging
import os
import subprocess
from setuptools import Command, setup
try:
from setuptools.command.build import build
except ImportError:
# Fallback for setuptools < 60 and Python < 3.12
# pylint: disable-next=deprecated-module
from distutils.command.build import build # type: ignore
HOOKS = ["hooks/disable-units", "hooks/enable-units"]
MAN_PAGES = ["bdebstrap.1"]
class DocCommand(Command):
"""A custom command to build the documentation using pandoc."""
description = "run pandoc to generate man pages"
user_options: list[tuple[str, str, str]] = []
def initialize_options(self) -> None:
"""Set default values for options."""
def finalize_options(self) -> None:
"""Post-process options."""
# pylint: disable-next=no-self-use
def run(self) -> None:
"""Run pandoc."""
logger = logging.getLogger(__name__)
for man_page in MAN_PAGES:
command = ["pandoc", "-s", "-t", "man", man_page + ".md", "-o", man_page]
logger.info("running command: %s", " ".join(command))
subprocess.check_call(command)
# pylint: disable-next=too-few-public-methods
class BuildCommand(build):
"""Custom build command (calling doc beforehand)."""
def run(self) -> None:
"""Execute the build command."""
self.run_command("doc")
super().run()
class CleanCommand(Command):
"""Custom clean command (removing generated man pages)."""
description = "remove generated man pages"
user_options = [("all", "a", "remove all build output, not just temporary by-products")]
boolean_options = ["all"]
def initialize_options(self) -> None:
"""Set default values for options."""
def finalize_options(self) -> None:
"""Post-process options."""
# pylint: disable-next=no-self-use
def run(self) -> None:
"""Clean build artefacts from doc command."""
logger = logging.getLogger(__name__)
for man_page in MAN_PAGES:
if os.path.exists(man_page):
logger.info("removing %s", man_page)
os.remove(man_page)
if __name__ == "__main__":
with open("README.md", "r", encoding="utf-8") as fh:
LONG_DESCRIPTION = fh.read()
setup(
name="bdebstrap",
version="0.7.0",
description="Benjamin's multi-mirror Debian chroot creation tool",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
author="Benjamin Drung",
author_email="[email protected]",
url="https://github.com/bdrung/bdebstrap",
project_urls={"Bug Tracker": "https://github.com/bdrung/bdebstrap/issues"},
license="ISC",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"License :: OSI Approved :: ISC License (ISCL)",
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
cmdclass={"doc": DocCommand, "build": BuildCommand, "clean": CleanCommand},
install_requires=["ruamel.yaml"],
scripts=["bdebstrap"],
py_modules=[],
data_files=[("/usr/share/man/man1", MAN_PAGES), ("/usr/share/bdebstrap/hooks", HOOKS)],
)