-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·193 lines (153 loc) · 5.36 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·193 lines (153 loc) · 5.36 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#! /usr/bin/env python3
"""Installation script for brz.
Run it with
'./setup.py install', or
'./setup.py --help' for more options.
"""
import os
import os.path
import sys
try:
import setuptools # noqa: F401
except ModuleNotFoundError as e:
sys.stderr.write(f"[ERROR] Please install setuptools ({e})\n")
sys.exit(1)
try:
from setuptools_rust import Binding, RustExtension, Strip
except ModuleNotFoundError as e:
sys.stderr.write(f"[ERROR] Please install setuptools_rust ({e})\n")
sys.exit(1)
from setuptools import setup
from setuptools.command.build import build
try:
from setuptools_gettext import build_mo # noqa: F401
except ImportError:
sys.stderr.write(
"[ERROR] Please install setuptools_gettext to build translations.\n"
)
sys.exit(1)
from distutils.command.build_scripts import build_scripts
from setuptools import Command
###############################
# Overridden distutils actions
###############################
class brz_build_scripts(build_scripts):
"""Custom build_scripts command that handles Rust extension binaries.
This class extends the standard build_scripts command to properly handle
Rust extension binaries by moving executable Rust extensions from the
build_lib directory to the scripts directory.
"""
def run(self):
"""Execute the build_scripts command and handle Rust executables.
First runs the standard build_scripts process, then moves any Rust
executable extensions from the build_lib directory to the scripts
build directory.
"""
build_scripts.run(self)
self.run_command("build_ext")
build_ext = self.get_finalized_command("build_ext")
for ext in self.distribution.rust_extensions:
if ext.binding == Binding.Exec:
# GZ 2021-08-19: Not handling multiple binaries yet.
os.replace(
os.path.join(build_ext.build_lib, ext.name),
os.path.join(self.build_dir, ext.name),
)
class build_man(Command):
"""Custom command to generate the brz.1 manual page.
This command builds the Breezy extension modules and then uses the
generate_docs tool to create the brz.1 manual page from the built
modules.
"""
def initialize_options(self):
"""Initialize command options.
No options to initialize for this command.
"""
pass
def finalize_options(self):
"""Finalize command options.
No options to finalize for this command.
"""
pass
def run(self):
"""Execute the manual page generation.
Builds the extension modules, adds the build directory to sys.path,
and then imports and runs the generate_docs tool to create the
brz.1 manual page.
"""
build_ext_cmd = self.get_finalized_command("build_ext")
build_lib_dir = build_ext_cmd.build_lib
sys.path.insert(0, os.path.abspath(build_lib_dir))
import importlib
importlib.invalidate_caches()
del sys.modules["breezy"]
from tools import generate_docs
generate_docs.main(["generate-docs", "man"])
########################
## Setup
########################
command_classes = {
"build_man": build_man,
}
if "editable_wheel" not in sys.argv:
command_classes["build_scripts"] = brz_build_scripts
# ad-hoc for easy_install
DATA_FILES = []
if (
"bdist_egg" not in sys.argv
and "bdist_wheel" not in sys.argv
and "editable_wheel" not in sys.argv
):
# generate and install brz.1 only with plain install, not the
# easy_install one
build.sub_commands.append(("build_man", lambda _: True))
DATA_FILES = [("man/man1", ["brz.1", "breezy/git/git-remote-bzr.1"])]
import site
site.ENABLE_USER_SITE = "--user" in sys.argv
rust_extensions = [
RustExtension("breezy._cmd_rs", "crates/cmd-py/Cargo.toml", binding=Binding.PyO3),
RustExtension(
"breezy._osutils_rs", "crates/osutils-py/Cargo.toml", binding=Binding.PyO3
),
RustExtension(
"breezy._patch_rs", "crates/patch-py/Cargo.toml", binding=Binding.PyO3
),
RustExtension(
"breezy._annotator_rs",
"crates/annotate-py/Cargo.toml",
binding=Binding.PyO3,
),
RustExtension(
"breezy.zlib_util", "crates/zlib-util-py/Cargo.toml", binding=Binding.PyO3
),
RustExtension("breezy._git_rs", "crates/git-py/Cargo.toml", binding=Binding.PyO3),
]
entry_points = {}
if (
os.environ.get("CIBUILDWHEEL", "0") == "0"
and "__pypy__" not in sys.builtin_module_names
and sys.platform != "win32"
):
rust_extensions.append(
RustExtension(
"brz", "crates/cli/Cargo.toml", binding=Binding.Exec, strip=Strip.All
)
)
else:
# Fall back to python main on cibuildwheels, since it doesn't provide
# -lpython3.7 to link binaries against
# also, disable it for PyPy. See https://foss.heptapod.net/pypy/pypy/-/issues/3286
entry_points.setdefault("console_scripts", []).append("brz=breezy.__main__:main")
# std setup
setup(
scripts=[ # TODO(jelmer): Only install the git scripts if
# Dulwich was found.
"breezy/git/git-remote-bzr",
"breezy/git/bzr-receive-pack",
"breezy/git/bzr-upload-pack",
],
data_files=DATA_FILES,
cmdclass=command_classes,
entry_points=entry_points,
rust_extensions=rust_extensions,
)