Skip to content

Commit

Permalink
Simplify maintenance with a set of Makefiles
Browse files Browse the repository at this point in the history
Move the package version to the version.txt in the top level directory, and
use metapensiero.tool.bump_version to maintain it, wrapped in a few Makefile
targets to reduce the release burden.
  • Loading branch information
lelit committed Aug 16, 2017
1 parent 3f350c7 commit 957be61
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 16 deletions.
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export TOPDIR := $(CURDIR)
export VENVDIR := $(TOPDIR)/env
export PYTHON := $(VENVDIR)/bin/python
export SHELL := /bin/bash
export SYS_PYTHON := $(shell which python3.6 || which python3)

all: rapidjson/license.txt virtualenv help

rapidjson/license.txt:
git submodule update --init

.PHONY: help
help::
@printf "\nBuild targets\n"
@printf "=============\n\n"

help::
@printf "build\n\tbuild the module\n"

build: virtualenv
$(PYTHON) setup.py build_ext --inplace

help::
@printf "clean\n\tremove rebuildable stuff\n"

.PHONY: clean
clean:
$(MAKE) -C docs clean
rm -f *.so

help::
@printf "distclean\n\tremove anything superfluous\n"

.PHONY: distclean
distclean:: clean
rm -rf build dist
rm -rf rapidjson/.* rapidjson/*

help::
@printf "doc\n\tbuild Sphinx documentation\n"

SPHINXBUILD := $(VENVDIR)/bin/sphinx-build

.PHONY: doc
doc:
$(MAKE) -C docs SPHINXBUILD=$(SPHINXBUILD) html

help::
@printf "check\n\trun the test suite\n"

PYTEST := $(VENVDIR)/bin/pytest

.PHONY: check
check: build
$(PYTEST) tests/
$(MAKE) -C docs SPHINXBUILD=$(SPHINXBUILD) doctest

include Makefile.virtualenv
include Makefile.release
60 changes: 60 additions & 0 deletions Makefile.release
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
BUMPER := $(VENVDIR)/bin/bump_version -f minor
VERSION_TXT := version.txt
VERSION = $(shell cat $(VERSION_TXT))

help::
@printf "\nRelease management\n"
@printf "==================\n\n"

.PHONY: assert-clean-tree
assert-clean-tree:
@(test -z "$(shell git status -s --untracked=no)" || \
(echo "UNCOMMITTED STAFF" && false))

.PHONY: assert-master-branch
assert-master-branch:
@(test "$(shell git rev-parse --abbrev-ref HEAD)" = "master" || \
(echo "NOT IN MASTER BRANCH" && false))

help::
@printf "release\n\tBump version number\n"

.PHONY: release
release: assert-master-branch assert-clean-tree
$(BUMPER) $(VERSION_TXT)
@echo ">>>"
@echo ">>> Do your duties (update CHANGES.rst for example), then"
@echo ">>> execute “make tag-release”."
@echo ">>>"

help::
@printf "tag-release\n\tComplete the release tagging the working tree\n"

.PHONY: tag-release
tag-release: assert-master-branch check-release-date check-long-description-markup
git commit -a -m "Release $(VERSION)"
git tag -a -m "Version $(VERSION)" v$(VERSION)

.PHONY: check-long-description-markup
check-long-description-markup:
@$(PYTHON) setup.py check -r -s

.PHONY: check-release-date
check-release-date:
@fgrep -q "$(VERSION) ($(shell date --iso-8601))" CHANGES.rst \
|| (echo "ERROR: release date of version $(VERSION) not set in CHANGES.rst"; exit 1)

help::
@printf "pypi-upload\n\tUpload the source distribution to PyPI\n"

.PHONY: pypi-upload
pypi-upload: assert-master-branch assert-clean-tree
$(PYTHON) setup.py sdist upload

help::
@printf "publish\n\tUpload to PyPI, push changes and tags to the remote repo\n"

.PHONY: publish
publish: pypi-upload
git push
git push --tags
41 changes: 41 additions & 0 deletions Makefile.virtualenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
ACTIVATE_SCRIPT := $(VENVDIR)/bin/activate
PIP := $(VENVDIR)/bin/pip
REQUIREMENTS ?= requirements.txt
REQUIREMENTS_TIMESTAMP := $(VENVDIR)/$(REQUIREMENTS).timestamp

help::
@printf "\nPython virtualenv related targets\n"
@printf "=================================\n\n"

help::
@printf "virtualenv\n\tsetup the Python virtualenv and install required packages\n"

.PHONY: virtualenv
virtualenv: $(VENVDIR) requirements

$(VENVDIR):
@echo "Bootstrapping Python 3 virtualenv..."
@$(SYS_PYTHON) -m venv --prompt $(notdir $(TOPDIR)) $@
@$(MAKE) upgrade-pip

help::
@printf "upgrade-pip\n\tupgrade pip\n"

.PHONY: upgrade-pip
upgrade-pip:
@echo "Upgrading pip..."
@$(PIP) install --no-cache-dir --upgrade pip

help::
@printf "requirements\n\tinstall/update required Python packages\n"

.PHONY: requirements
requirements: $(REQUIREMENTS_TIMESTAMP)

$(REQUIREMENTS_TIMESTAMP): $(REQUIREMENTS)
@echo "Installing pre-requirements..."
@PATH=$(TOPDIR)/bin:$(PATH) $(PIP) install --no-cache-dir -r $(REQUIREMENTS)
@touch $@

distclean::
rm -rf $(VENVDIR)
1 change: 0 additions & 1 deletion python-rapidjson/rapidjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "rapidjson/error/en.h"

#include "docstrings.h"
#include "version.h"


using namespace rapidjson;
Expand Down
3 changes: 0 additions & 3 deletions python-rapidjson/version.h

This file was deleted.

1 change: 0 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pytest >= 3
pytest-benchmark
pytz
readme-renderer

# Keep in sync with benchmark-tables.py versions
simplejson==3.11.1
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-r requirements-test.txt

metapensiero.tool.bump-version==1.3
readme-renderer==17.2
sphinx==1.6.3
21 changes: 10 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os.path
import re
import sys

try:
Expand Down Expand Up @@ -28,14 +27,11 @@
" the README.rst; in all other cases you may want to report the"
" issue.")

VERSION_H = os.path.join(ROOT_PATH, 'python-rapidjson', 'version.h')
AUTHOR = 'Ken Robbins'
EMAIL = 'ken@kenrobbins.com'

with open(VERSION_H, encoding='utf-8') as f:
data = f.read()

VERSION = re.search(r'PYTHON_RAPIDJSON_VERSION\s+"([^"]+)"', data).group(1)
AUTHOR = re.search(r'PYTHON_RAPIDJSON_AUTHOR\s+"([^"]+)"', data).group(1)
EMAIL = re.search(r'PYTHON_RAPIDJSON_AUTHOR_EMAIL\s+"([^"]+)"', data).group(1)
with open('version.txt', encoding='utf-8') as f:
VERSION = f.read()

with open('README.rst', encoding='utf-8') as f:
LONG_DESCRIPTION = f.read()
Expand All @@ -54,6 +50,9 @@
extension_options = {
'sources': ['./python-rapidjson/rapidjson.cpp'],
'include_dirs': [rj_include_dir],
'define_macros': [('PYTHON_RAPIDJSON_VERSION', '"%s"' % VERSION),
('PYTHON_RAPIDJSON_AUTHOR', '"%s"' % AUTHOR),
('PYTHON_RAPIDJSON_AUTHOR_EMAIL', '"%s"' % EMAIL)],
}

cc = sysconfig.get_config_var('CC')
Expand All @@ -69,8 +68,6 @@
# long" as an error under C++ (see issue #69)
extension_options['extra_compile_args'] = ['-pedantic', '-Wno-long-long']

rapidjson = Extension('rapidjson', **extension_options)

setup(
name='python-rapidjson',
version=VERSION,
Expand All @@ -80,6 +77,8 @@
keywords='json rapidjson',
author=AUTHOR,
author_email=EMAIL,
maintainer='Lele Gaifax',
maintainer_email='lele@metapensiero.it',
url='https://github.com/python-rapidjson/python-rapidjson',
classifiers=[
'Development Status :: 3 - Alpha',
Expand All @@ -93,6 +92,6 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python',
],
ext_modules=[rapidjson],
ext_modules=[Extension('rapidjson', **extension_options)],
**other_setup_options
)
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0

0 comments on commit 957be61

Please sign in to comment.