From 802e975c18ffbe77ef3724587bc133a5ef64b5fd Mon Sep 17 00:00:00 2001 From: Colin Dean Date: Tue, 30 Nov 2021 21:05:32 -0500 Subject: [PATCH] Adds a Makefile to facilitate common development tasks When working on #219, I found it repetitive to use history to invoke commands when I could just type "make" like I do in many other projects, including my Python projects. I extracted therefrom this minimalistic Makefile and added references to it in CONTRIBUTING. I also cleaned up some markup in CONTRIBUTING. --- CONTRIBUTING.md | 63 ++++++++++++++++++++++++++++++++----------------- Makefile | 35 +++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 Makefile diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 07d531a..5ebff7a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,19 +1,19 @@ # Contributing -We always like contributions here in ``peru``! +We always like contributions here in `peru`! First of all, if you're looking for something to work or you have some idea for a new feature or you found a bug, then check out our [issue tracker](https://github.com/buildinspace/peru/issues) for this. In the issue, discuss your idea and implementation. -Then if you want to make a contribution to ``peru`` then please raise a +Then if you want to make a contribution to `peru` then please raise a [Pull Request](https://github.com/buildinspace/peru/pulls) on GitHub. To help speed up the review process please ensure the following: - The PR addresses an open issue. -- The project passes linting with ``flake8 peru tests``. -- All tests are passing locally with (includes linting): ``python test.py``. +- The project passes linting with `make check` or `flake8 peru tests`. +- All tests are passing locally with (includes linting): `make test` or `python test.py`. - If adding a new feature you also add documentation. ## Developing @@ -24,14 +24,26 @@ To check out a local copy of the project you can [fork the project on GitHub](ht and then clone it locally. If you are using https, then you should adapt to it. ```bash - $ git clone git@github.com:yourusername/peru.git - $ cd peru +git clone git@github.com:yourusername/peru.git +cd peru ``` -This project uses ``flake8`` for linting. To configure your local environment please install these development dependencies. +This project uses `flake8` for linting. To configure your local environment, please install these development dependencies. +You may want to do this in a virtualenv; use `make venv` to create it in +`.venv` in the current directory. ```bash - $ pip install requirements-dev.txt +make deps-dev +# OR +pip install -r requirements-dev.txt +``` + +then you can run `flake8` with + +```bash +make check +# OR +flake8 peru tests ``` ## Testing @@ -39,33 +51,40 @@ This project uses ``flake8`` for linting. To configure your local environment p You can check that things are working correctly by calling the tests. ```bash - $ python test.py -v - test_safe_communicate (test_async.AsyncTest) ... ok - test_basic_export (test_cache.CacheTest) ... ok - . - . - . - test_assert_contents (test_test_shared.SharedTestCodeTest) ... ok - test_create_dir (test_test_shared.SharedTestCodeTest) ... ok - test_read_dir (test_test_shared.SharedTestCodeTest) ... ok +make test +# OR +python test.py -v +``` + +``` +$ python test.py -v +test_safe_communicate (test_async.AsyncTest) ... ok +test_basic_export (test_cache.CacheTest) ... ok +. +. +. +test_assert_contents (test_test_shared.SharedTestCodeTest) ... ok +test_create_dir (test_test_shared.SharedTestCodeTest) ... ok +test_read_dir (test_test_shared.SharedTestCodeTest) ... ok ---------------------------------------------------------------------- Ran 152 tests in 45.11s OK (skipped=1) -```` +``` + These checks will be run automatically when you make a pull request. You should always have a skipped test, because this is a platform specific tests. If you are working on a new feature please add tests to ensure the feature works as expected. If you are working on a bug fix then please add a test to ensure there is no regression. -Tests are stored in ``peru/tests`` and verify the current implementation to see how your test will fit in. +Tests are stored in `peru/tests` and verify the current implementation to see how your test will fit in. ## Making a Pull Request Once you have made your changes and are ready to make a Pull Request please ensure tests and linting pass locally before pushing to GitHub. -When making your Pull Request please include a short description of the changes, but more importantly why they are important. +When making your Pull Request please include a short description of the changes, but more importantly why they are important. Perhaps by writing a before and after paragraph with user examples. @@ -80,7 +99,7 @@ This PR includes a new feature that ... **Before** -If a user tried to pull a repository ... +If a user tried to pull a repository ... ```python > code example @@ -96,4 +115,4 @@ If a user tries to pull a repository now ... ``` ``` -After that you should wait the review and perform possible changes in the submitted code. \ No newline at end of file +After that you should wait the review and perform possible changes in the submitted code. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1c06d93 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +PYTHON ?= python3 +FLAKE8 ?= flake8 +PIP ?= pip3 + +VENV ?= .venv + +##@ Code Quality + +.PHONY: all +all: check test ## Run all checks and tests + +.PHONY: test +test: ## Run all tests + $(PYTHON) test.py -v + +.PHONY: check +check: ## Run all checks + $(FLAKE8) peru tests + +##@ Dev Env Setup + +.PHONY: venv +venv: ## Create a venv + $(PYTHON) -m venv --clear $(VENV) + @echo "Activate the venv with 'source $(VENV)/bin/activate'" + +.PHONY: deps-dev +deps-dev: ## Install development dependencies + $(PIP) install -r requirements-dev.txt + +##@ Utility + +.PHONY: help +help: ## Display this help + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[\#a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)