Skip to content

Commit 1967113

Browse files
committed
fmt: apply black formatting
1 parent 377824c commit 1967113

File tree

16 files changed

+150
-118
lines changed

16 files changed

+150
-118
lines changed

docs/conf.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
# -- Project information -----------------------------------------------------
1414

15-
project = 'setuptools-rust'
16-
copyright = '2021, The PyO3 Contributors'
17-
author = 'The PyO3 Contributors'
15+
project = "setuptools-rust"
16+
copyright = "2021, The PyO3 Contributors"
17+
author = "The PyO3 Contributors"
1818

1919

2020
# -- General configuration ---------------------------------------------------
@@ -31,28 +31,28 @@
3131
]
3232

3333
# Add any paths that contain templates here, relative to this directory.
34-
templates_path = ['_templates']
34+
templates_path = ["_templates"]
3535

3636
# List of patterns, relative to source directory, that match files and
3737
# directories to ignore when looking for source files.
3838
# This pattern also affects html_static_path and html_extra_path.
39-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
39+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
4040

4141

4242
# -- Options for HTML output -------------------------------------------------
4343

4444
# The theme to use for HTML and HTML Help pages. See the documentation for
4545
# a list of builtin themes.
4646
#
47-
html_theme = 'sphinx_rtd_theme'
47+
html_theme = "sphinx_rtd_theme"
4848

4949
# Add any paths that contain custom static files (such as style sheets) here,
5050
# relative to this directory. They are copied after the builtin static files,
5151
# so a file named "default.css" will overwrite the builtin "default.css".
52-
html_static_path = ['_static']
52+
html_static_path = ["_static"]
5353

5454
html_theme_options = {
55-
'prev_next_buttons_location': None,
55+
"prev_next_buttons_location": None,
5656
}
5757

5858
# -- Custom HTML link transformation to make documentation links relative --
@@ -62,29 +62,32 @@
6262

6363
from sphinx.transforms import SphinxTransform
6464

65-
DOCS_URL = 'https://setuptools-rust.readthedocs.io/en/latest/'
65+
DOCS_URL = "https://setuptools-rust.readthedocs.io/en/latest/"
66+
6667

6768
class RelativeDocLinks(SphinxTransform):
6869

6970
default_priority = 750
7071

7172
def apply(self):
7273
from docutils.nodes import reference, Text
74+
7375
baseref = lambda o: (
74-
isinstance(o, reference) and
75-
o.get('refuri', '').startswith(DOCS_URL))
76-
basetext = lambda o: (
77-
isinstance(o, Text) and o.startswith(DOCS_URL))
76+
isinstance(o, reference) and o.get("refuri", "").startswith(DOCS_URL)
77+
)
78+
basetext = lambda o: (isinstance(o, Text) and o.startswith(DOCS_URL))
7879
for node in self.document.traverse(baseref):
79-
target = node['refuri'].replace(DOCS_URL, "", 1)
80-
node.replace_attr('refuri', target)
80+
target = node["refuri"].replace(DOCS_URL, "", 1)
81+
node.replace_attr("refuri", target)
8182
for t in node.traverse(basetext):
8283
t1 = Text(t.replace(DOCS_URL, "", 1), t.rawsource)
8384
t.parent.replace(t, t1)
8485
return
8586

87+
8688
# end of class
8789

90+
8891
def setup(app):
8992
app.add_transform(RelativeDocLinks)
9093
return

examples/html-py-ever/setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
"Operating System :: MacOS :: MacOS X",
2020
],
2121
packages=["html_py_ever"],
22-
install_requires=[
23-
"beautifulsoup4",
24-
"lxml"
25-
],
22+
install_requires=["beautifulsoup4", "lxml"],
2623
rust_extensions=[RustExtension("html_py_ever.html_py_ever")],
2724
include_package_data=True,
2825
zip_safe=False,

examples/html-py-ever/test/run_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def rust(filename: str) -> Tuple[int, float, float]:
2121

2222
def python(filename: str, parser: str) -> Tuple[int, float, float]:
2323
start_load = perf_counter()
24-
with open(filename, encoding='utf8') as fp:
24+
with open(filename, encoding="utf8") as fp:
2525
soup = BeautifulSoup(fp, parser)
2626

2727
end_load = perf_counter()

examples/html-py-ever/test/test_parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def rust(filename: str) -> Document:
1616

1717

1818
def python(filename: str) -> BeautifulSoup:
19-
with open(filename, encoding='utf8') as fp:
19+
with open(filename, encoding="utf8") as fp:
2020
soup = BeautifulSoup(fp, "html.parser")
2121

2222
return soup

examples/html-py-ever/test/test_selector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ def test_bench_selector_rust(benchmark, filename):
1818

1919
@pytest.mark.parametrize("filename", HTML_FILES)
2020
def test_bench_selector_python(benchmark, filename):
21-
with open(filename, encoding='utf8') as fp:
21+
with open(filename, encoding="utf8") as fp:
2222
soup = BeautifulSoup(fp, "html.parser")
2323
benchmark(soup.select, "a[href]")

examples/namespace_package/setup.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33

44

55
setup(
6-
name='namespace_package',
6+
name="namespace_package",
77
version="0.1.0",
8-
packages=find_namespace_packages(include=['namespace_package.*']),
8+
packages=find_namespace_packages(include=["namespace_package.*"]),
99
zip_safe=False,
10-
rust_extensions=[RustExtension("namespace_package.rust", path="Cargo.toml", binding=Binding.PyO3, debug=False)],
10+
rust_extensions=[
11+
RustExtension(
12+
"namespace_package.rust",
13+
path="Cargo.toml",
14+
binding=Binding.PyO3,
15+
debug=False,
16+
)
17+
],
1118
)

examples/namespace_package/tests/test_namespace_package.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33

44
def test_rust():
5-
assert rust.rust_func() == 14
5+
assert rust.rust_func() == 14
66

77

88
def test_cffi():
9-
assert python.python_func() == 15
9+
assert python.python_func() == 15

examples/rust_with_cffi/cffi_module.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33

44
ffi = cffi.FFI()
5-
ffi.cdef("""
5+
ffi.cdef(
6+
"""
67
int cffi_func(void);
7-
""")
8-
ffi.set_source("rust_with_cffi.cffi", """
8+
"""
9+
)
10+
ffi.set_source(
11+
"rust_with_cffi.cffi",
12+
"""
913
int cffi_func(void) {
1014
return 15;
1115
}
12-
""")
16+
""",
17+
)

examples/rust_with_cffi/tests/test_rust_with_cffi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44

55
def test_rust():
6-
assert rust.rust_func() == 14
6+
assert rust.rust_func() == 14
77

88

99
def test_cffi():
10-
assert lib.cffi_func() == 15
10+
assert lib.cffi_func() == 15

setuptools_rust/build.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ def __init__(self, triple=None, cross_lib=None, linker=None, link_args=None):
3434
self.linker = linker
3535
self.link_args = link_args
3636

37+
3738
class build_rust(RustCommand):
38-
""" Command for building Rust crates via cargo. """
39+
"""Command for building Rust crates via cargo."""
3940

4041
description = "build Rust extensions (compile/link to build directory)"
4142

@@ -72,7 +73,7 @@ def finalize_options(self):
7273
super().finalize_options()
7374

7475
if self.plat_name is None:
75-
self.plat_name = self.get_finalized_command('build').plat_name
76+
self.plat_name = self.get_finalized_command("build").plat_name
7677

7778
# Inherit settings from the `build_ext` command
7879
self.set_undefined_options(
@@ -105,17 +106,17 @@ def get_nix_target_info(self):
105106
# necessarily the same as the system we are running on. *NIX systems
106107
# have more detailed information available in sysconfig. We need that
107108
# because plat_name doesn't give us information on e.g., glibc vs musl.
108-
host_type = sysconfig.get_config_var('HOST_GNU_TYPE')
109-
build_type = sysconfig.get_config_var('BUILD_GNU_TYPE')
109+
host_type = sysconfig.get_config_var("HOST_GNU_TYPE")
110+
build_type = sysconfig.get_config_var("BUILD_GNU_TYPE")
110111

111112
if not host_type or host_type == build_type:
112113
# not *NIX, or not cross compiling
113114
return _TargetInfo()
114115

115-
stdlib = sysconfig.get_path('stdlib')
116+
stdlib = sysconfig.get_path("stdlib")
116117
cross_lib = os.path.dirname(stdlib)
117118

118-
bldshared = sysconfig.get_config_var('BLDSHARED')
119+
bldshared = sysconfig.get_config_var("BLDSHARED")
119120
if not bldshared:
120121
linker = None
121122
linker_args = None
@@ -131,16 +132,17 @@ def get_nix_target_info(self):
131132

132133
# the vendor field can be ignored, so x86_64-pc-linux-gnu is compatible
133134
# with x86_64-unknown-linux-gnu
134-
components = host_type.split('-')
135+
components = host_type.split("-")
135136
if len(components) == 4:
136-
components[1] = 'unknown'
137-
host_type2 = '-'.join(components)
137+
components[1] = "unknown"
138+
host_type2 = "-".join(components)
138139
if host_type2 in targets:
139140
return _TargetInfo(host_type2, cross_lib, linker, linker_args)
140141

141142
raise DistutilsPlatformError(
142-
"Don't know the correct rust target for system type %s. Please "
143-
"set the CARGO_BUILD_TARGET environment variable." % host_type)
143+
"Don't know the correct rust target for system type %s. Please "
144+
"set the CARGO_BUILD_TARGET environment variable." % host_type
145+
)
144146

145147
def run_for_extension(self, ext: RustExtension):
146148
arch_flags = os.getenv("ARCHFLAGS")
@@ -151,9 +153,13 @@ def run_for_extension(self, ext: RustExtension):
151153
arm64_dylib_paths = self.build_extension(ext, "aarch64-apple-darwin")
152154
x86_64_dylib_paths = self.build_extension(ext, "x86_64-apple-darwin")
153155
dylib_paths = []
154-
for (target_fname, arm64_dylib), (_, x86_64_dylib) in zip(arm64_dylib_paths, x86_64_dylib_paths):
156+
for (target_fname, arm64_dylib), (_, x86_64_dylib) in zip(
157+
arm64_dylib_paths, x86_64_dylib_paths
158+
):
155159
fat_dylib_path = arm64_dylib.replace("aarch64-apple-darwin/", "")
156-
self.create_universal2_binary(fat_dylib_path, [arm64_dylib, x86_64_dylib])
160+
self.create_universal2_binary(
161+
fat_dylib_path, [arm64_dylib, x86_64_dylib]
162+
)
157163
dylib_paths.append((target_fname, fat_dylib_path))
158164
else:
159165
dylib_paths = self.build_extension(ext)
@@ -179,7 +185,9 @@ def build_extension(self, ext: RustExtension, target_triple=None):
179185
# which causes pythonXX-sys to fall back to detecting the
180186
# interpreter from the path.
181187
"PATH": os.path.join(bindir, os.environ.get("PATH", "")),
182-
"PYTHON_SYS_EXECUTABLE": os.environ.get("PYTHON_SYS_EXECUTABLE", sys.executable),
188+
"PYTHON_SYS_EXECUTABLE": os.environ.get(
189+
"PYTHON_SYS_EXECUTABLE", sys.executable
190+
),
183191
"PYO3_PYTHON": os.environ.get("PYO3_PYTHON", sys.executable),
184192
}
185193
)
@@ -212,7 +220,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
212220

213221
features = {
214222
*ext.features,
215-
*binding_features(ext, py_limited_api=self._py_limited_api())
223+
*binding_features(ext, py_limited_api=self._py_limited_api()),
216224
}
217225

218226
debug_build = ext.debug if ext.debug is not None else self.inplace
@@ -238,7 +246,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
238246
args.append("-q")
239247
elif self.verbose:
240248
# cargo only have -vv
241-
verbose_level = 'v' * min(self.verbose, 2)
249+
verbose_level = "v" * min(self.verbose, 2)
242250
args.append(f"-{verbose_level}")
243251

244252
else:
@@ -254,7 +262,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
254262
args.append("-q")
255263
elif self.verbose:
256264
# cargo only have -vv
257-
verbose_level = 'v' * min(self.verbose, 2)
265+
verbose_level = "v" * min(self.verbose, 2)
258266
args.append(f"-{verbose_level}")
259267

260268
args.extend(["--", "--crate-type", "cdylib"])
@@ -293,9 +301,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
293301
try:
294302
output = subprocess.check_output(args, env=env, encoding="latin-1")
295303
except subprocess.CalledProcessError as e:
296-
raise CompileError(
297-
f"cargo failed with code: {e.returncode}\n{e.output}"
298-
)
304+
raise CompileError(f"cargo failed with code: {e.returncode}\n{e.output}")
299305

300306
except OSError:
301307
raise DistutilsExecError(
@@ -421,23 +427,18 @@ def install_extension(self, ext: RustExtension, dylib_paths):
421427
mode |= (mode & 0o444) >> 2 # copy R bits to X
422428
os.chmod(ext_path, mode)
423429

424-
def get_dylib_ext_path(
425-
self,
426-
ext: RustExtension,
427-
target_fname: str
428-
) -> str:
430+
def get_dylib_ext_path(self, ext: RustExtension, target_fname: str) -> str:
429431
build_ext = self.get_finalized_command("build_ext")
430432

431433
filename = build_ext.get_ext_fullpath(target_fname)
432434

433-
if (
434-
(ext.py_limited_api == "auto" and self._py_limited_api())
435-
or (ext.py_limited_api)
435+
if (ext.py_limited_api == "auto" and self._py_limited_api()) or (
436+
ext.py_limited_api
436437
):
437438
abi3_suffix = get_abi3_suffix()
438439
if abi3_suffix is not None:
439-
so_ext = get_config_var('EXT_SUFFIX')
440-
filename = filename[:-len(so_ext)] + get_abi3_suffix()
440+
so_ext = get_config_var("EXT_SUFFIX")
441+
filename = filename[: -len(so_ext)] + get_abi3_suffix()
441442

442443
return filename
443444

@@ -451,9 +452,7 @@ def create_universal2_binary(output_path, input_paths):
451452
output = e.output
452453
if isinstance(output, bytes):
453454
output = e.output.decode("latin-1").strip()
454-
raise CompileError(
455-
"lipo failed with code: %d\n%s" % (e.returncode, output)
456-
)
455+
raise CompileError("lipo failed with code: %d\n%s" % (e.returncode, output))
457456
except OSError:
458457
# lipo not found, try using the fat-macho library
459458
try:

0 commit comments

Comments
 (0)