Skip to content

Commit 317b85b

Browse files
committed
Pull in the actual code format and lint bits from PR497 (thanks @albu-diku) but
without applying any formatting yet. Minor adjustments to get the comments and 'exclude' layout I tried but clearly failed to fully explain in the review comments. I'd like to get the changes in before we diverge further and in order to add a more thorough lint target using pylint and ruff on top of black and isort.
1 parent eb7793a commit 317b85b

2 files changed

Lines changed: 46 additions & 22 deletions

File tree

Makefile

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ ifndef PY
66
PY = 3
77
endif
88

9-
FORMAT_ENFORCE_DIRS = state/
10-
FORMAT_EXCLUDE_REGEX = '.*'
11-
FORMAT_EXCLUDE_GLOB = '*'
12-
FORMAT_LINE_LENGTH = 80
13-
9+
# TODO: enable on these dirs when ready, but just leave to dummy init for now
10+
#LINT_ENFORCE_DIRS = ./bin ./mig/lib ./sbin ./tests
11+
LINT_ENFORCE_DIRS = ./mig/__init__.py
1412
LOCAL_PYTHON_BIN = './envhelp/lpython'
1513

1614
ifdef PYTHON_BIN
@@ -42,15 +40,11 @@ ifneq ($(MIG_ENV),'local')
4240
endif
4341
@make format-python
4442

45-
.PHONY:format-python
43+
# NOTE: black and isort use pyproject.toml to temporarily exclude a few paths
44+
.PHONY: format-python
4645
format-python:
47-
@$(LOCAL_PYTHON_BIN) -m black $(FORMAT_ENFORCE_DIRS) \
48-
--line-length=$(FORMAT_LINE_LENGTH) \
49-
--exclude=$(FORMAT_EXCLUDE_REGEX)
50-
@$(LOCAL_PYTHON_BIN) -m isort $(FORMAT_ENFORCE_DIRS) \
51-
--profile=black \
52-
--line-length=$(FORMAT_LINE_LENGTH) \
53-
--skip-glob=$(FORMAT_EXCLUDE_GLOB)
46+
@$(LOCAL_PYTHON_BIN) -m black $(LINT_ENFORCE_DIRS)
47+
@$(LOCAL_PYTHON_BIN) -m isort $(LINT_ENFORCE_DIRS)
5448

5549
.PHONY: lint
5650
lint:
@@ -60,17 +54,11 @@ ifneq ($(MIG_ENV),'local')
6054
endif
6155
@make lint-python
6256

57+
# NOTE: black and isort use pyproject.toml to temporarily exclude a few paths
6358
.PHONY: lint-python
6459
lint-python:
65-
@$(LOCAL_PYTHON_BIN) -m black $(FORMAT_ENFORCE_DIRS) \
66-
--check \
67-
--line-length=$(FORMAT_LINE_LENGTH) \
68-
--exclude $(FORMAT_EXCLUDE_REGEX)
69-
@$(LOCAL_PYTHON_BIN) -m isort $(FORMAT_ENFORCE_DIRS) \
70-
--check-only \
71-
--profile=black \
72-
--line-length=$(FORMAT_LINE_LENGTH) \
73-
--skip-glob=$(FORMAT_EXCLUDE_GLOB)
60+
@$(LOCAL_PYTHON_BIN) -m black $(LINT_ENFORCE_DIRS) --check
61+
@$(LOCAL_PYTHON_BIN) -m isort $(LINT_ENFORCE_DIRS) --check-only
7462

7563
.PHONY: clean
7664
clean:

pyproject.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Project wide settings including tooling.
2+
3+
# Linting tools
4+
# TODO: fix CodeQL errors in symlinked files and disable extend-exclude+skip
5+
6+
[tool.black]
7+
line-length = 80
8+
exclude = '''
9+
tests/data/
10+
| tests/fixture/
11+
'''
12+
# NOTE: the following regex matches must be kept in sync with isort skip
13+
extend-exclude = '''
14+
bin/checkconf.py
15+
| bin/createresource.py
16+
| bin/notifypassword.py
17+
| sbin/grid_ftps.py
18+
| sbin/grid_openid.py
19+
| sbin/grid_sftp.py
20+
| sbin/grid_webdavs.py
21+
'''
22+
23+
[tool.isort]
24+
profile = "black"
25+
line_length = 80
26+
# NOTE: the following paths must be kept in sync with black extend-exclude
27+
skip = [
28+
"bin/checkconf.py",
29+
"bin/createresource.py",
30+
"bin/notifypassword.py",
31+
"sbin/grid_ftps.py",
32+
"sbin/grid_openid.py",
33+
"sbin/grid_sftp.py",
34+
"sbin/grid_webdavs.py"
35+
]
36+
skip_glob = [".git/*", "tests/data/*", "tests/fixture/*"]

0 commit comments

Comments
 (0)