Skip to content

Commit

Permalink
travis support
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiommendes committed Sep 14, 2016
1 parent afff257 commit b07c396
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 5 deletions.
Empty file added .travis.yml
Empty file.
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.. image:: https://travis-ci.org/fabiommendes/python-boilerplate.svg?branch=master
:target: https://travis-ci.org/fabiommendes/python-boilerplate

.. image:: https://coveralls.io/repos/github/fabiommendes/python-boilerplate/badge.svg?branch=master
:target: https://coveralls.io/github/fabiommendes/python-boilerplate?branch=master


Starting a new Python project from the scratch is boring and error prone:
* Create a setup.py script
* Configure documentation
Expand Down
2 changes: 1 addition & 1 deletion src/python_boilerplate/__meta__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Automatically created. Please do not edit.
__version__ = u'0.4.3'
__version__ = u'0.4.4'
__author__ = u'F\xe1bio Mac\xeado Mendes'
99 changes: 96 additions & 3 deletions src/python_boilerplate/compat.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals

import os as _os
import sys as _sys
import warnings as _warnings
from tempfile import mkdtemp

import six
from unidecode import unidecode as _unidecode


if six.PY2:
_unicode = unicode


def unidecode(x):
if not isinstance(x, _unicode):
x = six.u(x)
return _unidecode(x)


def unicode(x):
if isinstance(x, str):
return x.decode('utf8')
Expand All @@ -21,7 +28,93 @@ def unicode(x):
else:
unidecode = _unidecode


def unicode(x):
if isinstance(x, bytes):
return x.decode('utf8')
return str(x)


# Thanks to Leonardo.Z@stackoverflow
# http://stackoverflow.com/questions/19296146/tempfile-temporarydirectory-context-manager-in-python-2-7
class TemporaryDirectory(object):
"""
Create and return a temporary directory. This has the same
behavior as mkdtemp but can be used as a context manager. For
example:
with TemporaryDirectory() as tmpdir:
...
Upon exiting the context, the directory and everything contained
in it are removed.
"""

def __init__(self, suffix="", prefix="tmp", dir=None):
self._closed = False
self.name = None # Handle mkdtemp raising an exception
self.name = mkdtemp(suffix, prefix, dir)

def __repr__(self):
return "<{} {!r}>".format(self.__class__.__name__, self.name)

def __enter__(self):
return self.name

def cleanup(self, _warn=False):
if self.name and not self._closed:
try:
self._rmtree(self.name)
except (TypeError, AttributeError) as ex:
# Issue #10188: Emit a warning on stderr
# if the directory could not be cleaned
# up due to missing globals
if "None" not in str(ex):
raise
print("ERROR: {!r} while cleaning up {!r}".format(ex, self, ),
file=_sys.stderr)
return
self._closed = True
if _warn:
self._warn("Implicitly cleaning up {!r}".format(self),
ResourceWarning)

def __exit__(self, exc, value, tb):
self.cleanup()

def __del__(self):
# Issue a ResourceWarning if implicit cleanup needed
self.cleanup(_warn=True)

# XXX (ncoghlan): The following code attempts to make
# this class tolerant of the module nulling out process
# that happens during CPython interpreter shutdown
# Alas, it doesn't actually manage it. See issue #10188
_listdir = staticmethod(_os.listdir)
_path_join = staticmethod(_os.path.join)
_isdir = staticmethod(_os.path.isdir)
_islink = staticmethod(_os.path.islink)
_remove = staticmethod(_os.remove)
_rmdir = staticmethod(_os.rmdir)
_warn = _warnings.warn

def _rmtree(self, path):
# Essentially a stripped down version of shutil.rmtree. We can't
# use globals because they may be None'ed out at shutdown.
for name in self._listdir(path):
fullname = self._path_join(path, name)
try:
isdir = self._isdir(fullname) and not self._islink(fullname)
except OSError:
isdir = False
if isdir:
self._rmtree(fullname)
else:
try:
self._remove(fullname)
except OSError:
pass
try:
self._rmdir(path)
except OSError:
pass
3 changes: 3 additions & 0 deletions src/python_boilerplate/templates/gitignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ dist/

# Python-boilerplate auto generated files
src/{{ pyname }}/__meta__.py

# Testing and temporary files
.tox/
25 changes: 25 additions & 0 deletions src/python_boilerplate/templates/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[tox]
skipsdist = True
usedevelop = True
envlist = py{27,33,34,35},
flake8

[testenv]
install_command = pip install -e ".[dev]" -U {opts} {packages}
basepython =
py27: python2.7
py33: python3.3
py34: python3.4
py35: python3.5
deps =
invoke>=0.13
commands = py.test src/{{ pyname }}/tests/
# setenv =

[testenv:flake8]
basepython =
python3.4
deps =
flake8>=2.2.0
commands =
flake8 src/{{ pyname }}
7 changes: 6 additions & 1 deletion src/python_boilerplate/tests/test_python_boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

import mock
import pytest
import six

from python_boilerplate import compat
from python_boilerplate import config as config_mod
from python_boilerplate.commands import InitJobConfig, InitJobWriter
from python_boilerplate.config import get_config, get_context


@pytest.yield_fixture
def tempdir():
tempdir = tempfile.TemporaryDirectory()
if six.PY3:
tempdir = tempfile.TemporaryDirectory()
else:
tempdir = compat.TemporaryDirectory()
oldpath = os.getcwd()

with tempdir as path:
Expand Down
26 changes: 26 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[tox]
skipsdist = True
usedevelop = True
envlist = py{27,33,34,35},
flake8

[testenv]
install_command = pip install -e ".[dev]" -U {packages}
basepython =
py27: python2.7
py33: python3.3
py34: python3.4
py35: python3.5
deps =
invoke>=0.13
pytest-cov
commands = py.test src/python_boilerplate/tests/
# setenv =

[testenv:flake8]
basepython =
python3.4
deps =
flake8
commands =
flake8 src/python_boilerplate

0 comments on commit b07c396

Please sign in to comment.