Skip to content

Commit

Permalink
Document public functions with __all__
Browse files Browse the repository at this point in the history
Also, add missing revision sniffer for version-info.txt
  • Loading branch information
bloodearnest committed Sep 21, 2016
1 parent b41101b commit 4afc1c5
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 3 deletions.
4 changes: 4 additions & 0 deletions TODO.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

* expose @private request decorator to users
* raven integration
* pipeline statsd per request
3 changes: 3 additions & 0 deletions talisker/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
from talisker import revision


__all__ = []


class TestException(Exception):
pass

Expand Down
6 changes: 5 additions & 1 deletion talisker/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
from . import statsd


__all__ = ['access_log_format', 'logger_class']
__all__ = [
'access_log_format',
'logger_class',
'run',
]

# settings for gunicorn when in development
DEVEL_SETTINGS = {
Expand Down
6 changes: 6 additions & 0 deletions talisker/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@

from .request_context import request_context

__all__ = [
'configure',
'configure_logging',
'configure_test_logging',
'extra_logging',
]

_logging_configured = False

Expand Down
9 changes: 9 additions & 0 deletions talisker/request_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
from .request_context import request_context, cleanup
from .logs import set_logging_context


__all__ = [
'HEADER',
'get',
'set',
'context',
'decorator',
]

HEADER = 'X-Request-Id'


Expand Down
6 changes: 6 additions & 0 deletions talisker/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
from .util import parse_url
from . import request_id

__all__ = [
'HEADER'
'get_session',
'configure',
'enable_requests_logging',
]

HEADER = to_native_string(request_id.HEADER)
storage = threading.local()
Expand Down
11 changes: 11 additions & 0 deletions talisker/revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@
revision = None
http_safe_revision = None

__all__ = [
'get',
'set',
'header',
]

def _run(args):
return subprocess.check_output(args, stderr=subprocess.PIPE)


def version_info_txt():
with open('version-info.txt', 'rb') as f:
return f.read()


def git():
return _run(['git', 'rev-parse', 'HEAD'])

Expand All @@ -47,6 +57,7 @@ def setup_py():


revision_funcs = [
version_info_txt,
git,
bzr,
bzr_version_info,
Expand Down
1 change: 1 addition & 0 deletions talisker/statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from urllib.parse import urlparse, parse_qs
from statsd import StatsClient, defaults

__all__ = ['get_client']

_client = None

Expand Down
6 changes: 6 additions & 0 deletions talisker/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
from . import revision


__all__ = [
'set_environ',
'set_headers',
'wrap'
]

def set_environ(app, **kwargs):
def middleware(environ, start_response):
for key, value in kwargs.items():
Expand Down
13 changes: 11 additions & 2 deletions tests/test_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,14 @@ def test_bzr_version_info_py2(monkeypatch):
vinfo = run(['bzr', 'version-info', '--format=python'])
with open('versioninfo.py', 'wb') as f:
f.write(vinfo)
rev = revision.bzr_version_info()
assert rev.strip() == '1'
rev = revision.load_revision()
assert rev == '1'


def test_version_info(monkeypatch):
dir = tempfile.mkdtemp()
monkeypatch.chdir(dir)
with open('version-info.txt', 'wb') as f:
f.write(b'1\n')
rev = revision.load_revision()
assert rev == '1'

0 comments on commit 4afc1c5

Please sign in to comment.