Skip to content

Commit

Permalink
Merge pull request #112 from kbalk/fix-git-ls
Browse files Browse the repository at this point in the history
pylint and black find no python files outside of tardigrade-ci
  • Loading branch information
kbalk authored Dec 11, 2020
2 parents 76ebb7f + 927d3b6 commit 0181028
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.0
current_version = 0.3.0
commit = True
message = Bumps version to {new_version}
tag = False
Expand Down
19 changes: 10 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,31 +178,32 @@ cfn/lint: | guard/program/cfn-lint
## Runs eclint against the project
eclint/lint: | guard/program/eclint guard/program/git
eclint/lint: HAS_UNTRACKED_CHANGES ?= $(shell cd $(PROJECT_ROOT) && git status -s)
eclint/lint: ECLINT_FILES ?= git ls-files -z
eclint/lint: ECLINT_FILES ?= $(shell git -C $(PROJECT_ROOT) ls-files -z | grep -zv ".bats" | xargs -0)
eclint/lint:
@ echo "[$@]: Running eclint..."
cd $(PROJECT_ROOT) && \
[ -z "$(HAS_UNTRACKED_CHANGES)" ] || (echo "untracked changes detected!" && exit 1)
cd $(PROJECT_ROOT) && \
$(ECLINT_FILES) | grep -zv ".bats" | xargs -0 -I {} eclint check {}
eclint check $(ECLINT_FILES)
@ echo "[$@]: Project PASSED eclint test!"

python/%: PYTHON_FILES ?= git ls-files --cached --others --exclude-standard '*.py'
python/%: PYTHON_FILES ?= $(shell git -C $(PROJECT_ROOT) ls-files --cached --others --exclude-standard '*.py' | xargs --no-run-if-empty printf "$(PROJECT_ROOT)/%s ")
## Checks format and lints Python files. Runs pylint on each individual
## file and uses a custom format for the lint messages.
python/lint: | guard/program/pylint guard/program/black guard/program/git
python/lint:
@ echo "[$@]: Linting Python files..."
$(PYTHON_FILES) | xargs black --check
$(PYTHON_FILES) | $(XARGS) -n1 pylint -rn -sn \
--msg-template="{path}:{line} [{symbol}] {msg}" {}
@ echo "[$@]: Python files PASSED lint test!"
black --check $(PYTHON_FILES)
for python_file in $(PYTHON_FILES); do \
pylint --msg-template="{path}:{line} [{symbol}] {msg}" \
-rn -sn $$python_file; \
done
echo "[$@]: Python files PASSED lint test!"

## Formats Python files.
python/format: | guard/program/black guard/program/git
python/format:
@ echo "[$@]: Formatting Python files..."
$(PYTHON_FILES) | xargs black
black $(PYTHON_FILES)
@ echo "[$@]: Successfully formatted Python files!"

## Lints terraform files
Expand Down
4 changes: 2 additions & 2 deletions tests/make/eclint_lint_success.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ done

git add "$TEST_DIR/."
git commit -m 'eclint success testing'

}

@test "eclint/lint: success" {
run make eclint/lint
ECLINT_FILES=$(find "${TEST_DIR}" -type f | xargs echo)
run make eclint/lint ECLINT_FILES="${ECLINT_FILES}"
[ "$status" -eq 0 ]
}

Expand Down
4 changes: 4 additions & 0 deletions tests/make/python_format_success.bats
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ done
run make python/format
[ "$status" -eq 0 ]
[[ "$output" == *"[python/format]: Successfully formatted Python files!"* ]]

run make python/format PYTHON_FILES="$TEST_DIR/nested/*.py"
[ "$status" -eq 0 ]
[[ "$output" == *"1 file left unchanged"* ]]
}

function teardown() {
Expand Down

0 comments on commit 0181028

Please sign in to comment.