aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2013-10-02 15:34:18 +0200
committerMatěj Cepl <mcepl@redhat.com>2013-10-02 15:55:08 +0200
commit03f62c392f3c140f4cefb5ccd129d32734b169c3 (patch)
tree0ffbf9473f669890189a31fe9c775408fdceecba
parent4294510667c2359c63267e6805e4937dce4a7051 (diff)
downloadcucutags-03f62c392f3c140f4cefb5ccd129d32734b169c3.tar.gz
Make a proper Python package out of it.0.3.0
* add setup.py * add proper README.md * make script more object-oriented and with more simple API.
-rw-r--r--.gitignore5
-rw-r--r--README.md11
-rwxr-xr-xcucutags.py73
-rw-r--r--setup.py36
4 files changed, 89 insertions, 36 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bb0acb3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+*~
+*.pyc
+build/
+MANIFEST
+dist/
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e3cfc7f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,11 @@
+cucutags provides a simple generator of ctags-like tags file for
+the combination of [Gherkin language features](https://github.com/cucumber/cucumber/wiki/Gherkin) and Python [steps](https://github.com/behave/behave).
+
+Unfortunately, no text editor known to me is able to use so
+generated tags file. However, this script can be also used by any
+other Python script as a library, and thus for example
+[vim](http://www.vim.org) can use it via
+[vim-behave](https://gitorious.org/cucutags/vim-behave) plugin.
+
+All bug reports and enhancement requests, please, send to the
+email listed in the script file.
diff --git a/cucutags.py b/cucutags.py
index cd01dcf..6d8f907 100755
--- a/cucutags.py
+++ b/cucutags.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
+# -*- coding: utf-8 -*-
# Copyright (C) 2013 Red Hat, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -19,7 +20,6 @@
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
import os
import io
import re
@@ -30,6 +30,10 @@ logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
import parse
import argparse
+__docformat__ = 'reStructuredText'
+__version__ = "0.3.0"
+__author__ = u"Matěj Cepl <mcepl_at_redhat_dot_com>"
+
class Target(object):
"""
@@ -137,45 +141,42 @@ class CodeFile(io.TextIOWrapper):
return out
-def walker(startdir):
- feature_list = []
- target_list = []
-
- for root, dirs, files in os.walk(startdir):
- for directory in dirs:
- d = SourceFile(directory)
- if d.ishidden():
- dirs.remove(d.name)
+class Session(object):
+ def __init__(self, startdir):
+ self.feature_list = []
+ self.target_list = []
- for f in files:
- in_f = CodeFile(os.path.join(root, f))
+ for root, dirs, files in os.walk(startdir):
+ for directory in dirs:
+ d = SourceFile(directory)
+ if d.ishidden():
+ dirs.remove(d.name)
- new_out = in_f.process_file(root)
- feature_list.extend(new_out['features'])
- target_list.extend(new_out['targets'])
+ for f in files:
+ in_f = CodeFile(os.path.join(root, f))
- return feature_list, target_list
+ new_out = in_f.process_file(root)
+ self.feature_list.extend(new_out['features'])
+ self.target_list.extend(new_out['targets'])
+ def generate_tags(self, out_dir):
+ out = []
+ for feat in self.feature_list:
+ trg = feat.match(self.target_list)
+ if trg:
+ rel_filename = os.path.relpath(trg.filename, out_dir)
+ logging.debug("feat = %s", feat)
+ logging.debug("trg.filename = %s", rel_filename)
+ logging.debug("trg.lineno = %s", trg.lineno)
+ out.append((feat, rel_filename, trg.lineno,))
-def matcher(features, targets, out_dir):
- out = []
- for feat in features:
- trg = feat.match(targets)
- if trg:
- rel_filename = os.path.relpath(trg.filename, out_dir)
- logging.debug("feat = %s", feat)
- logging.debug("trg.filename = %s", rel_filename)
- logging.debug("trg.lineno = %s", trg.lineno)
- out.append((feat, rel_filename, trg.lineno,))
-
- return out
-
+ return out
-def get_step(feature, feat_list, target_list):
- for feat in feat_list:
- trg = feat.match(target_list)
- if trg:
- return trg.filename, trg.lineno
+ def get_step(self, feature):
+ for feat in self.feature_list:
+ trg = feat.match(self.target_list)
+ if trg:
+ return trg.filename, trg.lineno
if __name__ == "__main__":
@@ -197,7 +198,7 @@ if __name__ == "__main__":
outdir = os.curdir
logging.debug("outf = %s", outf)
- raw = walker(os.curdir)
- res = matcher(raw[0], raw[1], outdir)
+ raw = Session(os.curdir)
+ res = raw.generate_tags(outdir)
for r in res:
outf.write(unicode("%s\t%s\t%s\n" % r))
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..b5888f2
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,36 @@
+# coding: utf-8
+from __future__ import absolute_import, print_function
+from distutils.core import setup
+import os.path
+import cucutags
+
+
+def read(fname):
+ with open(os.path.join(os.path.dirname(__file__), fname)) as inf:
+ return "\n" + inf.read().replace("\r\n", "\n")
+
+setup(
+ name='cucutags',
+ py_modules=['cucutags'],
+ version=str(cucutags.__version__),
+ description='Generates ctags for BDD .feature/behave steps',
+ author=u'Matěj Cepl',
+ author_email='mcepl@redhat.com',
+ url='https://gitorious.org/cucutags/cucutags/',
+ long_description=read("README.md"),
+ keywords=['BDD', 'behave', 'ctags', 'tags'],
+ classifiers=[
+ "Programming Language :: Python",
+ "Programming Language :: Python :: 2",
+ "Programming Language :: Python :: 2.6",
+ "Programming Language :: Python :: 2.7",
+ "Development Status :: 3 - Alpha",
+ "Environment :: Console",
+ "Intended Audience :: Information Technology",
+ "License :: OSI Approved :: MIT License",
+ "Operating System :: OS Independent",
+ "Topic :: Software Development :: Libraries :: Python Modules",
+ "Topic :: Software Development :: Testing"
+ ],
+ requires=["parse"]
+)