Skip to content

Commit

Permalink
ENH: Restructure for Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Apr 27, 2016
1 parent 4cb7fe3 commit b400e42
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.coverage
build
dist
ld
codespell.egg-info
*.pyc

42 changes: 42 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# vim ft=yaml
# Multiple lines can be made a single "virtual line" because of how Travis
# munges each line before executing it to print out the exit status. It's okay
# for it to be on multiple physical lines, so long as you remember: - There
# can't be any leading "-"s - All newlines will be removed, so use ";"s

language: python

# Run jobs on container-based infrastructure, can be overridden per job
sudo: false

cache:
directories:
- $HOME/.cache/pip

python:
# 2.7
- 3.3
- 3.4
- 3.5

before_install:
- source tools/travis_tools.sh
- SRC_DIR=$PWD
- cd ~
- virtualenv --python=python venv
- source venv/bin/activate
- python --version # just to check
- pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors
- retry pip install nose flake8 coverage codecov
- cd $SRC_DIR

install:
- python setup.py install

# command to run tests, e.g. python setup.py test
script:
- flake8
- nosetests

after_success:
- codecov
7 changes: 7 additions & 0 deletions bin/codespell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python

import sys

if __name__ == '__main__':
import codespell_lib
sys.exit(codespell_lib.main(*sys.argv))
1 change: 1 addition & 0 deletions codespell_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._codespell import main, VERSION as __version__ # noqa
27 changes: 19 additions & 8 deletions codespell.py → codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
Copyright (C) 2011 ProFUSION embedded systems
"""

from __future__ import print_function

import sys
import re
from optparse import OptionParser
Expand All @@ -27,7 +29,7 @@
USAGE = """
\t%prog [OPTIONS] [file1 file2 ... fileN]
"""
VERSION = '1.8'
VERSION = '1.9'

misspellings = {}
exclude_lines = set()
Expand All @@ -37,7 +39,8 @@
encodings = ['utf-8', 'iso-8859-1']
# Users might want to link this file into /usr/local/bin, so we resolve the
# symbolic link path to the real path if necessary.
default_dictionary = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'dictionary.txt')
default_dictionary = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'data', 'dictionary.txt')

# OPTIONS:
#
Expand Down Expand Up @@ -260,7 +263,7 @@ def parse_options(args):
'reliable in detecting encodings other than utf-8, '
'iso8859-1 and ascii.')

(o, args) = parser.parse_args()
(o, args) = parser.parse_args(list(args))

if not os.path.exists(o.dictionary):
print('ERROR: cannot find dictionary file!', file=sys.stderr)
Expand Down Expand Up @@ -399,17 +402,18 @@ def parse_file(filename, colors, summary):
try:
text = is_text_file(filename)
except FileNotFoundError:
return
return 0
if not text:
if not quiet_level & QuietLevels.BINARY_FILE:
print("WARNING: Binary file: %s " % filename, file=sys.stderr)
return
return 0
try:
lines, encoding = file_opener.open(filename)
except:
return
return 0

i = 1
bad_count = 0
rx = re.compile(r"[\w\-']+")
for line in lines:
if line in exclude_lines:
Expand Down Expand Up @@ -467,6 +471,10 @@ def parse_file(filename, colors, summary):

creason = ''

# If we get to this point (uncorrected error) we should change
# our bad_count and thus return value
bad_count += 1

if filename != '-':
print("%(FILENAME)s:%(LINE)s: %(WRONGWORD)s "
" ==> %(RIGHTWORD)s%(REASON)s"
Expand Down Expand Up @@ -494,6 +502,7 @@ def parse_file(filename, colors, summary):
f = open(filename, 'w', encoding=encoding)
f.writelines(lines)
f.close()
return bad_count


def main(*args):
Expand Down Expand Up @@ -523,6 +532,7 @@ def main(*args):

glob_match = GlobMatch(options.skip)

bad_count = 0
for filename in args:
# ignore hidden files
if is_hidden(filename):
Expand All @@ -545,15 +555,16 @@ def main(*args):
continue
if glob_match.match(file):
continue
parse_file(fname, colors, summary)
bad_count += parse_file(fname, colors, summary)

continue

parse_file(filename, colors, summary)
bad_count += parse_file(filename, colors, summary)

if summary:
print("\n-------8<-------\nSUMMARY:")
print(summary)
return bad_count


if __name__ == '__main__':
Expand Down
Empty file added codespell_lib/data/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
Empty file added codespell_lib/tests/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import tempfile

from nose.tools import assert_equal

from codespell_lib import main


def test_basic():
"""Test some basic functionality"""
assert_equal(main('_does_not_exist_'), 0)
with tempfile.NamedTemporaryFile() as f:
f.write('this is a test file\n'.encode('utf-8'))
f.flush()
assert_equal(main(f.name,), 0)
f.write('abandonned'.encode('utf-8'))
f.flush()
assert_equal(main(f.name), 1)
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[nosetests]
with-coverage = 1
cover-package = codespell_lib
detailed-errors = 1
verbose = 3

[flake8]
exclude = build
ignore =
58 changes: 58 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#! /usr/bin/env python

# adapted from mne-python

import os
from os import path as op

try:
import setuptools # noqa to allow --develop
except Exception:
pass
from distutils.core import setup

from codespell_lib import __version__

DISTNAME = 'codespell'
DESCRIPTION = """Codespell"""
MAINTAINER = 'Lucas De Marchi'
MAINTAINER_EMAIL = 'lucas.de.marchi@gmail.com'
URL = 'https://github.com/lucasdemarchi/codespell/'
LICENSE = 'GPL v2'
DOWNLOAD_URL = 'https://github.com/lucasdemarchi/codespell/'
with open('README.md', 'r') as f:
LONG_DESCRIPTION = f.read()

if __name__ == "__main__":
if os.path.exists('MANIFEST'):
os.remove('MANIFEST')

setup(name=DISTNAME,
maintainer=MAINTAINER,
include_package_data=True,
maintainer_email=MAINTAINER_EMAIL,
description=DESCRIPTION,
license=LICENSE,
url=URL,
version=__version__,
download_url=DOWNLOAD_URL,
long_description=LONG_DESCRIPTION,
zip_safe=False,
classifiers=['Intended Audience :: Developers',
'License :: OSI Approved',
'Programming Language :: Python',
'Topic :: Software Development',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Operating System :: MacOS'],
platforms='any',
packages=[
'codespell_lib', 'codespell_lib.tests',
'codespell_lib.data',
],
package_data={'codespell_lib': [
op.join('data', 'dictionary.txt'),

This comment has been minimized.

Copy link
@anatol

anatol Jun 16, 2016

Collaborator

I just downloaded codespell package from https://pypi.python.org/pypi/codespell and I do not see any dictionary included there.

This comment has been minimized.

Copy link
@larsoner

larsoner Jun 16, 2016

Author Member

Fixed in master in 1.9.1, can you check and see if it works now?

op.join('data', 'linux-kernel.exclude'),
]},
scripts=['bin/codespell.py'])
32 changes: 32 additions & 0 deletions tools/travis_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Tools for working with travis-ci
WHEELHOSTS="travis-wheels.scikit-image.org travis-dev-wheels.scipy.org"

PIP_FLAGS="--timeout=60 --no-index"

for host in $WHEELHOSTS; do
PIP_FLAGS="${PIP_FLAGS} --trusted-host ${host} --find-links=http://${host}"
done


retry () {
# https://gist.github.com/fungusakafungus/1026804
local retry_max=5
local count=$retry_max
while [ $count -gt 0 ]; do
"$@" && break
count=$(($count - 1))
sleep 1
done

[ $count -eq 0 ] && {
echo "Retry failed [$retry_max]: $@" >&2
return 1
}
return 0
}


wheelhouse_pip_install() {
# Install pip requirements via travis wheelhouse
retry pip install $PIP_FLAGS $@
}

0 comments on commit b400e42

Please sign in to comment.