Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Add help command to Makefile #42

Merged
merged 2 commits into from
Mar 6, 2020
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
30 changes: 16 additions & 14 deletions tests/test_makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ def test_makefile_total_lines(cookies, context, black, pipenv, mypy):
We expect Makefile has below content
```
1 .PHONY: check
2 check:
3 isort
4 black
5
6 .PHONY: format
7 format:
8 isort
9 black
2 ## check: check if everything's okay
3 check:
4 isort
5 black
6
7 .PHONY: format
8 ## format: format files
9 format:
10 isort
11 black
```
"""
ctx = context(black=black, pipenv=pipenv, mypy=mypy)
Expand All @@ -27,10 +29,10 @@ def test_makefile_total_lines(cookies, context, black, pipenv, mypy):
makefile = result.project.join('Makefile')
lines = makefile.readlines(cr=False)

expected = 31
expected = 43
expected -= 2 if black == 'n' else 0
expected -= 1 if mypy == 'do not use' else 0
expected += 5 if pipenv == 'y' else 0
expected += 6 if pipenv == 'y' else 0
assert len(lines) == expected


Expand All @@ -45,8 +47,8 @@ def test_makefile_total_section(cookies, context, black, pipenv, mypy):
content = makefile.read()
sections = content.strip().split('\n\n')

expected = 7
expected -= 1 if pipenv == 'n' else 0
expected = 8 # init,check,format,test,coverage,htmlcov,requirements,help
expected -= 1 if pipenv == 'n' else 0 # requirements
assert len(sections) == expected


Expand All @@ -59,6 +61,6 @@ def test_makefile_phony(cookies, context, pipenv):

phonies = re.findall(r'\.PHONY: (\w+)', makefile.read())

expected = 7
expected -= 1 if pipenv == 'n' else 0
expected = 8 # init,check,format,test,coverage,htmlcov,requirements,help
expected -= 1 if pipenv == 'n' else 0 # requirements
assert len(set(phonies)) == expected
13 changes: 13 additions & 0 deletions {{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.PHONY: init
## init: install requirements
init:
{%- if cookiecutter.use_pipenv|lower != 'n' %}
pip install pipenv
Expand All @@ -9,6 +10,7 @@ init:
{%- endif %}

.PHONY: check
## check: check if everything's okay
check:
isort --recursive --check-only {{ cookiecutter.package_name }} tests
{%- if cookiecutter.use_black|lower != 'n' %}
Expand All @@ -20,21 +22,25 @@ check:
{%- endif %}

.PHONY: format
## format: format files
format:
isort -rc -y {{ cookiecutter.package_name }} tests
{%- if cookiecutter.use_black|lower != 'n' %}
black -S -l 79 {{ cookiecutter.package_name }} tests
{%- endif %}

.PHONY: test
## test: run tests
test:
python -m pytest

.PHONY: coverage
## coverage: run tests with coverage
coverage:
python -m pytest --cov {{ cookiecutter.package_name }} --cov-report term --cov-report xml

.PHONY: htmlcov
## htmlcov: run tests with coverage and create coverage report HTML files
htmlcov:
python -m pytest --cov {{ cookiecutter.package_name }} --cov-report html
rm -rf /tmp/htmlcov && mv htmlcov /tmp/
Expand All @@ -43,7 +49,14 @@ htmlcov:
{%- if cookiecutter.use_pipenv|lower != 'n' %}

.PHONY: requirements
## requirements: update requirements.txt
requirements:
pipenv lock -r > requirements.txt
pipenv lock -dr > requirements-dev.txt
{%- endif %}

.PHONY: help
## help: prints this help message
help:
@echo "Usage: \n"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':'