Centralize project commands to a Makefile

This commit is contained in:
coox 2020-05-10 16:32:10 +02:00
parent aa9aaad78c
commit 2f0f67d15a
3 changed files with 47 additions and 8 deletions

View file

@ -5,10 +5,10 @@
From the project root directory, execute the following command:
```sh
python ./manage.py test
make test
```
### How to maintain `requirements.txt`?
### How to maintain the Requirements File (`requirements.txt`)?
The canonical list of installation requirements (including development requirements) is maintained in the [`setup.py`](setup.py) file.
@ -17,7 +17,7 @@ The Requirements File ([`requirements.txt`](requirements.txt)) file must be kept
To to automatically generate or update `requirements.txt` based on `setup.py`, run [`pip-tools`](https://github.com/jazzband/pip-tools)s `pip-compile`:
```sh
python -m piptools compile --output-file=requirements.txt
make generate_requirements_file
```
**Warning:** Due to [limitations](https://github.com/jazzband/pip-tools/issues/908) in `pip-tools`, the same workflow can not be used for generating a `dev-requirements.txt` file, and requirements can not be declared in a `setup.cfg` file.
@ -25,7 +25,7 @@ python -m piptools compile --output-file=requirements.txt
### How to install modules required for development?
```sh
python -m pip install -e ".[dev]"
make install_dev
```
### How to run a code formatter?
@ -34,10 +34,10 @@ Run [Black](https://black.readthedocs.io/):
```sh
# Dry-run, showing what should be rewritten:
python -m black --target-version=py36 --diff .
make check_code_format
# Run code format:
python -m black --target-version=py36 .
make format_code
```
### How to run a linter?
@ -45,5 +45,5 @@ python -m black --target-version=py36 .
Run [Flake8](https://flake8.pycqa.org/):
```sh
python -m flake8
make lint
```

39
Makefile Normal file
View file

@ -0,0 +1,39 @@
.PHONY: \
clean \
check_code_format \
format_code \
generate_requirements_file \
install \
install_dev \
lint \
run \
test
clean:
# https://stackoverflow.com/a/41386937/162086
python3 -Bc "for p in __import__('pathlib').Path('.').rglob('*.py[co]'): p.unlink()"; \
python3 -Bc "for p in __import__('pathlib').Path('.').rglob('__pycache__'): p.rmdir()"
check_code_format:
python3 -m black --target-version=py36 --diff .
format_code:
python3 -m black --target-version=py36 .
generate_requirements_file:
python3 -m piptools compile --output-file=requirements.txt
install:
python3 -m pip install -r requirements.txt
install_dev:
python3 -m pip install -e ".[dev]"
lint:
python3 -m flake8
run:
python3 ./manage.py runserver --ipv6
test:
python3 ./manage.py test

View file

@ -7,5 +7,5 @@ A micro project proposed as a screening task for the [Senior Django Developer](h
On a system, or in a virtual environment where [Python](https://www.python.org/) version 3.6 or above, and [`pip`](https://pip.pypa.io/) and [`setuptools`](https://pypi.org/project/setuptools/) are available, run the following command to install required modules:
```sh
python -m pip install -r requirements.txt
make install
```