Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 96a527ba3dd9ffc7f31f348c64ff99c5a77f21ae @brentp committed Jun 23, 2011
@@ -0,0 +1,11 @@
+*.pyc
+
+.installed.cfg
+bin
+develop-eggs
+
+*.egg-info
+
+tmp
+build
+dist
@@ -0,0 +1,2 @@
+include README.rst
+include NEWS.txt
@@ -0,0 +1,10 @@
+News
+====
+
+0.1
+---
+
+*Release date: 15-Mar-2010*
+
+* Initial project structure.
+
@@ -0,0 +1,56 @@
+Toolshed: Less Boiler-Plate
+===========================
+
+This is a collection of well-tested, simple modules and functions
+that I use frequently
+
+Files
+-----
+
+If all you have is a file with a header and you want to get a dictionary
+for each row::
+
+ >>> from toolshed import reader
+ >>> for d in reader('src/toolshed/tests/data/file_data.txt'):
+ ... print d['a'], d['b'], d['c']
+ 1 2 3
+ 11 12 13
+ 21 22 23
+
+works the same for gzipped and bzipped files and for stdin (via "-")::
+
+ >>> for drow in (d for d in reader('src/toolshed/tests/data/file_data.txt.gz') if int(d['a']) > 10):
+ ... print drow['a'], drow['b'], drow['c']
+ 11 12 13
+ 21 22 23
+
+Shedskinner
+-----------
+
+Shedskin is a program that takes python scripts, infers the types based
+on example input and generates fast C++ code that compiles to a python
+extension module. Shedskinner is a decorator that automates this for a single
+function. Use looks like::
+
+ from toolshed import shedskinner
+
+ @shedskinner((2, 12), long=True, fast_random=True):
+ def adder(a, b):
+ return a + b
+
+Where here, we have decorated the adder function to make it a compiled, fast
+version that accepts and returns integers. The (2, 12) are example arguments
+to the function so that shedskin can infer types.
+The keyword arguments are sent to the compiler (see:
+https://gist.github.com/1036972) for more examples.
+
+Links
+-----
+
+- `Distribute`_
+- `Buildout`_
+- `modern-package-template`_
+
+.. _Buildout: http://www.buildout.org/
+.. _Distribute: http://pypi.python.org/pypi/distribute
+.. _`modern-package-template`: http://pypi.python.org/pypi/modern-package-template
@@ -0,0 +1,113 @@
+##############################################################################
+#
+# 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.
+
+$Id: bootstrap.py 102545 2009-08-06 14:49:47Z chrisw $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+from optparse import OptionParser
+
+tmpeggs = tempfile.mkdtemp()
+
+is_jython = sys.platform.startswith('java')
+
+# parsing arguments
+parser = OptionParser()
+parser.add_option("-v", "--version", dest="version",
+ help="use a specific zc.buildout version")
+parser.add_option("-d", "--distribute",
+ action="store_true", dest="distribute", default=True,
+ help="Use Disribute rather than Setuptools.")
+
+options, args = parser.parse_args()
+
+if options.version is not None:
+ VERSION = '==%s' % options.version
+else:
+ VERSION = ''
+
+USE_DISTRIBUTE = options.distribute
+args = args + ['bootstrap']
+
+to_reload = False
+try:
+ import pkg_resources
+ if not hasattr(pkg_resources, '_distribute'):
+ to_reload = True
+ raise ImportError
+except ImportError:
+ ez = {}
+ if USE_DISTRIBUTE:
+ exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
+ else:
+ exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+ if to_reload:
+ reload(pkg_resources)
+ else:
+ import pkg_resources
+
+if sys.platform == 'win32':
+ def quote(c):
+ if ' ' in c:
+ return '"%s"' % c # work around spawn lamosity on windows
+ else:
+ return c
+else:
+ def quote (c):
+ return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws = pkg_resources.working_set
+
+if USE_DISTRIBUTE:
+ requirement = 'distribute'
+else:
+ requirement = 'setuptools'
+
+if is_jython:
+ import subprocess
+
+ assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
+ quote(tmpeggs), 'zc.buildout' + VERSION],
+ env=dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse(requirement)).location
+ ),
+ ).wait() == 0
+
+else:
+ assert os.spawnle(
+ os.P_WAIT, sys.executable, quote (sys.executable),
+ '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse(requirement)).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout' + VERSION)
+import zc.buildout.buildout
+zc.buildout.buildout.main(args)
+shutil.rmtree(tmpeggs)
No changes.
@@ -0,0 +1,41 @@
+from setuptools import setup, find_packages
+import sys, os
+
+here = os.path.abspath(os.path.dirname(__file__))
+README = open(os.path.join(here, 'README.rst')).read()
+NEWS = open(os.path.join(here, 'NEWS.txt')).read()
+
+
+version = '0.1'
+
+install_requires = [
+ 'nose',
+]
+
+
+setup(name='toolshed',
+ version=version,
+ description="Tools for data",
+ long_description=README + '\n\n' + NEWS,
+ classifiers=[
+ # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+ 'Topic :: Scientific/Engineering',
+ 'Topic :: Scientific/Engineering :: Bio-Informatics',
+ 'Topic :: Text Processing',
+ 'Topic :: Utilities'
+ ],
+ keywords='bioinformatics',
+ author='Brent Pedersen',
+ author_email='bpederse@gmail.com',
+ url='https://github.com/brentp/toolshed/',
+ license='BSD',
+ packages=find_packages('src'),
+ package_dir = {'': 'src'},include_package_data=True,
+ test_suite='nose.collector',
+ zip_safe=False,
+ install_requires=install_requires,
+ entry_points={
+ 'console_scripts':
+ ['toolshed=toolshed:main']
+ }
+)
@@ -0,0 +1,21 @@
+from files import reader, tokens, nopen
+import sys
+
+try:
+ from optimize import shedskinner
+except ImportError:
+ pass
+
+
+def main():
+ #import argparse
+ #p = argparse.ArgumentParser(__doc__)
+ pass
+
+
+if __name__ == "__main__":
+ import doctest
+ if doctest.testmod(optionflags=doctest.ELLIPSIS |\
+ doctest.NORMALIZE_WHITESPACE).failed == 0:
+ main()
+
@@ -0,0 +1,71 @@
+"""
+ %prog [options] files
+"""
+import sys
+import gzip
+import bz2
+
+
+def nopen(f, mode="rb"):
+ """
+ open a file that's gzipped or return stdin for '-'
+
+ >>> nopen('-') == sys.stdin, nopen('-', 'w') == sys.stdout
+ (True, True)
+
+ >>> nopen(sys.argv[0])
+ <open file '...', mode 'r...>
+
+ # an already open file.
+ >>> nopen(open(sys.argv[0]))
+ <open file '...', mode 'r...>
+ """
+ if not isinstance(f, basestring):
+ return f
+ return {"r": sys.stdin, "w": sys.stdout}[mode[0]] if f == "-" \
+ else gzip.open(f, mode) if f.endswith(".gz") \
+ else bz2.BZ2File(f, mode) if f.endswith((".bz", ".bz2")) \
+ else open(f, mode)
+
+
+def tokens(line, sep="\t"):
+ r"""
+ >>> tokens("a\tb\tc\n")
+ ['a', 'b', 'c']
+ """
+ return line.rstrip("\r\n").split(sep)
+
+
+def reader(fname, header=True, sep="\t"):
+ r"""
+ for each row in the file `fname` generate dicts if `header` is True
+ or lists if `header` is False. The dict keys are drawn from the first
+ line. If `header` is a list of names, those will be used as the dict
+ keys.
+
+ >>> from StringIO import StringIO
+ >>> get_str = lambda : StringIO("a\tb\tname\n1\t2\tfred\n11\t22\tjane")
+ >>> list(reader(get_str()))
+ [{'a': '1', 'b': '2', 'name': 'fred'},
+ {'a': '11', 'b': '22', 'name': 'jane'}]
+
+ >>> list(reader(get_str(), header=False))
+ [['a', 'b', 'name'], ['1', '2', 'fred'], ['11', '22', 'jane']]
+ """
+ line_gen = (l.rstrip("\r\n").split(sep) for l in nopen(fname))
+ if header == True:
+ header = line_gen.next()
+ header[0] = header[0].lstrip("#")
+
+ if header:
+ for toks in line_gen:
+ yield dict(zip(header, toks))
+ else:
+ for toks in line_gen:
+ yield toks
+
+if __name__ == "__main__":
+ import doctest
+ if doctest.testmod(optionflags=doctest.ELLIPSIS |\
+ doctest.NORMALIZE_WHITESPACE).failed == 0:
+ pass
Oops, something went wrong.

0 comments on commit 96a527b

Please sign in to comment.