Skip to content

Commit

Permalink
Flake8.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed May 15, 2020
1 parent 714b9d2 commit 940b728
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -23,6 +23,7 @@ def read(*rnames):
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()


setup(
name="z3c.recipe.tag",
version='0.9.0.dev0',
Expand Down
29 changes: 19 additions & 10 deletions src/z3c/recipe/tag/__init__.py
Expand Up @@ -20,6 +20,7 @@
import zc.buildout.easy_install
import zc.recipe.egg


class TagsMaker(object):

def __init__(self, buildout, name, options):
Expand Down Expand Up @@ -73,7 +74,7 @@ def install(self):
self.buildout['buildout']['bin-directory'],
extra_paths=self._delegated.extra_paths,
initialization=initialization,
))
))

return generated

Expand All @@ -99,14 +100,15 @@ def getpath(candidates):
raise RuntimeError(
'Can\'t find executable for any of: %s' % candidates)


class Builder:
def get_relpaths(self, paths):
working_dir = os.getcwd()
return [os.path.relpath(path, working_dir) for path in paths]

def __call__(self, targets=None, languages=None, tag_relative=False):
if not targets:
targets = ('idutils', 'ctags_vi', 'ctags_emacs') # legacy behavior
targets = ('idutils', 'ctags_vi', 'ctags_emacs') # legacy behavior
self.languages = languages or ''
self.tag_relative = tag_relative
paths = [path for path in sys.path
Expand All @@ -128,14 +130,18 @@ def __call__(self, targets=None, languages=None, tag_relative=False):
return results

def _build_idutils(self):
return [['mkid'],
['-m',
pkg_resources.resource_filename(
return [
[
'mkid'
], [
'-m',
pkg_resources.resource_filename(
"z3c.recipe.tag", "id-lang.map"),
'-o',
'ID.new'] + self.paths,
'ID.new',
'ID']
'-o',
'ID.new'
] + self.paths,
'ID.new',
'ID']

def _build_ctags_vi(self):
res = [['ctags-exuberant', 'ctags'],
Expand Down Expand Up @@ -167,12 +173,14 @@ def _build_ctags_bbedit(self):
'--excmd=number', '--tag-relative=no', '--fields=+a+m+n+S']
return res


def append_const(option, opt_str, value, parser, const):
# 'append_const' action added in Py 2.5, and we're in 2.4 :-(
if getattr(parser.values, 'targets', None) is None:
parser.values.targets = []
parser.values.targets.append(const)


def build_tags(args=None):
parser = optparse.OptionParser()
parser.add_option('-l', '--languages', dest='languages',
Expand All @@ -182,7 +190,7 @@ def build_tags(args=None):
parser.add_option('-e', '--ctags-emacs', action='callback',
callback=append_const, callback_args=('ctags_emacs',),
help='flag to build emacs ctags ``TAGS`` file')
parser.add_option('-v', '--ctags-vi', action='callback',
parser.add_option('-v', '--ctags-vi', action='callback',
callback=append_const, callback_args=('ctags_vi',),
help='flag to build vi ctags ``tags`` file')
parser.add_option('-b', '--ctags-bbedit', action='callback',
Expand All @@ -206,6 +214,7 @@ def build_tags(args=None):
builder(targets, languages=options.languages,
tag_relative=options.tag_relative)


try:
import paver.easy
except ImportError:
Expand Down
22 changes: 14 additions & 8 deletions src/z3c/recipe/tag/tests.py
Expand Up @@ -10,6 +10,10 @@
def doctest_tags_recipe():
"""Test for z3c.recipe.tag
>>> write = write # noqa: F821 (undefined name)
>>> system = system # noqa: F821 (undefined name)
>>> cat = cat # noqa: F821 (undefined name)
>>> join = join # noqa: F821 (undefined name)
>>> write('buildout.cfg',
... '''
... [buildout]
Expand Down Expand Up @@ -62,7 +66,7 @@ def tearDown(test):
checker = renormalizing.RENormalizing([
zc.buildout.testing.normalize_path,
# zope.whatever-1.2.3-py2.7.egg -> zope.whatever-pyN.N.egg
(re.compile('-[^ /]+-py\d[.]\d(-\S+)?.egg'), '-pyN.N.egg'),
(re.compile(r'-[^ /]+-py\d[.]\d(-\S+)?.egg'), '-pyN.N.egg'),
# #!/path/to/whatever/python3.2mu -> #!/usr/bin/python
(re.compile('#![^\n]+/python[0-9.mu]*'), '#!/usr/bin/python'),
# location of this source tree
Expand All @@ -72,7 +76,7 @@ def tearDown(test):
# Couldn't find index page for 'zc.recipe.egg' (maybe misspelled?)
# error messages, let's just suppress them
(re.compile("Couldn't find index page for '[a-zA-Z0-9.]+' "
"\(maybe misspelled\?\)\n"), ''),
r"\(maybe misspelled\?\)\n"), ''),
# I've no idea what causes these
# Not found: /tmp/tmpJKH0LKbuildouttests/zc.buildout/
# error messages, let's just suppress them
Expand All @@ -84,13 +88,13 @@ def tearDown(test):
# and zc.buildout has no site isolation, so it finds them there,
# so it doesn't add them to sys.path in the generated scripts
checker += renormalizing.RENormalizing([
(re.compile("\s*'/sample-buildout/eggs/zc.recipe.egg-pyN.N.egg',\n"),
(re.compile(r"\s*'/sample-buildout/eggs/zc.recipe.egg-pyN.N.egg',\n"),
''),
(re.compile("\s*'/sample-buildout/eggs/zc.buildout-pyN.N.egg',\n"),
(re.compile(r"\s*'/sample-buildout/eggs/zc.buildout-pyN.N.egg',\n"),
''),
(re.compile("\s*'/sample-buildout/eggs/distribute-pyN.N.egg',\n"),
(re.compile(r"\s*'/sample-buildout/eggs/distribute-pyN.N.egg',\n"),
''),
(re.compile("\s*'/sample-buildout/eggs/setuptools-pyN.N.egg',\n"),
(re.compile(r"\s*'/sample-buildout/eggs/setuptools-pyN.N.egg',\n"),
''),
])

Expand All @@ -99,6 +103,8 @@ def test_suite():
return unittest.TestSuite([
doctest.DocTestSuite(
setUp=setUp, tearDown=tearDown, checker=checker,
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS|
doctest.REPORT_NDIFF),
optionflags=(
doctest.NORMALIZE_WHITESPACE
| doctest.ELLIPSIS
| doctest.REPORT_NDIFF)),
])

0 comments on commit 940b728

Please sign in to comment.