Skip to content

Commit

Permalink
Fixes and improvements in Makefile.
Browse files Browse the repository at this point in the history
Details:
- Merged "buildwin" target into "build" target, and improved "build" target
  to automatically build the right files for the current OS.
- Added dev-requirements.txt and requirements.txt to dependent list of
  "develop" rule.
- Added requirements.txt, setup.py, setup.cfg and package source files to
  dependent list of "install" rule.
- Fixed the bug that dependent packages in requirements files that point to
  a git URL were not updated in 'pip install .' by adding an explicit
  'pip install -r requirements.txt' to commands of "install" rule.
- Fixed "all" target to add "install" and "pylint" as dependents.
- Fixed the possibility that half-built artefacts are included in
  distribution archives (including the one uploaded to Pypi), by removing
  the "build" subtree before building them.
- Added "which zhmc" to commands of "install" rule, to improve diagnostics
  in CI environments.
- Added tests/../*.py files to files to be checked.
- Added test source files to dependent list of rule running the test.
- Improved the structure of make variables.

Signed-off-by: Andreas Maier <maiera@de.ibm.com>
  • Loading branch information
andy-maier committed Oct 17, 2017
1 parent 1f6ebd1 commit 83beac4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 31 deletions.
79 changes: 48 additions & 31 deletions Makefile
Expand Up @@ -80,6 +80,11 @@ win64_dist_file := $(dist_dir)/$(package_name)-$(package_version).win-amd64.exe
# dist_files := $(bdist_file) $(sdist_file) $(win64_dist_file)
dist_files := $(bdist_file) $(sdist_file)

# Source files in the package
package_py_files := \
$(wildcard $(package_name)/*.py) \
$(wildcard $(package_name)/*/*.py) \

# Directory for generated API documentation
doc_build_dir := build_doc

Expand All @@ -94,7 +99,19 @@ doc_opts := -v -d $(doc_build_dir)/doctrees -c $(doc_conf_dir) .
doc_dependent_files := \
$(doc_conf_dir)/conf.py \
$(wildcard $(doc_conf_dir)/*.rst) \
$(wildcard $(package_name)/*.py) \
$(package_py_files) \

# Directory with test source files
test_dir := tests

# Test log
test_log_file := test_$(python_version_fn).log

# Source files with test code
test_py_files := \
$(wildcard $(test_dir)/*.py) \
$(wildcard $(test_dir)/*/*.py) \
$(wildcard $(test_dir)/*/*/*.py) \

# Flake8 config file
flake8_rc_file := setup.cfg
Expand All @@ -105,24 +122,28 @@ pylint_rc_file := .pylintrc
# Source files for check (with PyLint and Flake8)
check_py_files := \
setup.py \
$(wildcard $(package_name)/*.py) \

# Test log
test_log_file := test_$(python_version_fn).log
$(package_py_files) \
$(test_py_files) \

ifdef TESTCASES
pytest_opts := -k $(TESTCASES)
else
pytest_opts :=
endif

# Files to be built
ifeq ($(PLATFORM),Windows)
build_files := $(win64_dist_file)
else
build_files := $(bdist_file) $(sdist_file)
endif

# Files the distribution archive depends upon.
dist_dependent_files := \
setup.py setup.cfg \
README.rst \
requirements.txt \
$(wildcard *.py) \
$(wildcard $(package_name)/*.py) \
$(package_py_files) \

# No built-in rules needed:
.SUFFIXES:
Expand All @@ -134,15 +155,17 @@ help:
@echo 'Uses the currently active Python environment: Python $(python_version_fn)'
@echo 'Valid targets are (they do just what is stated, i.e. no automatic prereq targets):'
@echo ' develop - Prepare the development environment by installing prerequisites'
@echo ' build - Build the distribution files in: $(dist_dir) (requires Linux or OSX)'
@echo ' buildwin - Build the Windows installable in: $(dist_dir) (requires Windows 64-bit)'
@echo ' builddoc - Build documentation in: $(doc_build_dir)'
@echo ' install - Install package in active Python environment'
@echo ' check - Run Flake8 on sources and save results in: flake8.log'
@echo ' pylint - Run PyLint on sources and save results in: pylint.log'
@echo ' test - Run unit tests (and test coverage) and save results in: $(test_log_file)'
@echo ' test - Run tests (and test coverage) and save results in: $(test_log_file)'
@echo ' Does not include install but depends on it, so make sure install is current.'
@echo ' Env.var TESTCASES can be used to specify a py.test expression for its -k option'
@echo ' all - Do all of the above (except buildwin when not on Windows)'
@echo ' install - Install package in active Python environment and test import (includes build)'
@echo ' build - Build the distribution files in: $(dist_dir)'
@echo ' On Windows, builds: $(win64_dist_file)'
@echo ' On Linux + OSX, builds: $(bdist_file) $(sdist_file)'
@echo ' builddoc - Build documentation in: $(doc_build_dir)'
@echo ' all - Do all of the above'
@echo ' uninstall - Uninstall package from active Python environment'
@echo ' upload - Upload the distribution files to PyPI (includes uninstall+build)'
@echo ' clean - Remove any temporary files'
Expand All @@ -161,17 +184,13 @@ _pip:
$(PIP_CMD) install $(pip_level_opts) pip setuptools wheel pbr

.PHONY: develop
develop: _pip
develop: _pip dev-requirements.txt requirements.txt
@echo 'Installing runtime and development requirements with PACKAGE_LEVEL=$(PACKAGE_LEVEL)'
$(PIP_CMD) install $(pip_level_opts) -r dev-requirements.txt
@echo '$@ done.'

.PHONY: build
build: $(bdist_file) $(sdist_file)
@echo '$@ done.'

.PHONY: buildwin
buildwin: $(win64_dist_file)
build: $(build_files)
@echo '$@ done.'

.PHONY: builddoc
Expand Down Expand Up @@ -240,9 +259,10 @@ pylint: pylint.log
@echo '$@ done.'

.PHONY: install
install: _pip
install: _pip requirements.txt setup.py setup.cfg $(package_py_files)
@echo 'Installing runtime requirements with PACKAGE_LEVEL=$(PACKAGE_LEVEL)'
$(PIP_CMD) install $(pip_level_opts) .
$(PIP_CMD) install $(pip_level_opts) -r requirements.txt .
which zhmc
zhmc --version
@echo 'Done: Installed $(package_name) into current Python environment.'
@echo '$@ done.'
Expand All @@ -259,12 +279,10 @@ test: $(test_log_file)
.PHONY: clobber
clobber: uninstall clean
rm -Rf $(doc_build_dir) htmlcov .tox
rm -fv pylint.log flake8.log test_*.log
rm -fv $(bdist_file) $(sdist_file) $(win64_dist_file)
rm -f pylint.log flake8.log test_*.log $(bdist_file) $(sdist_file) $(win64_dist_file)
@echo 'Done: Removed all build products to get to a fresh state.'
@echo '$@ done.'

# Also remove any build products that are dependent on the Python version
.PHONY: clean
clean:
rm -Rf build .cache $(package_name).egg-info .eggs
Expand All @@ -274,7 +292,7 @@ clean:
@echo '$@ done.'

.PHONY: all
all: develop check build builddoc test
all: develop install check pylint test build builddoc
@echo '$@ done.'

.PHONY: upload
Expand All @@ -294,7 +312,7 @@ endif
# Distribution archives.
$(bdist_file): Makefile $(dist_dependent_files)
ifneq ($(PLATFORM),Windows)
rm -Rfv $(package_name).egg-info .eggs
rm -Rfv $(package_name).egg-info .eggs build
$(PYTHON_CMD) setup.py bdist_wheel -d $(dist_dir) --universal
@echo 'Done: Created binary distribution archive: $@'
else
Expand All @@ -304,7 +322,7 @@ endif

$(sdist_file): Makefile $(dist_dependent_files)
ifneq ($(PLATFORM),Windows)
rm -Rfv $(package_name).egg-info .eggs
rm -Rfv $(package_name).egg-info .eggs build
$(PYTHON_CMD) setup.py sdist -d $(dist_dir)
@echo 'Done: Created source distribution archive: $@'
else
Expand All @@ -314,7 +332,7 @@ endif

$(win64_dist_file): Makefile $(dist_dependent_files)
ifeq ($(PLATFORM),Windows)
rm -Rfv $(package_name).egg-info .eggs
rm -Rfv $(package_name).egg-info .eggs build
$(PYTHON_CMD) setup.py bdist_wininst -d $(dist_dir) -o -t "$(package_name) v$(package_version)"
@echo 'Done: Created Windows installable: $@'
else
Expand All @@ -333,15 +351,14 @@ else
@echo 'Info: PyLint requires Python 2; skipping this step on Python $(python_major_version)'
endif

# TODO: Once Flake8 has no more errors, remove the dash "-"
flake8.log: Makefile $(flake8_rc_file) $(check_py_files)
rm -fv $@
bash -c 'set -o pipefail; flake8 $(check_py_files) 2>&1 |tee $@.tmp'
mv -f $@.tmp $@
@echo 'Done: Created Flake8 log file: $@'

$(test_log_file): Makefile $(package_name)/*.py .coveragerc
$(test_log_file): Makefile $(package_py_files) $(test_py_files) .coveragerc
rm -fv $@
bash -c 'set -o pipefail; PYTHONWARNINGS=default py.test -s tests --cov $(package_name) --cov-config .coveragerc --cov-report=html $(pytest_opts) 2>&1 |tee $@.tmp'
bash -c 'set -o pipefail; PYTHONWARNINGS=default py.test -s $(test_dir) --cov $(package_name) --cov-config .coveragerc --cov-report=html $(pytest_opts) 2>&1 |tee $@.tmp'
mv -f $@.tmp $@
@echo 'Done: Created test log file: $@'
2 changes: 2 additions & 0 deletions docs/changes.rst
Expand Up @@ -32,6 +32,8 @@ Released: not yet

**Enhancements:**

* Fixes and improvements in Makefile.

**Known issues:**

* See `list of open issues`_.
Expand Down

0 comments on commit 83beac4

Please sign in to comment.