Skip to content

Commit

Permalink
Enhance release procedure (#10)
Browse files Browse the repository at this point in the history
* Fix make sdist command

* Don't upload in this command.

* Move pypi requirements to own file

* Add twine and upgrade wheel

* Update and clean makefile

* Add pygcgen changelog generator package

* Create python script to generate changelog

* Add release instructions
  • Loading branch information
MartinHjelmare authored Apr 5, 2018
1 parent 76fba0f commit 2bd5ed9
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 15 deletions.
31 changes: 18 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
.PHONY: help clean clean-pyc clean-build list test test-all coverage docs release sdist
.PHONY: help clean clean-pyc clean-build list test test-all coverage docs release test-release sdist

help:
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
@echo "lint - check style with flake8"
@echo "lint - check style with flake8, pylint and pydocstyle"
@echo "test - run tests quickly with the default Python"
@echo "testall - run tests on every Python version with tox"
@echo "test-all - run tests on every Python version with tox"
@echo "coverage - check code coverage quickly with the default Python"
@echo "docs - generate Sphinx HTML documentation, including API docs"
@echo "release - package and upload a release"
@echo "api-docs - generate leicacam rst file for Sphinx HTML documentation"
@echo "release - package and upload a release to PyPI"
@echo "test-release - package and upload a release to test PyPI"
@echo "sdist - package"

clean: clean-build clean-pyc
Expand All @@ -27,30 +29,33 @@ lint:
tox -e lint

test:
pytest -v test/

test-all:
tox

coverage:
coverage run --source leicacam setup.py test
coverage report -m
coverage html
open htmlcov/index.html
pytest -v --cov-report term-missing --cov=leicacam test/

api-docs:
sphinx-apidoc -Mf -o docs/ leicacam
sphinx-apidoc -MfT -o docs/ leicacam

docs:
$(MAKE) -C docs clean
$(MAKE) -C docs html
open docs/_build/html/index.html

release: clean rst
python setup.py sdist upload
python setup.py bdist_wheel upload
python setup.py sdist bdist_wheel
twine upload dist/*

test-release: clean rst
python setup.py sdist bdist_wheel
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

rst:
if type pandoc; then pandoc --from=markdown --to=rst README.md -o README.rst; fi

sdist: clean rst
python setup.py sdist
python setup.py bdist_wheel upload
python setup.py sdist bdist_wheel
ls -l dist
21 changes: 21 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- Install the pypi requirements including `twine`.
```
pip install -r requirements_pypi.txt
```
- Fetch and checkout master branch.
- Update version in `leicacam/VERSION` to the new version number, eg `0.2.0`.
- Update `CHANGELOG.md` by running `scripts/gen_changelog.py`. Make sure you first set a GitHub token as an environment variable, for the changelog generator package `pygcgen`. See https://github.com/topic2k/pygcgen.
```
scripts/gen_changelog.py
```
- Commit and push to remote master. Use a commit message like: `Bump version to 0.2.0`
- Go to github releases and tag a new release on the master branch. Put the changes for the new release from the updated changelog as the description for the release. Use the same version for the tag as the new version in `leicacam/VERSION`, to ensure working links in the changelog.
- Fetch and checkout the master branch.
- Build source and wheel distributions and upload to test-pypi, to stage a release:
```
make test-release
```
- Release to pypi:
```
make release
```
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
pydebug==1.0.3
setuptools-git
wheel>=0.22
4 changes: 4 additions & 0 deletions requirements_pypi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pygcgen==0.2.3
setuptools-git
twine>=1.11.0
wheel>=0.31.0
43 changes: 43 additions & 0 deletions scripts/gen_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python
"""Generate changelog."""
import os

from pygcgen.main import ChangelogGenerator


def validate_version():
"""Validate version before release."""
import leicacam
version_string = leicacam.__version__
versions = version_string.split('.', 3)
try:
for ver in versions:
int(ver)
except ValueError:
print(
'Only integers are allowed in release version, '
'please adjust current version {}'.format(version_string))
return None
return version_string


def generate():
"""Generate changelog."""
old_dir = os.getcwd()
proj_dir = os.path.join(os.path.dirname(__file__), os.pardir)
os.chdir(proj_dir)
version = validate_version()
if not version:
os.chdir(old_dir)
return
print('Generating changelog for version {}'.format(version))
options = [
'--user', 'arve0', '--project', 'leicacam', '-v', '--with-unreleased',
'--future-release', version]
generator = ChangelogGenerator(options)
generator.run()
os.chdir(old_dir)


if __name__ == '__main__':
generate()

0 comments on commit 2bd5ed9

Please sign in to comment.