Skip to content

Commit b8f3bb1

Browse files
cclausstargos
cclauss
authored andcommitted
build: add lint-py which uses flake8
PR-URL: #21952 Reviewed-By: Refael Ackermann <[email protected]>
1 parent 0f00ac9 commit b8f3bb1

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Makefile

+23-1
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,28 @@ lint-addon-docs: test/addons/.docbuildstamp
12081208
cpplint: lint-cpp
12091209
@echo "Please use lint-cpp instead of cpplint"
12101210

1211+
.PHONY: lint-py-build
1212+
# python -m pip install flake8
1213+
# Try with '--system' is to overcome systems that blindly set '--user'
1214+
lint-py-build:
1215+
@echo "Pip installing flake8 linter on $(shell $(PYTHON) --version)..."
1216+
$(PYTHON) -m pip install --upgrade -t tools/pip/site-packages flake8 || \
1217+
$(PYTHON) -m pip install --upgrade --system -t tools/pip/site-packages flake8
1218+
1219+
ifneq ("","$(wildcard tools/pip/site-packages)")
1220+
.PHONY: lint-py
1221+
# Lints the Python code with flake8.
1222+
# Flag the build if there are Python syntax errors or undefined names
1223+
lint-py:
1224+
PYTHONPATH=tools/pip $(PYTHON) -m flake8 . \
1225+
--count --show-source --statistics --select=E901,E999,F821,F822,F823 \
1226+
--exclude=deps,lib,src,tools/*_macros.py,tools/gyp,tools/jinja2,tools/pip
1227+
else
1228+
lint-py:
1229+
@echo "Python linting with flake8 is not avalible"
1230+
@echo "Run 'make lint-py-build'"
1231+
endif
1232+
12111233
.PHONY: lint
12121234
.PHONY: lint-ci
12131235
ifneq ("","$(wildcard tools/node_modules/eslint/)")
@@ -1221,7 +1243,7 @@ lint: ## Run JS, C++, MD and doc linters.
12211243
CONFLICT_RE=^>>>>>>> [0-9A-Fa-f]+|^<<<<<<< [A-Za-z]+
12221244

12231245
# Related CI job: node-test-linter
1224-
lint-ci: lint-js-ci lint-cpp lint-md lint-addon-docs
1246+
lint-ci: lint-js-ci lint-cpp lint-py lint-md lint-addon-docs
12251247
@if ! ( grep -IEqrs "$(CONFLICT_RE)" benchmark deps doc lib src test tools ) \
12261248
&& ! ( find . -maxdepth 1 -type f | xargs grep -IEqs "$(CONFLICT_RE)" ); then \
12271249
exit 0 ; \

tools/pip/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pyc
2+
site-packages

tools/pip/sitecustomize.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import os
2+
import site
3+
site.addsitedir(os.path.dirname(os.path.realpath(__file__)) + '/site-packages')

0 commit comments

Comments
 (0)