forked from fsfe/reuse-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
154 lines (129 loc) · 4.7 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
#
# SPDX-FileCopyrightText: 2017 Free Software Foundation Europe e.V. <https://fsfe.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import platform
import shutil
import subprocess
from distutils import cmd
from pathlib import Path
from warnings import warn
from setuptools import setup
from setuptools.command.build_py import build_py
requirements = [
# For parsing .reuse/dep5.
"python-debian"
if platform.system() != "Windows"
else "python-debian != 0.1.39",
# For downloading from spdx/spdx-license-list-data. Could maybe use
# standard library instead?
"requests",
# For parsing SPDX License Expressions.
"license-expression",
# Indirect requirement of license-expression, but we require it because we
# import its exceptions.
"boolean.py",
# For templates of headers.
"Jinja2",
# Exactly what it says.
"binaryornot",
]
test_requirements = ["pytest"]
setup_requirements = ["setuptools_scm"]
fallback_version = "0.12.1"
def readme_md():
"""Return contents of README.md"""
return open("README.md").read()
def changelog_md():
"""Return contents of CHANGELOG.md"""
return open("CHANGELOG.md").read()
class BuildTrans(cmd.Command):
"""Command for compiling the .mo files."""
user_options = []
def initialize_options(self):
self.po_files = None
self.msgfmt = None
self.build_lib = None
self.outputs = []
def finalize_options(self):
self.set_undefined_options("build", ("build_lib", "build_lib"))
self.po_files = glob.glob("po/*.po")
for msgfmt in ["msgfmt", "msgfmt.py", "msgfmt3.py"]:
self.msgfmt = shutil.which(msgfmt)
if self.msgfmt:
break
def run(self):
if self.msgfmt:
for po_file in self.po_files:
self.announce(f"compiling {po_file}")
lang_dir = str(
Path(self.build_lib)
/ "reuse/locale"
/ Path(po_file).stem
/ "LC_MESSAGES"
)
destination = str(Path(lang_dir) / "reuse.mo")
compile_func = lambda msgfmt, in_file, out: subprocess.run(
[msgfmt, in_file, "-o", out]
)
self.mkpath(lang_dir)
self.make_file(
po_file,
destination,
compile_func,
(self.msgfmt, po_file, destination),
)
self.outputs.append(destination)
else:
warn("msgfmt is not installed. Translations will not be included.")
def get_outputs(self):
return self.outputs
class Build(build_py):
"""Redefined build."""
def run(self):
self.run_command("build_trans")
super().run()
def get_outputs(self):
build_trans = self.get_finalized_command("build_trans")
return super().get_outputs() + build_trans.get_outputs()
if __name__ == "__main__":
setup(
name="reuse",
use_scm_version={"fallback_version": fallback_version},
version=fallback_version,
url="https://reuse.software/",
project_urls={
"Documentation": "https://reuse.readthedocs.io/",
"Source": "https://github.com/fsfe/reuse-tool",
},
license="GPL-3.0-or-later AND Apache-2.0 AND CC0-1.0 AND CC-BY-SA-4.0",
author="Carmen Bianca Bakker",
author_email="[email protected]",
description="reuse is a tool for compliance with the REUSE "
"recommendations.",
long_description=readme_md() + "\n\n" + changelog_md(),
long_description_content_type="text/markdown",
package_dir={"": "src"},
packages=["reuse"],
include_package_data=True,
entry_points={"console_scripts": ["reuse = reuse._main:main"]},
install_requires=requirements,
tests_require=test_requirements,
setup_requires=setup_requirements,
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: "
"GNU General Public License v3 or later (GPLv3+)",
"License :: OSI Approved :: Apache Software License",
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
cmdclass={"build_py": Build, "build_trans": BuildTrans},
)