Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: Add lint-python which uses flake8 #21952

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,28 @@ lint-addon-docs: test/addons/.docbuildstamp
cpplint: lint-cpp
@echo "Please use lint-cpp instead of cpplint"

.PHONY: lint-py-build
# python -m pip install flake8
# Try with '--system' is to overcome systems that blindly set '--user'
lint-py-build:
@echo "Pip installing flake8 linter on $(shell $(PYTHON) --version)..."
$(PYTHON) -m pip install --upgrade -t tools/pip/site-packages flake8 || \
$(PYTHON) -m pip install --upgrade --system -t tools/pip/site-packages flake8

ifneq ("","$(wildcard tools/pip/site-packages)")
.PHONY: lint-py
# Lints the Python code with flake8.
# Flag the build if there are Python syntax errors or undefined names
lint-py:
PYTHONPATH=tools/pip $(PYTHON) -m flake8 . \
--count --show-source --statistics --select=E901,E999,F821,F822,F823 \
--exclude=deps,lib,src,tools/*_macros.py,tools/gyp,tools/jinja2,tools/pip
else
lint-py:
@echo "Python linting with flake8 is not avalible"
@echo "Run 'make lint-py-build'"
endif

.PHONY: lint
.PHONY: lint-ci
ifneq ("","$(wildcard tools/node_modules/eslint/)")
Expand All @@ -1221,7 +1243,7 @@ lint: ## Run JS, C++, MD and doc linters.
CONFLICT_RE=^>>>>>>> [0-9A-Fa-f]+|^<<<<<<< [A-Za-z]+

# Related CI job: node-test-linter
lint-ci: lint-js-ci lint-cpp lint-md lint-addon-docs
lint-ci: lint-js-ci lint-cpp lint-py lint-md lint-addon-docs
@if ! ( grep -IEqrs "$(CONFLICT_RE)" benchmark deps doc lib src test tools ) \
&& ! ( find . -maxdepth 1 -type f | xargs grep -IEqs "$(CONFLICT_RE)" ); then \
exit 0 ; \
Expand Down
2 changes: 2 additions & 0 deletions tools/pip/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
site-packages
3 changes: 3 additions & 0 deletions tools/pip/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os
import site
site.addsitedir(os.path.dirname(os.path.realpath(__file__)) + '/site-packages')