Skip to content

Commit

Permalink
Move the tag generation recipe out of my Sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
pcardune committed Mar 16, 2008
0 parents commit 694a3fa
Show file tree
Hide file tree
Showing 8 changed files with 484 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.txt
@@ -0,0 +1,37 @@
z3c.recipe.tag
==============

Introduction
------------

This recipe generates a TAGS database file that can be used with a
number of different editors to quickly lookup class and function
definitions in your package's source files and egg dependencies.

Dependencies
------------

Before running a tags enabled buildout, you must install the
appropriate command line tag generation tools: exuberant-ctags and
id-utils. In Ubuntu, you can install these with apt-get::

$ sudo apt-get install exuberant-ctags id-utils

How to use this recipe
----------------------

Suppose you have an egg called ``MyApplication``. To use this recipe with
buildout, you would add the following to the ``buildout.cfg`` file::

[tags]
recipe = z3c.recipe.tag:tags
eggs = MyApplication

This produces a script file in the ``bin/`` directory which you can
then run like this::

$ ./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).
124 changes: 124 additions & 0 deletions bootstrap.py
@@ -0,0 +1,124 @@
##############################################################################
#
# 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)
15 changes: 15 additions & 0 deletions buildout.cfg
@@ -0,0 +1,15 @@
[buildout]
index = http://download.zope.org/zope3.4
develop = .
parts = z3c.recipe.tag test
newest = false

[z3c.recipe.tag]
recipe = zc.recipe.egg
unzip = true
eggs = z3c.recipe.tag

[test]
recipe = zc.recipe.testrunner
eggs = z3c.recipe.tag
defaults = ['--exit-with-status', '--tests-pattern', '^f?tests$', '-v']
68 changes: 68 additions & 0 deletions setup.py
@@ -0,0 +1,68 @@
#!/usr/bin/env python
# -*- Encoding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 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.
#
##############################################################################
"""Setup for z3c.recipe.tag package
$Id$
"""

# Check python version
import sys
if sys.version_info < (2, 4):
print >> sys.stderr, '%s: need Python 2.4 or later.' % sys.argv[0]
print >> sys.stderr, 'Your python is %s' % sys.version
sys.exit(1)

import os
from setuptools import setup, find_packages

def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()

setup(
name="z3c.recipe.tag",
version='0.1.0-dev',
author="Ignas Mikalajūnas",
description="Generate ctags from eggs for development.",
long_description=read('README.txt')
license="ZPL 2.1",
maintainer="Paul Carduner",
maintainer_email="zope-dev@zope.org",
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: Zope Public License",
"Operating System :: OS Independent",
"Programming Language :: Python"],
url='http://svn.zope.org/Sanbox/pcardune/z3c.recipe.tag/',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['z3c','z3c.recipe'],
install_requires=['setuptools',
'zc.buildout',
#these two come from apt-get!
#'id-utils',
#'ctags-exuberant'
'zc.recipe.egg'],
entry_points="""
[zc.buildout]
tags = z3c.recipe.tag:TagsMaker
[console_scripts]
build_tags = z3c.recipe.tag:build_tags
""",
zip_safe=False,
include_package_data=True,
)
22 changes: 22 additions & 0 deletions src/z3c/__init__.py
@@ -0,0 +1,22 @@
##############################################################################
#
# Copyright (c) 2005 Zope Foundation 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.
#
##############################################################################
"""
$Id$
"""

# this is a namespace package
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
pass
22 changes: 22 additions & 0 deletions src/z3c/recipe/__init__.py
@@ -0,0 +1,22 @@
##############################################################################
#
# Copyright (c) 2005 Zope Foundation 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.
#
##############################################################################
"""
$Id$
"""

# this is a namespace package
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
pass
99 changes: 99 additions & 0 deletions src/z3c/recipe/tag/__init__.py
@@ -0,0 +1,99 @@
##############################################################################
#
# Copyright (c) 2007 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.
#
##############################################################################
import os, sys
import pkg_resources

import zc.buildout.easy_install
import zc.recipe.egg

class TagsMaker(object):

def __init__(self, buildout, name, options):
self.buildout = buildout
self.name = name
self.options = options
options['script'] = os.path.join(buildout['buildout']['bin-directory'],
options.get('script', self.name),
)

if not options.get('working-directory', ''):
options['location'] = os.path.join(
buildout['buildout']['parts-directory'], name)
self.egg = zc.recipe.egg.Egg(buildout, name, options)

def install(self):
options = self.options
dest = []
eggs, ws = self.egg.working_set(('z3c.recipe.tag',))

wd = options.get('working-directory', '')
if not wd:
wd = options['location']
if os.path.exists(wd):
assert os.path.isdir(wd)
else:
os.mkdir(wd)
dest.append(wd)

initialization = initialization_template % self.buildout['buildout']['directory']

env_section = options.get('environment', '').strip()
if env_section:
env = self.buildout[env_section]
for key, value in env.items():
initialization += env_template % (key, value)

initialization_section = options.get('initialization', '').strip()
if initialization_section:
initialization += initialization_section

dest.extend(zc.buildout.easy_install.scripts(
[(options['script'], 'z3c.recipe.tag', 'build_tags')],
ws, options['executable'],
self.buildout['buildout']['bin-directory'],
extra_paths=self.egg.extra_paths,
initialization = initialization,
))

return dest

update = install


initialization_template = """import os
sys.argv[0] = os.path.abspath(sys.argv[0])
os.chdir(%r)
"""

env_template = """os.environ['%s'] = %r
"""


def build_tags():
paths = [path for path in sys.path
if not path.endswith('.zip')]
paths = " ".join(paths)

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")

command = "ctags-exuberant -R --languages=-JavaScript -f tags.new %s" % paths
if os.system(command) == 0:
os.system("mv tags.new tags")

command = "ctags-exuberant -e -R --languages=-JavaScript -f TAGS.new %s" % paths
if os.system(command) == 0:
os.system("mv TAGS.new TAGS")

0 comments on commit 694a3fa

Please sign in to comment.