Skip to content

Commit 78a8608

Browse files
committed
Add flag --check in setup.py black command
1 parent ce1cfac commit 78a8608

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

.github/workflows/kentik-api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
python -m pip install --upgrade -r requirements-dev.txt
5050
- name: Black
5151
working-directory: ./kentik_api_library
52-
run: python3 setup.py black
52+
run: python3 setup.py black --check
5353
- name: Mypy
5454
working-directory: ./kentik_api_library
5555
run: python3 setup.py mypy

kentik_api_library/pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ build-backend = "setuptools.build_meta"
55
[tool.black]
66
line-length = 120
77
target-version = ['py39']
8-
check = true
9-
fast = true
108

119
[tool.isort]
1210
line_length = 120

kentik_api_library/setup.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,25 @@ def run(self):
8383
class Black(Command):
8484
"""Custom command to run black"""
8585

86-
description = "run black on all relevant code; read configuration from pyproject.toml"
87-
user_options = []
86+
description = "run black on all relevant code"
87+
user_options = [("dirs=", None, "Directories to check with black"), ("check", None, "Run in check mode")]
8888

8989
def initialize_options(self) -> None:
90-
pass
90+
self.dirs = ["."]
91+
self.check = False
9192

9293
def finalize_options(self):
93-
pass
94+
"""Post-process options."""
95+
for d in self.dirs:
96+
assert os.path.exists(d), "Path {} does not exist.".format(d)
9497

9598
def run(self):
9699
"""Run command"""
97-
cmd = ["black", "."]
100+
cmd = ["black"]
101+
if self.check:
102+
cmd.append("--check")
103+
for d in self.dirs:
104+
cmd.append(d)
98105
run_cmd(cmd, self.announce)
99106

100107

0 commit comments

Comments
 (0)