[Checkins] SVN: z3c.recipe.tag/trunk/ Specify tools to be built in the commandline; add support for Mac, BBEdit.

Gary Poster gary at modernsongs.com
Thu Aug 28 21:12:06 EDT 2008


Log message for revision 90566:
  Specify tools to be built in the commandline; add support for Mac, BBEdit.
  
  * Allow command-line choices for what files to build, and what languages ctags
    should parse.  (Note that the default behavior of running ``./bin/tags``
    is the same as previous releases.)
  
  * Support the Mac OS X packaging system "macports" (exuberant ctags is
    ``ctags-exuberant`` in Ubuntu and ``ctags`` in macports).
  
  * Support creating BBEdit-style ctags files.
  
  * Small changes for development (use bootstrap external, set svn:ignore)
  
  

Changed:
  _U  z3c.recipe.tag/trunk/
  U   z3c.recipe.tag/trunk/CHANGES.txt
  U   z3c.recipe.tag/trunk/README.txt
  D   z3c.recipe.tag/trunk/bootstrap.py
  U   z3c.recipe.tag/trunk/setup.py
  U   z3c.recipe.tag/trunk/src/z3c/recipe/tag/__init__.py

-=-

Property changes on: z3c.recipe.tag/trunk
___________________________________________________________________
Name: svn:ignore
   + develop-eggs
bin
parts
.installed.cfg
dist
*.kpf
*.bbproject
tags
TAGS
ID

Name: svn:externals
   + bootstrap svn://svn.zope.org/repos/main/zc.buildout/trunk/bootstrap


Modified: z3c.recipe.tag/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.tag/trunk/CHANGES.txt	2008-08-28 22:26:04 UTC (rev 90565)
+++ z3c.recipe.tag/trunk/CHANGES.txt	2008-08-29 01:12:04 UTC (rev 90566)
@@ -2,11 +2,20 @@
 CHANGES
 =======
 
-0.1.1 (unreleased)
+0.2.0 (unreleased)
 ------------------
 
-* ...
+* Allow command-line choices for what files to build, and what languages ctags
+  should parse.  (Note that the default behavior of running ``./bin/tags``
+  is the same as previous releases.)
 
+* Support the Mac OS X packaging system "macports" (exuberant ctags is
+  ``ctags-exuberant`` in Ubuntu and ``ctags`` in macports).
+
+* Support creating BBEdit-style ctags files.
+
+* Small changes for development (use bootstrap external, set svn:ignore)
+
 0.1.0 (2008-03-16)
 ------------------
 

Modified: z3c.recipe.tag/trunk/README.txt
===================================================================
--- z3c.recipe.tag/trunk/README.txt	2008-08-28 22:26:04 UTC (rev 90565)
+++ z3c.recipe.tag/trunk/README.txt	2008-08-29 01:12:04 UTC (rev 90566)
@@ -17,6 +17,11 @@
 
   $ sudo apt-get install exuberant-ctags id-utils
 
+On a Mac, download and install ``port`` from http://www.macports.org/ and then
+install ctags and utils in this way::
+
+  $ sudo port install ctags idutils
+
 How to use this recipe
 ----------------------
 
@@ -32,6 +37,44 @@
 
   $ ./bin/tags
 
-This script produces a file called ``TAGS`` in the directory from
-which you ran the script.  You can then use this file in your editor
-of choice (e.g. emacs).
\ No newline at end of file
+By default, this script produces three files in the directory from
+which you ran the script: 
+
+- a ctags file called ``TAGS`` for use by emacs,
+- a ctags file called ``tags`` for use by vi, and
+- an idutils file called ``ID`` for use by either.
+
+You can then use these file in your editor of choice.
+
+Optionally, you can select which files to build.  The following is the output
+of ``./bin/tags --help``::
+
+    usage: build_tags [options]
+
+    options:
+      -h, --help            show this help message and exit
+      -l LANGUAGES, --languages=LANGUAGES
+                            ctags comma-separated list of languages
+      -e, --ctags-emacs     flag to build emacs ctags ``TAGS`` file
+      -v, --ctags-vi        flag to build vi ctags ``tags`` file
+      -b, --ctags-bbedit    flag to build bbedit ctags ``tags`` file
+      -i, --idutils         flag to build idutils ``ID`` file
+
+(BBEdit_ is a Macintosh text editor.)
+
+Legacy support
+--------------
+
+To follow a legacy pattern in this package, running ``./bin/tags`` without
+options assumes a --languages value of "-JavaScript".  Passing *any* option
+to ``./bin/tags`` will turn this behavior off.  Thus, these two commands are
+effectively identical, making ctags files that exclude JavaScript::
+
+  $ ./bin/tags
+  $ ./bin/tags -iev --languages=-JavaScript
+
+But this command will produce ctags files that include JavaScript.
+
+  $ ./bin/tags -iev
+
+.. _BBEdit: http://barebones.com/products/bbedit/

Deleted: z3c.recipe.tag/trunk/bootstrap.py
===================================================================
--- z3c.recipe.tag/trunk/bootstrap.py	2008-08-28 22:26:04 UTC (rev 90565)
+++ z3c.recipe.tag/trunk/bootstrap.py	2008-08-29 01:12:04 UTC (rev 90566)
@@ -1,124 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Bootstrap a buildout-based project
-
-Simply run this script in a directory containing a buildout.cfg.
-The script accepts buildout command-line options, so you can
-use the -c option to specify an alternate configuration file.
-
-"""
-import os, shutil, sys, tempfile, urllib2
-
-join = os.path.join
-py_version = 'python%s.%s' % (sys.version_info[0], sys.version_info[1])
-
-def mkdir(path):
-    if not os.path.exists(path):
-        print 'Creating %s' % path
-        os.makedirs(path)
-
-def symlink(src, dest):
-    if not os.path.exists(dest):
-        os.symlink(src, dest)
-    else:
-        print 'Symlink %s already exists' % dest
-
-
-def rmtree(dir):
-    if os.path.exists(dir):
-        print 'Deleting tree %s' % dir
-        shutil.rmtree(dir)
-
-def make_exe(fn):
-    if os.name == 'posix':
-        oldmode = os.stat(fn).st_mode & 07777
-        newmode = (oldmode | 0555) & 07777
-        os.chmod(fn, newmode)
-
-def make_virtual_python():
-    if os.name != 'posix':
-        print "This script only works on Unix-like platforms, sorry."
-        return
-
-    lib_dir = join('python', 'lib', py_version)
-    inc_dir = join('python', 'include', py_version)
-    bin_dir = join('python', 'bin')
-
-    if sys.executable.startswith(bin_dir):
-        print 'Please use the *system* python to run this script'
-        return
-
-    mkdir('python')
-    prefix = sys.prefix
-    mkdir(lib_dir)
-    stdlib_dir = join(prefix, 'lib', py_version)
-    for fn in os.listdir(stdlib_dir):
-        if fn != 'site-packages':
-            symlink(join(stdlib_dir, fn), join(lib_dir, fn))
-
-    mkdir(join(lib_dir, 'site-packages'))
-
-    mkdir(inc_dir)
-    stdinc_dir = join(prefix, 'include', py_version)
-    for fn in os.listdir(stdinc_dir):
-        symlink(join(stdinc_dir, fn), join(inc_dir, fn))
-
-    if sys.exec_prefix != sys.prefix:
-        exec_dir = join(sys.exec_prefix, 'lib', py_version)
-        for fn in os.listdir(exec_dir):
-            symlink(join(exec_dir, fn), join(lib_dir, fn))
-
-    mkdir(bin_dir)
-    print 'Copying %s to %s' % (sys.executable, bin_dir)
-    py_executable = join(bin_dir, 'python')
-    if sys.executable != py_executable:
-        shutil.copyfile(sys.executable, py_executable)
-        make_exe(py_executable)
-
-
-if __name__ == "__main__":
-    if sys.executable != os.path.abspath('python/bin/python'):
-        make_virtual_python()
-        sys.exit(os.spawnve(
-                os.P_WAIT, 'python/bin/python',
-                ['python/bin/python'] + sys.argv, os.environ))
-
-    tmpeggs = tempfile.mkdtemp()
-
-    ez = {}
-    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
-                         ).read() in ez
-    ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
-
-    import pkg_resources
-
-    cmd = 'from setuptools.command.easy_install import main; main()'
-    if sys.platform == 'win32':
-        cmd = '"%s"' % cmd # work around spawn lamosity on windows
-
-    ws = pkg_resources.working_set
-    assert os.spawnle(
-        os.P_WAIT, sys.executable, sys.executable,
-        '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
-        dict(os.environ,
-             PYTHONPATH=
-             ws.find(pkg_resources.Requirement.parse('setuptools')).location
-             ),
-        ) == 0
-
-    ws.add_entry(tmpeggs)
-    ws.require('zc.buildout')
-    import zc.buildout.buildout
-    zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
-    shutil.rmtree(tmpeggs)

Modified: z3c.recipe.tag/trunk/setup.py
===================================================================
--- z3c.recipe.tag/trunk/setup.py	2008-08-28 22:26:04 UTC (rev 90565)
+++ z3c.recipe.tag/trunk/setup.py	2008-08-29 01:12:04 UTC (rev 90566)
@@ -33,7 +33,7 @@
 
 setup(
     name="z3c.recipe.tag",
-    version='0.1.1-dev',
+    version='0.2.0b2',
     author="Ignas Mikalajūnas",
     description="Generate ctags from eggs for development.",
     long_description=(read('README.txt')
@@ -57,6 +57,8 @@
                       #these two come from apt-get!
                       #'id-utils',
                       #'ctags-exuberant'
+                      # alternately, on Mac, use macports (macports.org) and
+                      # ``sudo port install ctags idutils``
                       'zc.recipe.egg'],
     entry_points="""
     [zc.buildout]

Modified: z3c.recipe.tag/trunk/src/z3c/recipe/tag/__init__.py
===================================================================
--- z3c.recipe.tag/trunk/src/z3c/recipe/tag/__init__.py	2008-08-28 22:26:04 UTC (rev 90565)
+++ z3c.recipe.tag/trunk/src/z3c/recipe/tag/__init__.py	2008-08-29 01:12:04 UTC (rev 90566)
@@ -11,8 +11,11 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-import os, sys
+import os
+import optparse
 import pkg_resources
+import subprocess
+import sys
 
 import zc.buildout.easy_install
 import zc.recipe.egg
@@ -80,20 +83,96 @@
 """
 
 
-def build_tags():
-    paths = [path for path in sys.path
-             if not path.endswith('.zip')]
-    paths = " ".join(paths)
+def getpath(candidates):
+    paths = os.environ['PATH'].split(os.pathsep)
+    for c in candidates:
+        for p in paths:
+            full = os.path.join(p, c)
+            if os.path.exists(full):
+                return full
 
-    map = pkg_resources.resource_filename("z3c.recipe.tag", "id-lang.map")
-    command = "mkid -m %s -o ID.new %s" % (map, paths)
-    if os.system(command) == 0:
-        os.system("mv ID.new ID")
+class Builder:
+    def __init__(self):
+        self.paths = [path for path in sys.path
+                      if not path.endswith('.zip')]
 
-    command = "ctags-exuberant -R --languages=-JavaScript -f tags.new %s" % paths
-    if os.system(command) == 0:
-        os.system("mv tags.new tags")
+    def __call__(self, targets=None, languages=None):
+        if not targets:
+            targets = ('idutils', 'ctags-vi', 'ctags-emacs') # legacy behavior
+            if languages is None:
+                languages = '-JavaScript' # legacy behavior
+        self.languages = languages or ''
+        results = {}
+        for target in targets:
+            tool_candidates, arguments, source, destination = getattr(
+                self, '_build_%s' % (target,))()
+            arguments[0:0] = [getpath(tool_candidates)]
+            res = subprocess.call(arguments)
+            if res == 0:
+                res = subprocess.call(['mv', source, destination])
+            results[target] = res
+        return results
 
-    command = "ctags-exuberant -e -R --languages=-JavaScript -f TAGS.new %s" % paths
-    if os.system(command) == 0:
-        os.system("mv TAGS.new TAGS")
+    def _build_idutils(self):
+        return [['mkid'],
+                ['-m', 
+                 pkg_resources.resource_filename(
+                    "z3c.recipe.tag", "id-lang.map"),
+                 '-o',
+                 'ID.new'] + self.paths,
+                'ID.new',
+                'ID']
+
+    def _build_ctags_vi(self):
+        res = [['ctags-exuberant', 'ctags'],
+               ['-R',
+                '-f',
+                'tags.new'] + self.paths,
+                'tags.new',
+                'tags']
+        if self.languages:
+            res[1][0:0] = ['--languages=%s' % self.languages]
+        return res
+
+    def _build_ctags_emacs(self):
+        res = self._build_ctags_vi()
+        res[1][0:0] = ['-e']
+        res[3] = 'TAGS'
+        return res
+
+    def _build_ctags_bbedit(self):
+        res = self._build_ctags_vi()
+        res[1][0:0] = [
+            '--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():
+    parser = optparse.OptionParser()
+    parser.add_option('-l', '--languages', dest='languages',
+                      help='ctags comma-separated list of languages')
+    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',
+                      callback=append_const, callback_args=('ctags_vi',),
+                      help='flag to build vi ctags ``tags`` file')
+    parser.add_option('-b', '--ctags-bbedit', action='callback',
+                      callback=append_const, callback_args=('ctags_bbedit',),
+                      help='flag to build bbedit ctags ``tags`` file')
+    parser.add_option('-i', '--idutils', action='callback',
+                      callback=append_const, callback_args=('idutils',),
+                      help='flag to build idutils ``ID`` file')
+    options, args = parser.parse_args()
+    if args:
+        parser.error('no arguments accepted')
+    targets = getattr(options, 'targets', None)
+    if (targets and 'ctags_bbedit' in targets and 'ctags_vi' in targets):
+        parser.error('cannot build both vi and bbedit ctags files (same name)')
+    builder = Builder()
+    builder(targets, options.languages)



More information about the Checkins mailing list