From 3cc93b9fac6fe6e7c02a4717b13b3a2ca0bbacb1 Mon Sep 17 00:00:00 2001 From: Ivan Ogasawara Date: Wed, 15 Nov 2023 15:40:51 -0400 Subject: [PATCH] chore(dev): Replace make by makim (#90) --- .github/workflows/main.yaml | 10 +- .makim.yaml | 186 ++++++++++++++++++++++++++++++++++++ Makefile | 182 ----------------------------------- docs/contributing.md | 4 +- poetry.lock | 47 ++++++++- pyproject.toml | 1 + 6 files changed, 239 insertions(+), 191 deletions(-) create mode 100644 .makim.yaml delete mode 100644 Makefile diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c281bf4..16060f9 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -20,7 +20,7 @@ jobs: cancel-in-progress: true env: - KXGR_PROJECT_NAME: ${{ matrix.python_version }}-${{ github.ref }} + KXGR_PROJECT_NAME: ${{ github.run_id }}-${{ github.sha }} steps: - uses: actions/checkout@v3 @@ -44,10 +44,10 @@ jobs: run: poetry install - name: run unit tests - run: make test + run: makim tests.unit --verbose - name: CLI tests - run: make smoke-tests + run: makim tests.smoke --verbose linter: runs-on: ubuntu-latest @@ -78,6 +78,4 @@ jobs: run: poetry install - name: Run style checks - run: | - pre-commit install - pre-commit run --all + run: makim tests.linter diff --git a/.makim.yaml b/.makim.yaml new file mode 100644 index 0000000..a402a05 --- /dev/null +++ b/.makim.yaml @@ -0,0 +1,186 @@ +version: 1.0.0 +shell: bash +groups: + clean: + env-file: .env + targets: + all: + help: Remove build artifacts, compiled files, and cache + run: | + rm -fr build/ + rm -fr dist/ + rm -fr .eggs/ + find . -name '*.egg-info' -exec rm -fr {} + + find . -name '*.egg' -exec rm -f {} + + find . -name '*.pyc' -exec rm -f {} + + find . -name '__pycache__' -exec rm -fr {} + + find . -name '*~' -exec rm -f {} + + rm -f .coverage + rm -fr htmlcov/ + rm -fr .pytest_cache + + docs: + help: Commands for building and previewing the documentation + targets: + build: + help: Build the documentation + run: mkdocs build --config-file docs/mkdocs.yaml + + preview: + help: Preview the documentation + dependencies: + - target: docs-build + run: mkdocs serve --watch docs --config-file docs/mkdocs.yam + + package: + help: helper commands for handling the package + targets: + build: + help: Build the project + run: poetry build + + tests: + help: Test commands + targets: + linter: + help: Run lint checks + run: | + pre-commit install + pre-commit run --all-files --verbose + + unit: + help: Run tests + args: + params: + help: Extra parameters for pytest + type: str + default: "-vv" + run: pytest -s {{ args.params }} tests + + smoke-1: + help: Run smoke tests for group 1 + dependencies: + - target: docker.killall + run: | + sugar build --verbose + sugar build --verbose --group group1 --all + sugar build --verbose --group group1 + sugar build --verbose --group group1 --services service1-1 + sugar pull --verbose --group group1 --all + sugar pull --verbose --group group1 + sugar pull --verbose --group group1 --services service1-1 + sugar ext start --verbose --group group1 --all --options -d + sugar ext restart --verbose --group group1 --all --options -d + sugar exec --verbose --group group1 --service service1-1 --options -T --cmd env + sugar stop --verbose --group group1 --all + sugar run --verbose --group group1 --service service1-1 --options -T --cmd env + sugar down --verbose --group group1 + + smoke-2: + help: Run smoke tests for group 2 + dependencies: + - target: docker.killall + run: | + sugar build --verbose --group group2 --all + sugar build --verbose --group group2 + sugar build --verbose --group group2 --services service2-1 + sugar pull --verbose --group group2 --all + sugar pull --verbose --group group2 + sugar pull --verbose --group group2 --services service2-1 + sugar ext start --verbose --group group2 --all --options -d + sugar ext restart --verbose --group group2 --all --options -d + sugar exec --verbose --group group2 --service service2-1 --options -T --cmd env + sugar stop --verbose --group group2 --all + sugar run --verbose --group group2 --service service2-1 --options -T --cmd env + sugar down --verbose --group group2 + + smoke-mix: + help: Run smoke tests for group mix + dependencies: + - target: docker.killall + run: | + sugar build --verbose --group group-mix --all + sugar build --verbose --group group-mix + sugar build --verbose --group group-mix --services service1-1,service2-1 + sugar pull --verbose --group group-mix --all + sugar pull --verbose --group group-mix + sugar pull --verbose --group group-mix --services service1-1,service2-1 + sugar ext start --verbose --group group-mix --all --options -d + sugar ext restart --verbose --group group-mix --all --options -d + sugar exec --verbose --group group-mix --service service2-1 --options -T --cmd env + sugar stop --verbose --group group-mix --all + sugar run --verbose --group group-mix --service service2-1 --options -T --cmd env + sugar down --verbose --group group-mix + + smoke-main: + help: Run smoke tests for group main + dependencies: + - target: docker.killall + run: | + # general tests main profile/plugins + sugar build --verbose --group group1 + sugar config --verbose --group group1 + sugar create --verbose --group group1 + sugar ext start --verbose --group group1 --options -d + sugar ext restart --verbose --group group1 --options -d + sugar exec --verbose --group group1 --service service1-1 --options -T --cmd env + sugar images --verbose --group group1 + sugar logs --verbose --group group1 + # port is not complete supported + # sugar port --verbose --group group1 --service service1-1 + sugar ps --verbose --group group1 + sugar pull --verbose --group group1 + sugar push --verbose --group group1 + sugar run --verbose --group group1 --service service1-1 --options -T --cmd env + sugar top --verbose --group group1 + sugar up --verbose --group group1 --options -d + sugar version --verbose + # port is not complete supported + # sugar events --verbose --group group1 --service service1-1 --options --json --dry-run + + smoke-defaults: + help: Run smoke tests for group defaults + dependencies: + - target: docker.killall + run: | + export KXGR_PROJECT_NAME="test-`python -c 'from uuid import uuid4; print(uuid4().hex[:7])'`" + echo $KXGR_PROJECT_NAME + sugar build --verbose --group group-defaults + sugar ext start --verbose --group group-defaults --options -d + sugar ext restart --verbose --group group-defaults --options -d + docker ps|grep $KXGR_PROJECT_NAME + sugar ext stop --verbose --group group-defaults + + smoke-final: + help: Run final smoke tests + dependencies: + - target: docker.killall + run: | + sugar ext restart --verbose --group group-defaults --options -d + sugar pause --verbose --group group1 + sugar unpause --verbose --group group1 + sugar kill --verbose --group group1 + sugar stop --verbose --group group1 + sugar rm --verbose --group group1 --options --force + sugar down --verbose --group group1 + + smoke: + help: Run final smoke tests + dependencies: + - target: docker.killall + - target: tests.smoke-1 + - target: tests.smoke-2 + - target: tests.smoke-mix + - target: tests.smoke-main + - target: tests.smoke-defaults + - target: tests.smoke-final + run: | + sugar --help + sugar --version + + docker: + help: Commands for docker + targets: + killall: + help: Kill all running Docker containers + run: docker kill `docker ps -q` || true diff --git a/Makefile b/Makefile deleted file mode 100644 index 55335f4..0000000 --- a/Makefile +++ /dev/null @@ -1,182 +0,0 @@ -.DEFAULT_GOAL := help - -define PRINT_HELP_PYSCRIPT -import re, sys - -for line in sys.stdin: - match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) - if match: - target, help = match.groups() - print("%-20s %s" % (target, help)) -endef -export PRINT_HELP_PYSCRIPT - -ARGS:= - -.PHONY:help -help: - @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) - -.PHONY:clean -clean: ## remove build artifacts, compiled files, and cache - rm -fr build/ - rm -fr dist/ - rm -fr .eggs/ - find . -name '*.egg-info' -exec rm -fr {} + - find . -name '*.egg' -exec rm -f {} + - find . -name '*.pyc' -exec rm -f {} + - find . -name - find . -name '__pycache__' -exec rm -fr '*.pyo' -exec rm -f {} + - find . -name '*~' -exec rm -f {} +{} + - rm -f .coverage - rm -fr htmlcov/ - rm -fr .pytest_cache - -.PHONY:lint -lint: - pre-commit run --all-files - - -.PHONY:test -test: ## run tests quickly with the default Python - pytest -s -vv tests ${ARGS} - - -.PHONY:docs-build -docs-build: - mkdocs build --config-file docs/mkdocs.yaml - -.PHONY: docs-preview -docs-preview: docs-build - mkdocs serve --watch docs --config-file docs/mkdocs.yaml - -.PHONY:build -build: - poetry build - - -# SMOKE TESTS - -.ONESHELL: -.PHONY: docker-killall -docker-killall: - set -ex - docker kill `docker ps -q` || true - set +ex - -.ONESHELL: -.PHONY: smoke-test-group-1 -smoke-test-group-1: docker-killall - set -ex - # group 1 - sugar build --verbose - sugar build --verbose --group group1 --all - sugar build --verbose --group group1 - sugar build --verbose --group group1 --services service1-1 - sugar pull --verbose --group group1 --all - sugar pull --verbose --group group1 - sugar pull --verbose --group group1 --services service1-1 - sugar ext start --verbose --group group1 --all --options -d - sugar ext restart --verbose --group group1 --all --options -d - sugar exec --verbose --group group1 --service service1-1 --options -T --cmd env - sugar stop --verbose --group group1 --all - sugar run --verbose --group group1 --service service1-1 --options -T --cmd env - sugar down --verbose --group group1 - set +ex - -.ONESHELL: -.PHONY: smoke-test-group-2 -smoke-test-group-2: docker-killall - set -ex - # group 2 - sugar build --verbose --group group2 --all - sugar build --verbose --group group2 - sugar build --verbose --group group2 --services service2-1 - sugar pull --verbose --group group2 --all - sugar pull --verbose --group group2 - sugar pull --verbose --group group2 --services service2-1 - sugar ext start --verbose --group group2 --all --options -d - sugar ext restart --verbose --group group2 --all --options -d - sugar exec --verbose --group group2 --service service2-1 --options -T --cmd env - sugar stop --verbose --group group2 --all - sugar run --verbose --group group2 --service service2-1 --options -T --cmd env - sugar down --verbose --group group2 - set +ex - -.ONESHELL: -.PHONY: smoke-test-group-mix -smoke-test-group-mix: docker-killall - set -ex - # group mix - sugar build --verbose --group group-mix --all - sugar build --verbose --group group-mix - sugar build --verbose --group group-mix --services service1-1,service2-1 - sugar pull --verbose --group group-mix --all - sugar pull --verbose --group group-mix - sugar pull --verbose --group group-mix --services service1-1,service2-1 - sugar ext start --verbose --group group-mix --all --options -d - sugar ext restart --verbose --group group-mix --all --options -d - sugar exec --verbose --group group-mix --service service2-1 --options -T --cmd env - sugar stop --verbose --group group-mix --all - sugar run --verbose --group group-mix --service service2-1 --options -T --cmd env - sugar down --verbose --group group-mix - set +ex - -.ONESHELL: -.PHONY: smoke-test-main -smoke-test-main: docker-killall - set -ex - # general tests main profile/plugins - sugar build --verbose --group group1 - sugar config --verbose --group group1 - sugar create --verbose --group group1 - sugar ext start --verbose --group group1 --options -d - sugar ext restart --verbose --group group1 --options -d - sugar exec --verbose --group group1 --service service1-1 --options -T --cmd env - sugar images --verbose --group group1 - sugar logs --verbose --group group1 - # port is not complete supported - # sugar port --verbose --group group1 --service service1-1 - sugar ps --verbose --group group1 - sugar pull --verbose --group group1 - sugar push --verbose --group group1 - sugar run --verbose --group group1 --service service1-1 --options -T --cmd env - sugar top --verbose --group group1 - sugar up --verbose --group group1 --options -d - sugar version --verbose - # port is not complete supported - # sugar events --verbose --group group1 --service service1-1 --options --json --dry-run - set +ex - - -.ONESHELL: -.PHONY: smoke-test-defaults -smoke-test-defaults: docker-killall - $(MAKE) docker-killall - set -ex - export KXGR_PROJECT_NAME="test-`python -c 'from uuid import uuid4; print(uuid4().hex[:7])'`" - echo $$KXGR_PROJECT_NAME - sugar build --verbose --group group-defaults - sugar ext start --verbose --group group-defaults --options -d - sugar ext restart --verbose --group group-defaults --options -d - docker ps|grep $$KXGR_PROJECT_NAME - sugar ext stop --verbose --group group-defaults - set +ex - -.ONESHELL: -.PHONY: smoke-final-tests -smoke-final-tests: docker-killall - # keep these ones at the end - sugar ext restart --verbose --group group-defaults --options -d - sugar pause --verbose --group group1 - sugar unpause --verbose --group group1 - sugar kill --verbose --group group1 - sugar stop --verbose --group group1 - sugar rm --verbose --group group1 --options --force - sugar down --verbose --group group1 - -.ONESHELL: -.PHONY: smoke-tests -smoke-tests: smoke-test-group-1 smoke-test-group-2 smoke-test-group-mix smoke-test-main smoke-test-defaults smoke-final-tests - sugar --help - sugar --version diff --git a/docs/contributing.md b/docs/contributing.md index 907e835..14ce28c 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -75,8 +75,8 @@ Ready to contribute? Here’s how to set up `containers-sugar` for local develop 5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:: - $ make lint - $ make test + $ makim tests.linter + $ makim tests.unit To get flake8 and tox, just pip install them into your virtualenv. diff --git a/poetry.lock b/poetry.lock index 4738494..ea05338 100644 --- a/poetry.lock +++ b/poetry.lock @@ -900,6 +900,25 @@ toml = "*" rst2md = ["sphinx-gallery (>=0.7.0,<0.8.0)"] toml = ["toml"] +[[package]] +name = "makim" +version = "1.8.3" +description = "Simplify the usage of containers" +optional = false +python-versions = ">=3.8.1,<4.0.0" +files = [ + {file = "makim-1.8.3-py3-none-any.whl", hash = "sha256:3bc87d53ea2b40aaa92e5e08645a62b145fb9020a4888dd48a76eef1a09bb0e6"}, + {file = "makim-1.8.3.tar.gz", hash = "sha256:d7db0a978aa634d40896043057df11ea908d982080365e409b173c3e35116369"}, +] + +[package.dependencies] +colorama = ">=0.4.6" +jinja2 = ">=2.0" +python-dotenv = ">=0.21.1" +pyyaml = ">=5.0" +sh = ">=2.0.0" +xonsh = ">=0.14.0" + [[package]] name = "markdown" version = "3.5.1" @@ -2548,6 +2567,32 @@ files = [ {file = "webencodings-0.5.1.tar.gz", hash = "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923"}, ] +[[package]] +name = "xonsh" +version = "0.14.0" +description = "Python-powered, cross-platform, Unix-gazing shell" +optional = false +python-versions = ">=3.8" +files = [ + {file = "xonsh-0.14.0-py310-none-any.whl", hash = "sha256:72506c6dc494103df6d04467e127abddb1c6cbe05cc5903b6a4cbfbad217ff5d"}, + {file = "xonsh-0.14.0-py311-none-any.whl", hash = "sha256:678a65671bd0a62cdc43e932d6aecc8b1622aa18942e0afb388b8b8ae02f67a5"}, + {file = "xonsh-0.14.0-py38-none-any.whl", hash = "sha256:25976edc5695fb5806b8b23f384ff48e618e07f4596ec0806007f63122917a83"}, + {file = "xonsh-0.14.0-py39-none-any.whl", hash = "sha256:751b615726d2322d43c8166ad4bc5cbe65d03a3728f1837aa02380fa9fadb189"}, + {file = "xonsh-0.14.0.tar.gz", hash = "sha256:45a8aaabb17ce0d6d4eca9b709ecfd7ce1c8fb92162decd29a45bf88a60e9bf1"}, +] + +[package.extras] +bestshell = ["prompt-toolkit (>=3.0.29)", "pygments (>=2.2)"] +dev = ["pre-commit", "re-ver", "tomli", "xonsh[doc,test]"] +doc = ["doctr", "furo", "livereload", "matplotlib", "myst-parser", "numpydoc", "psutil", "pyzmq", "runthis-sphinxext", "sphinx (>=3.1,<5)", "tornado", "xonsh[bestshell]"] +full = ["distro", "gnureadline", "setproctitle", "ujson", "xonsh[ptk,pygments]"] +linux = ["distro"] +mac = ["gnureadline"] +proctitle = ["setproctitle"] +ptk = ["prompt-toolkit (>=3.0.29)", "pyperclip"] +pygments = ["pygments (>=2.2)"] +test = ["coverage (>=5.3.1)", "prompt-toolkit (>=3.0.29)", "pygments (>=2.2)", "pyte (>=0.8.0)", "pytest (>=7)", "pytest-cov", "pytest-mock", "pytest-rerunfailures", "pytest-subprocess", "pytest-timeout", "restructuredtext-lint", "virtualenv (>=20.16.2)", "xonsh[bestshell]"] + [[package]] name = "zipp" version = "3.17.0" @@ -2566,4 +2611,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<3.12" -content-hash = "dd14c1255924aaa8990fbd65376a480317d6e5b5cfae40e1dd904503076dac00" +content-hash = "686e9e128dbadc6de6625dc2fcbea11483d2ff66d03fc767eb69c9a1c418696f" diff --git a/pyproject.toml b/pyproject.toml index b148825..387c394 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,6 +60,7 @@ mkdocs-macros-plugin = ">=0.6.3" mkdocs-material = ">=8.2.1" mkdocstrings = ">=0.17.0" compose-go = ">=1.23.0" +makim = "1.8.3" [build-system] requires = ["poetry-core>=1.0.0"]