Skip to content

Commit

Permalink
update Makefile and tox.ini from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Xav Paice committed Aug 5, 2020
1 parent 0b4a4f1 commit c5a5bd2
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 58 deletions.
47 changes: 38 additions & 9 deletions .gitignore
@@ -1,12 +1,41 @@
*.swp
*~
.idea
# Juju files
.unit-state.db
.go-cookies

layers/*
interfaces/*

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Tests files and dir
.pytest_cache/
.coverage
.tox
.vscode
/builds/
/deb_dist
/dist
/repo-info
__pycache__
report/
htmlcov/

# Log files
*.log

# pycharm
.idea/

# vi
.*.swp

# version data
repo-info
version

# Python builds
deb_dist/
dist/

# Snaps
*.snap

# Builds
.build/
92 changes: 61 additions & 31 deletions Makefile
@@ -1,50 +1,80 @@
PYTHON := /usr/bin/python3

PROJECTPATH=$(dir $(realpath $(MAKEFILE_LIST)))
ifndef CHARM_BUILD_DIR
CHARM_BUILD_DIR := /tmp/charm-builds
export CHARM_BUILD_DIR
$(warning Warning CHARM_BUILD_DIR was not set, defaulting to $(CHARM_BUILD_DIR))
CHARM_BUILD_DIR=${PROJECTPATH}.build
endif
ifndef CHARM_LAYERS_DIR
CHARM_LAYERS_DIR=${PROJECTPATH}/layers
endif
ifndef CHARM_INTERFACES_DIR
CHARM_INTERFACES_DIR=${PROJECTPATH}/interfaces
endif
METADATA_FILE="src/metadata.yaml"
CHARM_NAME=$(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E "^name:" | awk '{print $$2}')

help:
@echo "This project supports the following targets"
@echo ""
@echo " make help - show this text"
@echo " make lint - run flake8"
@echo " make test - run all tests: lint, unit and func tests"
@echo " make unittest - run the tests defined in the unittest subdirectory"
@echo " make functional - run the tests defined in the functional subdirectory"
@echo " make release - build the charm"
@echo " make clean - remove unneeded files"
@echo " make submodules - make sure that the submodules are up-to-date"
@echo " make submodules-update - update submodules to latest changes on remote branch"
@echo " make build - build the charm"
@echo " make release - run clean, submodules, and build targets"
@echo " make lint - run flake8 and black --check"
@echo " make black - run black and reformat files"
@echo " make proof - run charm proof"
@echo " make unittests - run the tests defined in the unittest subdirectory"
@echo " make functional - run the tests defined in the functional subdirectory"
@echo " make test - run lint, proof, unittests and functional targets"
@echo ""

lint:
@echo "Running flake8"
@tox -e lint

test: lint unittest functional
clean:
@echo "Cleaning files"
@git clean -ffXd -e '!.idea'
@echo "Cleaning existing build"
@rm -rf ${CHARM_BUILD_DIR}/${CHARM_NAME}

unittest:
@tox -e unit
submodules:
@echo "Cloning submodules"
@git submodule update --init --recursive

functional: build
@PYTEST_KEEP_MODEL=$(PYTEST_KEEP_MODEL) \
PYTEST_CLOUD_NAME=$(PYTEST_CLOUD_NAME) \
PYTEST_CLOUD_REGION=$(PYTEST_CLOUD_REGION) \
tox -e functional
submodules-update:
@echo "Pulling latest updates for submodules"
@git submodule update --init --recursive --remote --merge

build:
@echo "Building charm to base directory $(CHARM_BUILD_DIR)/advanced-routing"
# @-git describe --tags > ./repo-info
@CHARM_LAYERS_DIR=./layers CHARM_INTERFACES_DIR=./interfaces TERM=linux \
charm build --build-dir=$(CHARM_BUILD_DIR) . --force
@echo "Building charm to directory ${CHARM_BUILD_DIR}/${CHARM_NAME}"
@-git rev-parse --abbrev-ref HEAD > ./src/repo-info
@CHARM_LAYERS_DIR=${CHARM_LAYERS_DIR} CHARM_INTERFACES_DIR=${CHARM_INTERFACES_DIR} \
TERM=linux CHARM_BUILD_DIR=${CHARM_BUILD_DIR} charm build src/

release: clean build
@echo "Charm is built at $(JUJU_REPOSITORY)/builds"
@echo "Charm is built at ${CHARM_BUILD_DIR}/${CHARM_NAME}"

clean:
@echo "Cleaning files"
@if [ -d .tox ] ; then rm -r .tox ; fi
@if [ -d .pytest_cache ] ; then rm -r .pytest_cache ; fi
@find . -type d -name '__pycache__' -prune -exec rm -rf "{}"
lint:
@echo "Running lint checks"
@cd src && tox -e lint

black:
@echo "Reformat files with black"
@cd src && tox -e black

proof:
@echo "Running charm proof"
@charm proof src

unittests:
@echo "Running unit tests"
@cd src && tox -e unit

functional: build
@echo "Executing functional tests in ${CHARM_BUILD_DIR}"
@cd src && CHARM_BUILD_DIR=${CHARM_BUILD_DIR} tox -e func

test: lint proof unittests functional
@echo "Tests completed for charm ${CHARM_NAME}."

# The targets below don't depend on a file
.PHONY: lint test unittest functional build release clean help
.PHONY: help submodules submodules-update clean build release lint black proof unittests functional test
60 changes: 42 additions & 18 deletions tox.ini
@@ -1,35 +1,33 @@
[tox]
skipsdist=True
envlist = unit, functional
skip_missing_interpreters = True
envlist = lint, unit, func

[testenv]
basepython = python3
setenv =
PYTHONPATH = .

[testenv:unit]
commands = pytest -o log_cli=true --full-trace -v --ignore {toxinidir}/tests/functional
deps = -r{toxinidir}/tests/unit/requirements.txt
-r{toxinidir}/requirements.txt
setenv = PYTHONPATH={toxinidir}/lib:{toxinidir}/actions
whitelist_externals = pytest

[testenv:functional]
PYTHONPATH = {toxinidir}:{toxinidir}/lib/:{toxinidir}/hooks/
passenv =
HOME
CHARM_BUILD_DIR
PATH
CHARM_BUILD_DIR
PYTEST_KEEP_MODEL
PYTEST_CLOUD_NAME
PYTEST_CLOUD_REGION
commands = pytest -vv --ignore {toxinidir}/tests/unit
deps = -r{toxinidir}/tests/functional/requirements.txt
-r{toxinidir}/requirements.txt
PYTEST_MODEL
MODEL_SETTINGS
HTTP_PROXY
HTTPS_PROXY
NO_PROXY
SNAP_HTTP_PROXY
SNAP_HTTPS_PROXY

[testenv:lint]
commands = flake8
commands =
flake8
black --check --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
deps =
black
flake8
flake8-docstrings
flake8-import-order
Expand All @@ -41,6 +39,32 @@ exclude =
.git,
__pycache__,
.tox,
ignore=D401,W503
max-line-length = 120
charmhelpers,
mod,
.build

max-line-length = 88
max-complexity = 10

[testenv:black]
commands =
black --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
deps =
black

[testenv:unit]
commands =
pytest -v --ignore {toxinidir}/tests/functional \
--cov=lib \
--cov=reactive \
--cov=actions \
--cov=hooks \
--cov=src \
--cov-report=term \
--cov-report=annotate:report/annotated \
--cov-report=html:report/html
deps = -r{toxinidir}/tests/unit/requirements.txt

[testenv:func]
commands = pytest -v --ignore {toxinidir}/tests/unit
deps = -r{toxinidir}/tests/functional/requirements.txt

0 comments on commit c5a5bd2

Please sign in to comment.