Skip to content

Commit

Permalink
Merge pull request #107 from elyezer/release-script
Browse files Browse the repository at this point in the history
Release script
  • Loading branch information
sthirugn authored Jun 20, 2016
2 parents 88a77eb + 7f9ffb4 commit 3798489
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
sudo: false
language: python
install: "pip install flake8 ."
install: pip install -r requirements-dev.txt .
script:
- flake8 testimony
- make lint
- make test
notifications:
irc: "chat.freenode.net#robottelo"
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
include README.rst
include LICENSE
include LICENSE README.rst VERSION
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
lint:
flake8 testimony

package:
python setup.py sdist bdist_wheel --universal

package-clean:
rm -rf build dist testimony.egg-info

publish: package
twine upload dist/*
test:
@./tests/test_testimony.sh | diff tests/sample_output.txt -

.PHONY: test
.PHONY: package package-clean publish test
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.6
72 changes: 72 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
#
# Test Testimony for sanity. If all is well, generate a new commit, tag it, and
# print instructions for further steps to take.
#
# NOTE: This script should be run from the repository root directory. Also in
# order to actually release to PyPI a proper `.pypirc` file should be already
# setup, for more information check
# https://docs.python.org/3/distutils/packageindex.html#the-pypirc-file
#
set -euo pipefail

# Make sure local fork is updated
git fetch -p --all
git checkout master
git merge --ff-only upstream/master

OLD_VERSION="$(git tag --list | sort -V | tail -n 1)"
MAJOR_VERSION="$(echo ${OLD_VERSION} | cut -d . -f 1)"
MINOR_VERSION="$(echo ${OLD_VERSION} | cut -d . -f 2)"
NEW_VERSION="${MAJOR_VERSION}.$((${MINOR_VERSION} + 1)).0"

# Bump version number
echo "${NEW_VERSION}" > VERSION

# Generate the package
make package-clean package

# Sanity check Testimony packages on both Python 2 and Python 3
for python in python{2,3}; do
venv="$(mktemp --directory)"
virtualenv -p "${python}" "${venv}"
set +u
source "${venv}/bin/activate"
set -u
for dist in dist/*; do
ls "${dist}"
pip install --quiet -U pip
pip install --quiet "${dist}"
python -c "import testimony" 1>/dev/null
make test
pip uninstall --quiet --yes testimony
done
set +u
deactivate
set -u
rm -rf "${venv}"
done

# Get the changes from last release and commit
git add VERSION
git commit -m "Release version ${NEW_VERSION}" \
-m "Shortlog of commits since last release:" \
-m "$(git shortlog ${OLD_VERSION}.. | sed 's/^./ &/')"

# Tag with the new version
git tag "${NEW_VERSION}"

fmt <<EOF
This script has made only local changes: it has updated the VERSION file,
generated a new commit, tagged the new commit, and performed a few checks along
the way. If you are confident in these changes, you can publish them with
commands like the following:
EOF

cat <<EOF
git push --tags origin master && git push --tags upstream master
make publish
EOF
10 changes: 10 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# For `make lint`
flake8
flake8-docstrings
flake8-quotes

# For `make package`
wheel

# For `make publish`
twine
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from distutils.core import setup
from setuptools import find_packages, setup # prefer setuptools over distutils

with open('LICENSE') as file:
license = file.read()

with open('README.rst') as file:
long_description = file.read()

with open('VERSION') as file:
version = file.read()

setup(
name='testimony',
version='1.0.6',
version=version,
url='https://github.com/SatelliteQE/testimony/',
author='Suresh Thirugn',
author_email='[email protected]',
packages=['testimony'],
packages=find_packages(),
install_requires=['Click'],
entry_points='''
[console_scripts]
Expand Down
13 changes: 7 additions & 6 deletions testimony/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
"""DocString manipulation methods to create test reports"""
# coding=utf-8
"""Docstring manipulation methods to create test reports."""
from __future__ import print_function, unicode_literals

import ast
Expand Down Expand Up @@ -36,7 +36,7 @@


def indent(text, prefix, predicate=None):
"""Adds 'prefix' to the beginning of selected lines in 'text'.
"""Add 'prefix' to the beginning of selected lines in 'text'.
If 'predicate' is provided, 'prefix' will only be added to the lines
where 'predicate(line)' is True. If 'predicate' is not provided,
Expand Down Expand Up @@ -68,7 +68,7 @@ class TestFunction(object):
"""

def __init__(self, function_def, parent_class=None, testmodule=None):
#: A ``ast.FunctionDef`` instance used to extract information
"""A ``ast.FunctionDef`` instance used to extract information."""
self.docstring = ast.get_docstring(function_def)
self.function_def = function_def
self.name = function_def.name
Expand Down Expand Up @@ -128,6 +128,7 @@ def to_dict(self):
}

def __str__(self):
"""String representation for a test and its tokens."""
output = []
for token, value in sorted(self.tokens.items()):
output.append('{0}:\n{1}\n'.format(
Expand All @@ -148,7 +149,7 @@ def __str__(self):


def main(report, paths, json_output, nocolor):
"""Main function for testimony project
"""Main function for testimony project.
Expects a valid report type and valid directory paths, hopefully argparse
is taking care of validation
Expand Down Expand Up @@ -200,7 +201,7 @@ def summary_report(testcases):
tokens_count[token] += 1

def percentage(value):
"""Calculates the percentage of the value on the total."""
"""Calculate the percentage of the value on the total."""
return value / float(count) * 100
summary_result = {
'count': count,
Expand Down
2 changes: 1 addition & 1 deletion testimony/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@click.argument('report', type=click.Choice(constants.REPORT_TAGS))
@click.argument('path', nargs=-1, type=click.Path(exists=True))
def testimony(json, nocolor, tokens, minimum_tokens, report, path):
"""Inspects and report on the Python test cases."""
"""Inspect and report on the Python test cases."""
if tokens:
SETTINGS['tokens'] = [token.strip() for token in tokens.split(',')]
if minimum_tokens:
Expand Down
4 changes: 2 additions & 2 deletions testimony/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
"""Defines various constants"""
# coding=utf-8
"""Defines various constants."""

# Per termcolor webpage, these are the available colors: grey, red, green,
# yellow, blue, magenta, cyan, white
Expand Down
4 changes: 3 additions & 1 deletion testimony/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DocstringParser(object):
"""Parse docstring extracting tokens."""

def __init__(self, tokens=None, minimum_tokens=None):
"""Initialize the parser with expected tokens and the minimum set."""
if tokens is None:
self.tokens = DEFAULT_TOKENS
else:
Expand All @@ -25,7 +26,7 @@ def __init__(self, tokens=None, minimum_tokens=None):
raise ValueError('tokens should contain minimum_tokens')

def parse(self, docstring=None):
"""Parses the docstring and returns the valid and invalid tokens.
"""Parse the docstring and return the valid and invalid tokens.
For example in the following docstring (using single quote to demo)::
Expand Down Expand Up @@ -60,4 +61,5 @@ def parse(self, docstring=None):
return valid_tokens, invalid_tokens

def validate_tokens(self, tokens):
"""Check if the ``tokens`` is a superset of ``minimum_tokens``."""
return self.minimum_tokens.issubset(tokens)

0 comments on commit 3798489

Please sign in to comment.