Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.

Commit 974a5ca

Browse files
authored
Env aware makefile (#6)
1 parent 71cca9a commit 974a5ca

4 files changed

Lines changed: 29 additions & 15 deletions

File tree

.github/templates/flask/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is a Flask application.
77
From source:
88

99
```bash
10-
git clone https://github.com/author_name/project_urlname
10+
git clone https://github.com/author_name/project_urlname project_name
1111
cd project_name
1212
make install
1313
```

.github/templates/flask/apply.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ else
1818
fi
1919

2020
# Move module files
21+
rm -rf project_name
22+
rm -rf tests
2123
cp -R .github/templates/flask/module project_name
2224
cp -R .github/templates/flask/tests tests
2325

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ jobs:
8484
- uses: actions/setup-python@v2
8585
with:
8686
python-version: ${{ matrix.python-version }}
87+
- name: Install Pip
88+
run: pip install --user --upgrade pip
8789
- name: Install project
8890
run: pip install -e .[test]
8991
- name: run tests

Makefile

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.ONESHELL:
2+
ENV_PREFIX=$(shell python -c "if __import__('pathlib').Path('.venv/bin/pip').exists(): print('.venv/bin/')")
23

34
.PHONY: help
45
help: ## Show the help.
@@ -7,32 +8,41 @@ help: ## Show the help.
78
@echo "Targets:"
89
@fgrep "##" Makefile | fgrep -v fgrep
910

11+
12+
.PHONY: show
13+
show: ## Show the current environment.
14+
@echo "Current environment:"
15+
@echo "Running using $(ENV_PREFIX)"
16+
@$(ENV_PREFIX)python -V
17+
@$(ENV_PREFIX)python -m site
18+
1019
.PHONY: install
1120
install: ## Install the project in dev mode.
12-
@if [ ! -f pyproject.toml ]; then pip install -e .[test]; else poetry install --dev; fi
21+
@echo "Don't forget to run 'make virtualenv' if you got errors."
22+
@if [ ! -f pyproject.toml ]; then $(ENV_PREFIX)pip install -e .[test]; else poetry install --dev; fi
1323

1424
.PHONY: fmt
1525
fmt: ## Format code using black & isort.
16-
isort project_name/
17-
black -l 79 project_name/
18-
black -l 79 tests/
26+
$(ENV_PREFIX)isort project_name/
27+
$(ENV_PREFIX)black -l 79 project_name/
28+
$(ENV_PREFIX)black -l 79 tests/
1929

2030
.PHONY: lint
2131
lint: ## Run pep8, black, mypy linters.
22-
flake8 project_name/
23-
black -l 79 --check project_name/
24-
black -l 79 --check tests/
25-
mypy project_name/
32+
$(ENV_PREFIX)flake8 project_name/
33+
$(ENV_PREFIX)black -l 79 --check project_name/
34+
$(ENV_PREFIX)black -l 79 --check tests/
35+
$(ENV_PREFIX)mypy project_name/
2636

2737
.PHONY: test
2838
test: lint ## Run tests and generate coverage report.
29-
pytest -v --cov-config .coveragerc --cov=project_name -l --tb=short --maxfail=1 tests/
30-
coverage xml
31-
coverage html
39+
$(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=project_name -l --tb=short --maxfail=1 tests/
40+
$(ENV_PREFIX)coverage xml
41+
$(ENV_PREFIX)coverage html
3242

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

3747
.PHONY: clean
3848
clean: ## Clean unused files.
@@ -67,7 +77,7 @@ release: ## Create a new tag for release.
6777
@echo "creating git tag : $${TAG}"
6878
@git tag $${TAG}
6979
@echo "$${TAG}" > project_name/VERSION
70-
@gitchangelog > HISTORY.md
80+
@$(ENV_PREFIX)gitchangelog > HISTORY.md
7181
@git add project_name/VERSION HISTORY.md
7282
@git commit -m "release: version $${TAG} 🚀"
7383
@git push -u origin HEAD --tags
@@ -76,7 +86,7 @@ release: ## Create a new tag for release.
7686
.PHONY: docs
7787
docs: ## Build the documentation.
7888
@echo "building documentation ..."
79-
@mkdocs build
89+
@$(ENV_PREFIX)mkdocs build
8090
URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL
8191

8292
.PHONY: switch-to-poetry

0 commit comments

Comments
 (0)