Skip to content

Commit

Permalink
Run isort and black via docker instead of installing in a virtualenv (c…
Browse files Browse the repository at this point in the history
…loudposse#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
  • Loading branch information
charlieparkes authored Jul 29, 2020
1 parent 2f44992 commit 07b147f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
26 changes: 12 additions & 14 deletions modules/python/Makefile.style
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
BLACK=$(call which,black)
ISORT=$(call which,isort)
FLAKE8=$(call which,flake8)
AUTOFLAKE=$(call which,autoflake)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions requirements.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
advbumpversion
black
flake8
isort
autoflake
docker-compose
bandit

0 comments on commit 07b147f

Please sign in to comment.