Skip to content

Commit 4235027

Browse files
authored
fix(format): add formatting with pre-commit and CI (#431)
1 parent 9230133 commit 4235027

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+7817
-5146
lines changed

.github/workflows/format.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Formatting
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
paths:
9+
- "**/*.py"
10+
pull_request:
11+
branches:
12+
- main
13+
- dev
14+
paths:
15+
- "**/*.py"
16+
17+
jobs:
18+
format:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: 3.12
26+
27+
- name: Install poetry
28+
run: python -m pip install --upgrade poetry wheel
29+
30+
- name: Install dependencies
31+
run: make install
32+
33+
- name: Run format check
34+
run: make format-check

.github/workflows/lint.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Linting
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
paths:
9+
- "**/*.py"
10+
pull_request:
11+
branches:
12+
- main
13+
- dev
14+
paths:
15+
- "**/*.py"
16+
17+
jobs:
18+
lint:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: 3.12
26+
27+
- name: Install poetry
28+
run: python -m pip install --upgrade poetry wheel
29+
30+
- name: Install dependencies
31+
run: make install
32+
33+
- name: Run lint
34+
run: make lint

.github/workflows/test.yml

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,6 @@ on:
2323
- dev
2424

2525
jobs:
26-
lint:
27-
runs-on: ubuntu-latest
28-
steps:
29-
- uses: actions/checkout@v4
30-
- name: Set up Python
31-
uses: actions/setup-python@v5
32-
with:
33-
python-version: 3.12
34-
35-
- name: Install pipenv
36-
run: |
37-
python -m pip install --upgrade poetry wheel
38-
39-
- name: Install dependencies
40-
run: |
41-
make install
42-
43-
- name: Run lint
44-
run: |
45-
make lint
46-
4726
test:
4827
strategy:
4928
matrix:
@@ -56,14 +35,11 @@ jobs:
5635
with:
5736
python-version: ${{ matrix.version }}
5837

59-
- name: Install pipenv
60-
run: |
61-
python -m pip install --upgrade poetry wheel
38+
- name: Install poetry
39+
run: python -m pip install --upgrade poetry wheel
6240

6341
- name: Install dependencies
64-
run: |
65-
make install
42+
run: make install
6643

6744
- name: Run test suite
68-
run: |
69-
make test
45+
run: make test

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ repos:
1313
entry: venv/bin/ruff
1414
args: [check, --force-exclude, --fix, --exit-non-zero-on-fix]
1515
types: ["python"]
16+
17+
- repo: local
18+
hooks:
19+
- id: ruff-format
20+
name: ruff-format
21+
language: system
22+
entry: venv/bin/ruff
23+
args: [format, --check]
24+
types: ["python"]

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ lint:
2424
lint-fix:
2525
poetry run ruff check --fix
2626

27+
format:
28+
poetry run ruff format
29+
30+
format-check:
31+
poetry run ruff format --check
32+
2733
pre-commit-install:
2834
poetry run pre-commit install
2935

boaviztapi/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import yaml
66

77
if "pytest" in sys.modules:
8-
data_dir = os.path.join(os.path.dirname(__file__), '../tests/data')
8+
data_dir = os.path.join(os.path.dirname(__file__), "../tests/data")
99
else:
10-
data_dir = os.path.join(os.path.dirname(__file__), 'data')
10+
data_dir = os.path.join(os.path.dirname(__file__), "data")
1111

12-
config_file = os.path.join(data_dir, 'config.yml')
13-
config = yaml.safe_load(Path(config_file).read_text())
12+
config_file = os.path.join(data_dir, "config.yml")
13+
config = yaml.safe_load(Path(config_file).read_text())

boaviztapi/data/utils/complete_Azure_VMs/compare_vantage_with_benchmarks.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
benchmark_file_linux = "instances_azure_linux.csv"
77
benchmark_file_windows = "instances_azure_windows.csv"
88

9+
910
def main():
1011
v_csv_data = pd.read_csv(vantage_file)
1112
b_csv_data_win = pd.read_csv(benchmark_file_windows)
@@ -15,33 +16,42 @@ def main():
1516
items_found_in_v = []
1617
for d in v_csv_data["Name"]:
1718
d = d.replace(" ", "_")
18-
#print("d: {}".format(d))
19-
res_lin = [ i for i in b_csv_data_lin["Name"] if i == d ]
19+
# print("d: {}".format(d))
20+
res_lin = [i for i in b_csv_data_lin["Name"] if i == d]
2021
if len(res_lin) > 0:
2122
print("Found {} in Benchmark data for Linux: {}".format(d, res_lin))
2223
found_v_in_b += 1
2324
else:
24-
res_win = [ i for i in b_csv_data_win["Name"] if i == d ]
25+
res_win = [i for i in b_csv_data_win["Name"] if i == d]
2526
if len(res_win) > 0:
2627
print("Found {} in Benchmark data for Windows: {}".format(d, res_win))
2728
found_v_in_b += 1
2829
else:
2930
print("{} NOT FOUND IN ANY BENCH".format(d))
3031
for d in b_csv_data_win["Name"]:
31-
res_v = [ i for i in v_csv_data["Name"] if i.replace(" ", "_") == d ]
32+
res_v = [i for i in v_csv_data["Name"] if i.replace(" ", "_") == d]
3233
if len(res_v) > 0 and d not in items_found_in_v:
3334
print("Found {} from bench windows in vantage data: {}".format(d, res_v))
3435
found_b_in_v += 1
3536
items_found_in_v += d
3637
for d in b_csv_data_lin["Name"]:
37-
res_v = [ i for i in v_csv_data["Name"] if i.replace(" ", "_") == d ]
38+
res_v = [i for i in v_csv_data["Name"] if i.replace(" ", "_") == d]
3839
if len(res_v) > 0 and d not in items_found_in_v:
3940
print("Found {} from bench linux in vantage data: {}".format(d, res_v))
4041
found_b_in_v += 1
4142
items_found_in_v += d
4243

43-
print("Found {} items from benchmarks in vantage data. Vantage data contains {}".format(found_b_in_v, len(v_csv_data)))
44-
print("Found {} items from vantage data in benchmarks. Benchmarks contains {}".format(found_v_in_b, len(b_csv_data_lin)+len(b_csv_data_win)))
44+
print(
45+
"Found {} items from benchmarks in vantage data. Vantage data contains {}".format(
46+
found_b_in_v, len(v_csv_data)
47+
)
48+
)
49+
print(
50+
"Found {} items from vantage data in benchmarks. Benchmarks contains {}".format(
51+
found_v_in_b, len(b_csv_data_lin) + len(b_csv_data_win)
52+
)
53+
)
54+
4555

4656
if __name__ == "__main__":
4757
main()

0 commit comments

Comments
 (0)