archrelease: copy trunk to community-any
[ArchLinux/community.git] / reuse / trunk / ftbfs-build.py.patch
blob44e817d3e17e5c185973728db1a2783cc0ea34ce
1 --- a/build.py
2 +++ /dev/null
3 @@ -1,103 +0,0 @@
4 -#!/usr/bin/env python3
5 -#
6 -# SPDX-FileCopyrightText: 2017 Free Software Foundation Europe e.V. <https://fsfe.org>
7 -# SPDX-FileCopyrightText: 2022 Carmen Bianca Bakker <carmenbianca@fsfe.org>
8 -#
9 -# SPDX-License-Identifier: GPL-3.0-or-later
11 -"""Script called by poetry. The API used by poetry is unstable, but let's hope
12 -this stays functional.
13 -"""
15 -import glob
16 -import os
17 -import shutil
18 -import subprocess
19 -from pathlib import Path
20 -from warnings import warn
22 -from setuptools import Distribution
23 -from setuptools.command.build_py import build_py
25 -# pylint: disable=attribute-defined-outside-init
28 -class Build(build_py):
29 - """Redefined build."""
31 - def initialize_options(self):
32 - super().initialize_options()
33 - self.po_files = None
34 - self.msgfmt = None
35 - self.mo_outputs = []
37 - def finalize_options(self):
38 - super().finalize_options()
39 - self.po_files = glob.glob("po/*.po")
40 - for msgfmt in ["msgfmt", "msgfmt.py", "msgfmt3.py"]:
41 - self.msgfmt = shutil.which(msgfmt)
42 - if self.msgfmt:
43 - break
45 - def run(self):
46 - super().run()
47 - if self.msgfmt:
48 - for po_file in self.po_files:
49 - self.announce(f"compiling {po_file}")
50 - lang_dir = str(
51 - Path(self.build_lib)
52 - / "reuse/locale"
53 - / Path(po_file).stem
54 - / "LC_MESSAGES"
55 - )
56 - destination = str(Path(lang_dir) / "reuse.mo")
57 - compile_func = lambda msgfmt, in_file, out: subprocess.run(
58 - [msgfmt, in_file, "-o", out],
59 - check=True,
60 - )
62 - self.mkpath(lang_dir)
63 - self.make_file(
64 - po_file,
65 - destination,
66 - compile_func,
67 - (self.msgfmt, po_file, destination),
68 - )
69 - self.mo_outputs.append(destination)
71 - else:
72 - warn("msgfmt is not installed. Translations will not be included.")
74 - def get_outputs(self, include_bytecode=1):
75 - return (
76 - super().get_outputs(include_bytecode=include_bytecode)
77 - + self.mo_outputs
78 - )
81 -def build():
82 - """Main function that runs the compilation."""
83 - distribution = Distribution(
84 - {
85 - "package_dir": {"": "src"},
86 - }
87 - )
88 - cmd = Build(distribution)
89 - cmd.inplace = 1
90 - cmd.ensure_finalized()
91 - cmd.run()
93 - # Copy into src/. This appears to be the thing that actually does all the
94 - # heavy lifting. I'm not sure why I'm bothering with all the
95 - # setuptools-specific logic above.
96 - #
97 - # In summary: Get .mo files from build directory and put them into
98 - # src/reuse/locale/{lang}/LC_MESSAGES/reuse.mo.
99 - for output in cmd.get_outputs():
100 - relative = Path("src") / os.path.relpath(output, cmd.build_lib)
101 - relative.parent.mkdir(parents=True, exist_ok=True)
102 - shutil.copyfile(output, relative)
105 -if __name__ == "__main__":
106 - build()
107 --- a/pyproject.toml
108 +++ b/pyproject.toml
109 @@ -68,7 +68,6 @@ reuse = 'reuse._main:main'
111 [tool.poetry.build]
112 generate-setup-file = false
113 -script = "build.py"
115 [build-system]
116 requires = ["poetry-core>=1.1.0", "setuptools"]