Skip to content

Instantly share code, notes, and snippets.

------- code/__main__.py -------
import os
import pkgutil
from pprint import pprint
import sys
from zipimport import zipimporter
sys.path.insert(0, os.path.join(sys.argv[0], 'deps'))
import twitter
@wickman
wickman / pygoal.diff
Created May 13, 2014 17:08
python goal backend diff
diff --git a/3rdparty/python/BUILD b/3rdparty/python/BUILD
index 1188c3f..7427891 100644
--- a/3rdparty/python/BUILD
+++ b/3rdparty/python/BUILD
@@ -14,14 +14,14 @@
# limitations under the License.
# ==================================================================================================
-def make_dep(name, dependency_name=None):
+def make_dep(name, dependency_name=None, **kw):
@wickman
wickman / setup.py
Created May 14, 2014 20:36
example autogenerated setup.py
# DO NOT EDIT THIS FILE -- AUTOGENERATED BY PANTS
# Target: PythonLibrary(src/main/python/apache/thermos/observer/BUILD:observer)
from setuptools import setup
setup(**
{ 'description': 'The Thermos observer web interface.',
'entry_points': { 'console_scripts': [ 'thermos_observer = apache.thermos.observer.bin.thermos_observer:proxy_main']},
'install_requires': [ 'apache.thermos.monitoring==0.5.0-DEV1399063100',
'mako==0.4.0',
@wickman
wickman / requests.diff
Created June 11, 2014 16:14
requests patch to twitter.common.http
diff --git a/src/python/twitter/common/python/http/http.py b/src/python/twitter/common/python/http/h
index 51d0543..db5ab05 100644
--- a/src/python/twitter/common/python/http/http.py
+++ b/src/python/twitter/common/python/http/http.py
@@ -6,7 +6,7 @@ import struct
import time
from ..common import safe_delete, safe_mkdir, safe_mkdtemp
-from ..compatibility import PY2, PY3
+from ..compatibility import PY2, PY3, StringIO
@wickman
wickman / thread_registry.py
Created August 27, 2014 22:49
healthy thread registry
import threading
from twitter.common import log
from twitter.common.exceptions import ExceptionalThread
class ThreadRegistry(ExceptionalThread):
DEFAULT_WAIT_INTERVAL_SECS = 1.0
def __init__(self, wait_interval=DEFAULT_WAIT_INTERVAL_SECS):
@wickman
wickman / coverage.patch
Created September 12, 2014 20:18
custom pants pytest runner
diff --git a/src/python/twitter/pants/BUILD b/src/python/twitter/pants/BUILD
index c4cfaac..656392d 100644
--- a/src/python/twitter/pants/BUILD
+++ b/src/python/twitter/pants/BUILD
@@ -27,13 +27,13 @@ python_library(
name='pants-deps',
dependencies=[
pants('3rdparty/python:ansicolors'),
+ pants('3rdparty/python:coverage'),
pants('3rdparty/python:elementtree'),
@wickman
wickman / gist:1236753
Created September 23, 2011 04:38
bottle bug
class BottleServer(object):
@staticmethod
def route(*args, **kwargs):
def annotated(function):
if hasattr(function, '__routes__'):
function.__routes__.append( (args, kwargs) )
else:
function.__routes__ = [(args, kwargs)]
return function
return annotated
@wickman
wickman / bottle_test.py
Created September 23, 2011 19:39
bottle bug simplest example
import bottle
bottle.debug(True)
class BottleServer(object):
def __init__(self):
self.app = bottle.Bottle()
self.setup_routes()
def hello(self, **kw):
@wickman
wickman / gist:2484405
Created April 24, 2012 22:45
class decorator to inherit documentation from abstract base class
from abc import ABCMeta, abstractmethod
def documented_by(documenting_abc):
def document(cls):
cls_dict = cls.__dict__.copy()
for attr in documenting_abc.__abstractmethods__:
cls_dict[attr].__doc__ = getattr(documenting_abc, attr).__doc__
return type(cls.__name__, cls.__mro__[1:], cls_dict)
return document
@wickman
wickman / bootstrap_python.sh
Last active December 17, 2015 04:29
python distro bootstrapper for osx
INSTALL_ROOT=$HOME/Python
CPY=$INSTALL_ROOT/CPython
PYPY=$INSTALL_ROOT/PyPy
SANDBOX=$(mktemp -d /tmp/python.XXXXXX)
CURL='wget --no-check-certificate'
mkdir -p $INSTALL_ROOT