Skip to content

Commit 7681c58

Browse files
authored
style: Add black pre-commit hook (#2811)
1 parent 391e7b0 commit 7681c58

File tree

4 files changed

+68
-52
lines changed

4 files changed

+68
-52
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ repos:
5858
--ignore-words=pre-commit-hooks/codespell_ignore.txt,
5959
]
6060

61+
- repo: https://github.com/psf/black-pre-commit-mirror
62+
rev: 25.11.0
63+
hooks:
64+
- id: black
65+
6166
# Running some C++ hooks before clang-format
6267
# to ensure that the style is consistent.
6368
- repo: local

conanfile.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,60 @@
33

44

55
class ClioConan(ConanFile):
6-
name = 'clio'
7-
license = 'ISC'
8-
author = 'Alex Kremer <akremer@ripple.com>, John Freeman <jfreeman@ripple.com>, Ayaz Salikhov <asalikhov@ripple.com>'
9-
url = 'https://github.com/xrplf/clio'
10-
description = 'Clio RPC server'
11-
settings = 'os', 'compiler', 'build_type', 'arch'
6+
name = "clio"
7+
license = "ISC"
8+
author = "Alex Kremer <akremer@ripple.com>, John Freeman <jfreeman@ripple.com>, Ayaz Salikhov <asalikhov@ripple.com>"
9+
url = "https://github.com/xrplf/clio"
10+
description = "Clio RPC server"
11+
settings = "os", "compiler", "build_type", "arch"
1212
options = {}
1313

1414
requires = [
15-
'boost/1.83.0',
16-
'cassandra-cpp-driver/2.17.0',
17-
'protobuf/3.21.12',
18-
'grpc/1.50.1',
19-
'openssl/1.1.1w',
20-
'xrpl/3.0.0-rc1',
21-
'zlib/1.3.1',
22-
'libbacktrace/cci.20210118',
23-
'spdlog/1.16.0',
15+
"boost/1.83.0",
16+
"cassandra-cpp-driver/2.17.0",
17+
"protobuf/3.21.12",
18+
"grpc/1.50.1",
19+
"openssl/1.1.1w",
20+
"xrpl/3.0.0-rc1",
21+
"zlib/1.3.1",
22+
"libbacktrace/cci.20210118",
23+
"spdlog/1.16.0",
2424
]
2525

2626
default_options = {
27-
'xrpl/*:tests': False,
28-
'xrpl/*:rocksdb': False,
29-
'cassandra-cpp-driver/*:shared': False,
30-
'date/*:header_only': True,
31-
'grpc/*:shared': False,
32-
'grpc/*:secure': True,
33-
'libpq/*:shared': False,
34-
'lz4/*:shared': False,
35-
'openssl/*:shared': False,
36-
'protobuf/*:shared': False,
37-
'protobuf/*:with_zlib': True,
38-
'snappy/*:shared': False,
39-
'gtest/*:no_main': True,
27+
"xrpl/*:tests": False,
28+
"xrpl/*:rocksdb": False,
29+
"cassandra-cpp-driver/*:shared": False,
30+
"date/*:header_only": True,
31+
"grpc/*:shared": False,
32+
"grpc/*:secure": True,
33+
"libpq/*:shared": False,
34+
"lz4/*:shared": False,
35+
"openssl/*:shared": False,
36+
"protobuf/*:shared": False,
37+
"protobuf/*:with_zlib": True,
38+
"snappy/*:shared": False,
39+
"gtest/*:no_main": True,
4040
}
4141

42-
exports_sources = (
43-
'CMakeLists.txt', 'cmake/*', 'src/*'
44-
)
42+
exports_sources = ("CMakeLists.txt", "cmake/*", "src/*")
4543

4644
def requirements(self):
47-
self.requires('gtest/1.14.0')
48-
self.requires('benchmark/1.9.4')
49-
self.requires('fmt/12.1.0', force=True)
45+
self.requires("gtest/1.14.0")
46+
self.requires("benchmark/1.9.4")
47+
self.requires("fmt/12.1.0", force=True)
5048

5149
def configure(self):
52-
if self.settings.compiler == 'apple-clang':
53-
self.options['boost'].visibility = 'global'
50+
if self.settings.compiler == "apple-clang":
51+
self.options["boost"].visibility = "global"
5452

5553
def layout(self):
5654
cmake_layout(self)
5755
# Fix this setting to follow the default introduced in Conan 1.48
5856
# to align with our build instructions.
59-
self.folders.generators = 'build/generators'
57+
self.folders.generators = "build/generators"
6058

61-
generators = 'CMakeDeps'
59+
generators = "CMakeDeps"
6260

6361
def generate(self):
6462
tc = CMakeToolchain(self)

pre-commit-hooks/json_in_cpp.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import re
55
from pathlib import Path
66

7-
87
PATTERN = r'R"JSON\((.*?)\)JSON"'
98

109

@@ -40,6 +39,7 @@ def replace_json(match):
4039
raw_json = match.group(1)
4140
raw_json = re.sub(r'":\n\s*(\[|\{)', r'": \1', raw_json)
4241
return f'R"JSON({raw_json})JSON"'
42+
4343
return re.sub(PATTERN, replace_json, cpp_content, flags=re.DOTALL)
4444

4545

@@ -49,12 +49,12 @@ def fix_indentation(cpp_content: str) -> str:
4949

5050
lines = cpp_content.splitlines()
5151

52-
ends_with_newline = cpp_content.endswith('\n')
52+
ends_with_newline = cpp_content.endswith("\n")
5353

5454
def find_indentation(line: str) -> int:
5555
return len(line) - len(line.lstrip())
5656

57-
for (line_num, (line, next_line)) in enumerate(zip(lines[:-1], lines[1:])):
57+
for line_num, (line, next_line) in enumerate(zip(lines[:-1], lines[1:])):
5858
if "JSON(" in line and ")JSON" not in line:
5959
indent = find_indentation(line)
6060
next_indent = find_indentation(next_line)
@@ -69,7 +69,11 @@ def find_indentation(line: str) -> int:
6969
if ")JSON" in lines[i]:
7070
lines[i] = " " * indent + lines[i].lstrip()
7171
break
72-
lines[i] = lines[i][by_how_much:] if by_how_much > 0 else " " * (-by_how_much) + lines[i]
72+
lines[i] = (
73+
lines[i][by_how_much:]
74+
if by_how_much > 0
75+
else " " * (-by_how_much) + lines[i]
76+
)
7377

7478
result = "\n".join(lines)
7579

tools/rebuild_conan.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python3
22
import json
3-
import plumbum
43
from pathlib import Path
54

5+
import plumbum
6+
67
THIS_DIR = Path(__file__).parent.resolve()
78
ROOT_DIR = THIS_DIR.parent.resolve()
89

@@ -21,15 +22,23 @@ def rebuild():
2122
for profile in profiles:
2223
print(f"Rebuilding {profile} with build type {build_type}")
2324
with plumbum.local.cwd(ROOT_DIR):
24-
CONAN[
25-
"install", ".",
26-
"--build=missing",
27-
f"--output-folder=build_{profile}_{build_type}",
28-
"-s", f"build_type={build_type}",
29-
"-o", "&:tests=True",
30-
"-o", "&:benchmark=True",
31-
"--profile:all", profile
32-
] & plumbum.FG
25+
(
26+
CONAN[
27+
"install",
28+
".",
29+
"--build=missing",
30+
f"--output-folder=build_{profile}_{build_type}",
31+
"-s",
32+
f"build_type={build_type}",
33+
"-o",
34+
"&:tests=True",
35+
"-o",
36+
"&:benchmark=True",
37+
"--profile:all",
38+
profile,
39+
]
40+
& plumbum.FG
41+
)
3342

3443

3544
if __name__ == "__main__":

0 commit comments

Comments
 (0)