From 3541e4ff4e639520124e2fc20851d557a2b8caf4 Mon Sep 17 00:00:00 2001 From: Arthur Meyre Date: Wed, 25 Aug 2021 18:24:24 +0200 Subject: [PATCH] fix(tools): various Makefile improvements - sync output recursively for make calls - add a script to get the number of cpus on mac and linux - Makefile formatting - update serialize_targets.sh to invoke the proper make binary - Add instructions to install make --- Makefile | 18 ++++++++++++------ docs/dev/GETTING-STARTED.md | 23 +++++++++++++++++++++++ script/make_utils/ncpus.sh | 7 +++++++ script/make_utils/serialize_targets.sh | 6 +++++- 4 files changed, 47 insertions(+), 7 deletions(-) create mode 100755 script/make_utils/ncpus.sh diff --git a/Makefile b/Makefile index 25741b9d2..0985de3b4 100644 --- a/Makefile +++ b/Makefile @@ -16,11 +16,13 @@ sync_env: .PHONY: sync_env python_format: - poetry run env bash ./script/source_format/format_python.sh --dir hdk --dir tests --dir benchmarks + poetry run env bash ./script/source_format/format_python.sh \ + --dir hdk --dir tests --dir benchmarks .PHONY: python_format check_python_format: - poetry run env bash ./script/source_format/format_python.sh --dir hdk --dir tests --dir benchmarks --check + poetry run env bash ./script/source_format/format_python.sh \ + --dir hdk --dir tests --dir benchmarks --check .PHONY: check_python_format check_strip_nb: @@ -28,7 +30,8 @@ check_strip_nb: .PHONY: strip_nb pylint: - +poetry run env bash script/make_utils/serialize_targets.sh pylint_src pylint_tests pylint_benchmarks + +poetry run env bash script/make_utils/serialize_targets.sh $(MAKE) \ + pylint_src pylint_tests pylint_benchmarks .PHONY: pylint pylint_src: @@ -46,7 +49,8 @@ pylint_benchmarks: .PHONY: pylint_benchmarks flake8: - poetry run flake8 --max-line-length 100 --per-file-ignores="__init__.py:F401" hdk/ tests/ benchmarks/ + poetry run flake8 --max-line-length 100 --per-file-ignores="__init__.py:F401" \ + hdk/ tests/ benchmarks/ .PHONY: flake8 python_linting: pylint flake8 @@ -56,7 +60,8 @@ conformance: strip_nb python_format .PHONY: conformance pcc: - @$(MAKE) --keep-going --jobs $$(nproc) --output-sync --no-print-directory pcc_internal + @$(MAKE) --keep-going --jobs $(./script/make_utils/ncpus.sh) --output-sync=recurse \ + --no-print-directory pcc_internal .PHONY: pcc pcc_internal: check_python_format check_strip_nb python_linting mypy_ci pydocstyle @@ -89,7 +94,8 @@ mypy_benchmark: # the parent make execution. We serialize calls to these targets as they may overwrite each others # cache which can cause issues. mypy_ci: - +poetry run env bash script/make_utils/serialize_targets.sh mypy mypy_test mypy_benchmark + +poetry run env bash script/make_utils/serialize_targets.sh $(MAKE) \ + mypy mypy_test mypy_benchmark .PHONY: mypy_ci pytest_and_coverage: pytest coverage diff --git a/docs/dev/GETTING-STARTED.md b/docs/dev/GETTING-STARTED.md index 2c8577131..8c05213f9 100644 --- a/docs/dev/GETTING-STARTED.md +++ b/docs/dev/GETTING-STARTED.md @@ -16,6 +16,29 @@ You can follow [this](https://realpython.com/installing-python/) guide to instal You can follow [this](https://python-poetry.org/docs/#installation) official guide to install it. +### Installing make + +The dev tools use make to launch the various commands. + +On Linux you can install make from your distribution's preferred package manager. + +On Mac OS you can install a more recent version of make via brew: + +```consol +# check for gmake +which gmake +# If you don't have it, it will error out, install gmake +brew install make +# recheck, now you should have gmake +which gmake +``` + +It is possible to install gmake as make, check this [StackOverflow post](https://stackoverflow.com/questions/38901894/how-can-i-install-a-newer-version-of-make-on-mac-os) for more infos. + +On Windows check [this GitHub gist](https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058#make). + +**/!\\ In the next sections, be sure to use the proper `make` tool for your system, `make`, `gmake` or other. /!\\** + ### Cloning repository Now, it's time to get the source code of `hdk`. You can use the following command to do that. diff --git a/script/make_utils/ncpus.sh b/script/make_utils/ncpus.sh new file mode 100755 index 000000000..2c8cfb618 --- /dev/null +++ b/script/make_utils/ncpus.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [[ `uname` == "Darwin" ]]; then + sysctl -n hw.logicalcpu +else + nproc +fi diff --git a/script/make_utils/serialize_targets.sh b/script/make_utils/serialize_targets.sh index 2b4b802af..c018ad80f 100755 --- a/script/make_utils/serialize_targets.sh +++ b/script/make_utils/serialize_targets.sh @@ -4,8 +4,12 @@ set +e EXIT_CODE=0 +# Get the make executable +MAKE="$1" +shift + for make_target in "$@"; do - make --no-print-directory "${make_target}" + "${MAKE}" --no-print-directory "${make_target}" if [[ "$?" != "0" ]]; then EXIT_CODE=1 fi