Skip to content

Commit

Permalink
Env aware makefile (rochacbruno#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno authored Aug 16, 2021
1 parent 71cca9a commit 974a5ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/templates/flask/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is a Flask application.
From source:

```bash
git clone https://github.com/author_name/project_urlname
git clone https://github.com/author_name/project_urlname project_name
cd project_name
make install
```
Expand Down
2 changes: 2 additions & 0 deletions .github/templates/flask/apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ else
fi

# Move module files
rm -rf project_name
rm -rf tests
cp -R .github/templates/flask/module project_name
cp -R .github/templates/flask/tests tests

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Pip
run: pip install --user --upgrade pip
- name: Install project
run: pip install -e .[test]
- name: run tests
Expand Down
38 changes: 24 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.ONESHELL:
ENV_PREFIX=$(shell python -c "if __import__('pathlib').Path('.venv/bin/pip').exists(): print('.venv/bin/')")

.PHONY: help
help: ## Show the help.
Expand All @@ -7,32 +8,41 @@ help: ## Show the help.
@echo "Targets:"
@fgrep "##" Makefile | fgrep -v fgrep


.PHONY: show
show: ## Show the current environment.
@echo "Current environment:"
@echo "Running using $(ENV_PREFIX)"
@$(ENV_PREFIX)python -V
@$(ENV_PREFIX)python -m site

.PHONY: install
install: ## Install the project in dev mode.
@if [ ! -f pyproject.toml ]; then pip install -e .[test]; else poetry install --dev; fi
@echo "Don't forget to run 'make virtualenv' if you got errors."
@if [ ! -f pyproject.toml ]; then $(ENV_PREFIX)pip install -e .[test]; else poetry install --dev; fi

.PHONY: fmt
fmt: ## Format code using black & isort.
isort project_name/
black -l 79 project_name/
black -l 79 tests/
$(ENV_PREFIX)isort project_name/
$(ENV_PREFIX)black -l 79 project_name/
$(ENV_PREFIX)black -l 79 tests/

.PHONY: lint
lint: ## Run pep8, black, mypy linters.
flake8 project_name/
black -l 79 --check project_name/
black -l 79 --check tests/
mypy project_name/
$(ENV_PREFIX)flake8 project_name/
$(ENV_PREFIX)black -l 79 --check project_name/
$(ENV_PREFIX)black -l 79 --check tests/
$(ENV_PREFIX)mypy project_name/

.PHONY: test
test: lint ## Run tests and generate coverage report.
pytest -v --cov-config .coveragerc --cov=project_name -l --tb=short --maxfail=1 tests/
coverage xml
coverage html
$(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=project_name -l --tb=short --maxfail=1 tests/
$(ENV_PREFIX)coverage xml
$(ENV_PREFIX)coverage html

.PHONY: watch
watch: ## Run tests on every change.
ls **/**.py | entr pytest -s -vvv -l --tb=long --maxfail=1 tests/
ls **/**.py | entr $(ENV_PREFIX)pytest -s -vvv -l --tb=long --maxfail=1 tests/

.PHONY: clean
clean: ## Clean unused files.
Expand Down Expand Up @@ -67,7 +77,7 @@ release: ## Create a new tag for release.
@echo "creating git tag : $${TAG}"
@git tag $${TAG}
@echo "$${TAG}" > project_name/VERSION
@gitchangelog > HISTORY.md
@$(ENV_PREFIX)gitchangelog > HISTORY.md
@git add project_name/VERSION HISTORY.md
@git commit -m "release: version $${TAG} 🚀"
@git push -u origin HEAD --tags
Expand All @@ -76,7 +86,7 @@ release: ## Create a new tag for release.
.PHONY: docs
docs: ## Build the documentation.
@echo "building documentation ..."
@mkdocs build
@$(ENV_PREFIX)mkdocs build
URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL

.PHONY: switch-to-poetry
Expand Down

0 comments on commit 974a5ca

Please sign in to comment.