From 07b147f6709f5e655dd57531aa87cba34a1dac21 Mon Sep 17 00:00:00 2001 From: Charlie Date: Wed, 29 Jul 2020 10:44:00 -0500 Subject: [PATCH] Run isort and black via docker instead of installing in a virtualenv (#60) * Run isort via docker instead of installing in a virtualenv * Run black via docker to avoid installing it in a virtualenv * Set user uid:gid when running python formatting via docker --- modules/python/Makefile.style | 26 ++++++++++++-------------- requirements.template | 2 -- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/modules/python/Makefile.style b/modules/python/Makefile.style index c4303a17..7c0aeae8 100644 --- a/modules/python/Makefile.style +++ b/modules/python/Makefile.style @@ -1,5 +1,3 @@ -BLACK=$(call which,black) -ISORT=$(call which,isort) FLAKE8=$(call which,flake8) AUTOFLAKE=$(call which,autoflake) @@ -45,29 +43,29 @@ python/autoflake: bh/venv .PHONY: python/isort/check ## Check python imports using isort -python/isort/check: bh/venv - $(call assert-set,ISORT) +python/isort/check: + @$(DOCKER) pull -q alphachai/isort @$(MAKE) python/lint/announce/isort - @$(ISORT) $(ISORT_FLAGS) --check-only $(PYTHON_LINT_TARGETS) --diff + @$(DOCKER) run -it --rm --user $(id -u):$(id -g) --mount type=bind,src=$$(pwd),dst=/app alphachai/isort $(ISORT_FLAGS) --check-only $(PYTHON_LINT_TARGETS) --diff .PHONY: python/isort ## Fix python imports using isort -python/isort: bh/venv - $(call assert-set,ISORT) - $(ISORT) $(ISORT_FLAGS) $(PYTHON_LINT_TARGETS) +python/isort: + @$(DOCKER) pull -q alphachai/isort + $(DOCKER) run -it --rm --user $(id -u):$(id -g) --mount type=bind,src=$$(pwd),dst=/app alphachai/isort $(ISORT_FLAGS) $(PYTHON_LINT_TARGETS) .PHONY: python/black/check ## Check python files using black -python/black/check: bh/venv - $(call assert-set,BLACK) +python/black/check: + @$(DOCKER) pull -q alphachai/black @$(MAKE) python/lint/announce/black - @$(BLACK) --check $(PYTHON_LINT_TARGETS) + @$(DOCKER) run -it --rm --user $(id -u):$(id -g) --mount type=bind,src=$$(pwd),dst=/app alphachai/black --check $(PYTHON_LINT_TARGETS) .PHONY: python/black ## Reformat python files using black -python/black: bh/venv - $(call assert-set,BLACK) - $(BLACK) $(PYTHON_LINT_TARGETS) +python/black: + @$(DOCKER) pull -q alphachai/black + $(DOCKER) run -it --rm --user $(id -u):$(id -g) --mount type=bind,src=$$(pwd),dst=/app alphachai/black $(PYTHON_LINT_TARGETS) .PHONY: python/flake8 ## Check python style against pep8 using flake8 diff --git a/requirements.template b/requirements.template index 9b7698e6..8fe425a3 100644 --- a/requirements.template +++ b/requirements.template @@ -1,7 +1,5 @@ advbumpversion -black flake8 -isort autoflake docker-compose bandit