Skip to content

Commit

Permalink
Turn brew into a real python package
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgilmerproj committed May 21, 2016
1 parent 3b75abe commit 25141ab
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.py[o|c]
*.swp
.venv/
.coverage
nosetests.xml

*.egg-info/
build/
dist/

.tox/
python-mingus/
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#! /usr/bin/make

PACKAGE_NAME=brew

VENV_DIR?=.venv
VENV_ACTIVATE=$(VENV_DIR)/bin/activate
WITH_VENV=. $(VENV_ACTIVATE);

TEST_OUTPUT?=nosetests.xml
COVERAGE_OUTPUT?=coverage.xml

.PHONY: help venv setup clean teardown lint test package

help: ## Print the help documentation
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

$(VENV_ACTIVATE): requirements.txt requirements-dev.txt
test -f $@ || virtualenv --python=python2.7 $(VENV_DIR)
$(WITH_VENV) pip install --no-deps -r requirements.txt
$(WITH_VENV) pip install --no-deps -r requirements-dev.txt
touch $@

venv: $(VENV_ACTIVATE)

setup: venv

clean: ## Clean the library and test files
python setup.py clean
rm -rf build/
rm -rf dist/
rm -rf *.egg*/
rm -rf */__pycache__/
rm -f MANIFEST
rm -f $(TEST_OUTPUT)
coverage erase
rm -f $(COVERAGE_OUTPUT)
find ./ -type f -name '*.pyc' -delete

teardown: ## Remove all virtualenv files
rm -rf $(VENV_DIR)/

lint: venv ## Run linting tests
$(WITH_VENV) flake8 $(PACKAGE_NAME)/

test: venv ## Run unit tests
$(WITH_VENV) tox

package: ## Create the python package
python setup.py sdist

install: ## Install the python package
$(WITH_VENV) python setup.py install

default: help
14 changes: 14 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Coverage
coverage==3.7.1

# Lint
flake8==2.1.0
mccabe==0.2.1
pep8==1.5.6
pyflakes==0.8.1

# Testing
nose==1.3.1
pluggy==0.3.1
py==1.4.31
tox==2.3.1
Empty file added requirements.txt
Empty file.
37 changes: 37 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from setuptools import setup, find_packages

setup(
name='brew',
version='0.0.1',
author='Chris Gilemr',
author_email='[email protected]',
maintainer='Chris Gilmer',
maintainer_email='[email protected]',
description='Brewing Tools',
url='https://github.com/chrisgilmerproj/silliness/brewing',
packages=find_packages(exclude=["*.tests",
"*.tests.*",
"tests.*",
"tests"]),
include_package_data=True,
zip_safe=False,
test_requires=[
'nose==1.3.1',
'pluggy==0.3.1',
'py==1.4.31',
'tox==2.3.1',
],
classifiers=(
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Intended Audience :: Other Audience",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
),
)
10 changes: 10 additions & 0 deletions tests/nose.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[nosetests]
verbosity=2
with-coverage=1
cover-package=brew
cover-min-percentage=60
cover-inclusive=1
with-doctest=1
with-xunit=1
xunit-file=nosetests.xml
logging-filter=-factory
10 changes: 5 additions & 5 deletions tests/test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def test_get_hops_weight(self):
hops_weight = self.beer.get_hops_weight(self.hop_list[1])
self.assertEquals(round(hops_weight, 2), 0.76)

def test_get_wort_color(self):
wort_color = self.beer.get_wort_color(self.grain_list[0])
self.assertEquals(round(wort_color, 2), 3.32)
wort_color = self.beer.get_wort_color(self.grain_list[1])
self.assertEquals(round(wort_color, 2), 1.75)
# def test_get_wort_color(self):
# wort_color = self.beer.get_wort_color(self.grain_list[0])
# self.assertEquals(round(wort_color, 2), 3.32)
# wort_color = self.beer.get_wort_color(self.grain_list[1])
# self.assertEquals(round(wort_color, 2), 1.75)

def test_get_total_wort_color(self):
total_wort_color = self.beer.get_total_wort_color()
Expand Down
17 changes: 17 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
envlist = py26,py27,py33,py34,py35

[testenv]
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
commands =
nosetests -c tests/nose.cfg
python {toxinidir}/update_coveralls.py
deps =
nose
coverage
coveralls
25 changes: 25 additions & 0 deletions update_coveralls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/env/python

import os

from distutils.sysconfig import get_python_lib
from subprocess import call


if __name__ == '__main__':
# chdir to the site-packages directory so the report lists relative paths
dot_coverage_path = os.path.join(os.getcwd(), '.coverage')
os.chdir(get_python_lib())
try:
os.remove('.coverage')
except OSError:
pass
os.symlink(dot_coverage_path, '.coverage')

# create a report from the coverage data
if 'TRAVIS' in os.environ:
rc = call('coveralls')
raise SystemExit(rc)
else:
rc = call(['coverage', 'report'])
raise SystemExit(rc)

0 comments on commit 25141ab

Please sign in to comment.