Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 2f4825a

Browse files
committed
Modularize formatter
1 parent a902d24 commit 2f4825a

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

script/formatting/formatter.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import subprocess
1515

1616
from functools import reduce
17-
from script.helpers import CLANG_FORMAT, PELOTON_DIR, CLANG_FORMAT_FILE, LOG
17+
from script.helpers import CLANG_FORMAT, PELOTON_DIR, CLANG_FORMAT_FILE, LOG,\
18+
clang_format
1819

1920
## ==============================================
2021
## CONFIGURATION
@@ -98,13 +99,9 @@ def format_file(file_path, update_header, clang_format_code):
9899
file.write(file_data)
99100

100101
elif clang_format_code:
101-
if CLANG_FORMAT is None:
102+
if clang_format(file_path) is None:
102103
LOG.error("clang-format seems not installed")
103-
exit("clang-format seems not installed")
104-
105-
formatting_command = CLANG_FORMAT + " -style=file -i " + file_path
106-
LOG.info(formatting_command)
107-
subprocess.call([CLANG_FORMAT, "-style=file", "-i", file_path])
104+
exit()
108105

109106
#END WITH
110107
#END FORMAT__FILE(FILE_NAME)

script/helpers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def find_clangformat():
4242
return path
4343

4444
CLANG_FORMAT = find_clangformat()
45-
45+
CLANG_COMMAND_PREFIX = [CLANG_FORMAT, "-style=file"]
4646

4747
def clang_check(file_path):
4848
"""Checks and reports bad code formatting."""
@@ -57,7 +57,7 @@ def clang_check(file_path):
5757
if CLANG_FORMAT is None:
5858
LOG.error("clang-format seems not installed")
5959
exit()
60-
clang_format_cmd = [CLANG_FORMAT, "-style=file", file_path]
60+
clang_format_cmd = CLANG_COMMAND_PREFIX + [file_path]
6161
formatted_src = subprocess.check_output(clang_format_cmd).splitlines(True)
6262

6363
# For Python 3, the above command gives a list of binary sequences, each
@@ -84,3 +84,13 @@ def clang_check(file_path):
8484
file_status = False
8585

8686
return file_status
87+
88+
89+
def clang_format(file_path):
90+
"""Formats the file at file_path"""
91+
if CLANG_FORMAT is None:
92+
return False
93+
formatting_command = CLANG_COMMAND_PREFIX + ["-i", file_path]
94+
LOG.info(' '.join(formatting_command))
95+
subprocess.call(formatting_command)
96+
return True

src/main/peloton/peloton.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ int main(int argc, char *argv[]) {
3434

3535
// Print settings
3636
if (peloton::settings::SettingsManager::GetBool(
37-
peloton::settings::SettingId::display_settings)) {
38-
auto &settings = peloton::settings::SettingsManager::GetInstance();
37+
peloton::settings::SettingId::display_settings)) {auto &settings = peloton::settings::SettingsManager::GetInstance();
3938
settings.ShowInfo();
4039
}
4140

0 commit comments

Comments
 (0)