Skip to content

Commit

Permalink
Merge pull request #23 from devilbox/python-black
Browse files Browse the repository at this point in the history
Add Python Black
  • Loading branch information
cytopia authored Nov 27, 2022
2 parents 8e12fbc + dbdc85b commit 0592c8f
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Makefile.python
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ PYLINT_PIP_PKGS =
PYLINT_ARGS =
PYLINT_DIR = .

# Black
BLACK_VERSION = latest
BLACK_LINT_ARGS = --check --diff
BLACK_FIX_ARGS =
BLACK_DIR = .


# -------------------------------------------------------------------------------------------------
# Lint Targets
# -------------------------------------------------------------------------------------------------
.PHONY: lint
lint:: lint-mypy
lint:: lint-pylint
lint:: lint-black


.PHONY: lint-mypy
Expand All @@ -50,6 +57,32 @@ lint-pylint:
docker run --rm $$(tty -s && echo "-it" || echo) -e PIP_ROOT_USER_ACTION=ignore -v $$(pwd):/data -w /data --entrypoint=sh cytopia/pylint:$(PYLINT_VERSION) \
-c 'for pkg in $(PYLINT_PIP_PKGS); do python3 -m pip install $${pkg}; done && pylint $(PYLINT_ARGS) $(PYLINT_DIR)'

.PHONY: lint-black
lint-black: _lint-black-pull
lint-black:
@echo "################################################################################"
@echo "# Lint Python Black"
@echo "################################################################################"
docker run --rm $$(tty -s && echo "-it" || echo) -e PIP_ROOT_USER_ACTION=ignore -v $$(pwd):/data -w /data cytopia/black:$(BLACK_VERSION) \
$(BLACK_LINT_ARGS) \
$(BLACK_DIR)

# -------------------------------------------------------------------------------------------------
# Fix Targets
# -------------------------------------------------------------------------------------------------
.PHONY: fix
fix:: fix-black

fix-black: _lint-black-pull
fix-black:
@echo "################################################################################"
@echo "# Fix Python Black"
@echo "################################################################################"
docker run --rm $$(tty -s && echo "-it" || echo) -e PIP_ROOT_USER_ACTION=ignore -v $$(pwd):/data -w /data cytopia/black:$(BLACK_VERSION) \
$(BLACK_FIX_ARGS) \
$(BLACK_DIR)



# -------------------------------------------------------------------------------------------------
# Helper Targets
Expand Down Expand Up @@ -79,3 +112,16 @@ _lint-pylint-pull:
sleep 1; \
done; \
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;

.PHONY: _lint-black-pull
_lint-black-pull:
@echo "Pulling cytopia/black:$(BLACK_VERSION)"; \
SUCC=0; \
for i in $$(seq 10); do \
if docker pull -q cytopia/black:$(BLACK_VERSION); then \
SUCC=1; \
break; \
fi; \
sleep 1; \
done; \
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;

0 comments on commit 0592c8f

Please sign in to comment.