-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert bouncer to an application (#36)
Some of the upcoming changes include adding multiple config files (supervisor, collectd), and it doesn't really make sense to keep bouncer as a Python package anymore in my opinion. This also means that we won't have specific versions anymore but have the same approach to version numbers as h, namely the date and sha of the most recent commit. This will also be reflected in the version number that we report to Sentry.
- Loading branch information
1 parent
fe400bb
commit c8eaeff
Showing
17 changed files
with
111 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bouncer/_version.py export-subst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
*.egg-info | ||
*.pyc | ||
node_modules | ||
|
||
.coverage | ||
bouncer/static/scripts/bundle.js | ||
.coverage.* | ||
.cache | ||
dist | ||
.tox | ||
|
||
node_modules | ||
bouncer/static/scripts/bundle.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import datetime | ||
import subprocess | ||
from subprocess import DEVNULL # Python 3 | ||
|
||
__all__ = ('get_version',) | ||
|
||
# git-archive substitution markers. When this file is written out by a `git | ||
# archive` command, these will be replaced by the short commit hash and the | ||
# commit date, respectively. | ||
VERSION_GIT_REF = '$Format:%h$' | ||
VERSION_GIT_DATE = '$Format:%ct$' | ||
|
||
# Fallback version in case we cannot derive the version. | ||
VERSION_UNKNOWN = '0+unknown' | ||
|
||
|
||
def fetch_git_ref(): | ||
ref = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], | ||
stderr=DEVNULL).strip() | ||
return ref.decode('utf-8') | ||
|
||
|
||
def fetch_git_date(ref): | ||
ts = subprocess.check_output(['git', 'show', '-s', '--format=%ct', ref]) | ||
return datetime.datetime.fromtimestamp(int(ts)) | ||
|
||
|
||
def fetch_git_dirty(): | ||
dirty_tree = subprocess.call(['git', 'diff-files', '--quiet']) != 0 | ||
dirty_index = subprocess.call(['git', 'diff-index', '--quiet', | ||
'--cached', 'HEAD']) != 0 | ||
return dirty_tree or dirty_index | ||
|
||
|
||
def git_version(): | ||
ref = fetch_git_ref() | ||
date = fetch_git_date(ref) | ||
dirty = fetch_git_dirty() | ||
return pep440_version(date, ref, dirty) | ||
|
||
|
||
def git_archive_version(): | ||
ref = VERSION_GIT_REF | ||
date = datetime.datetime.fromtimestamp(int(VERSION_GIT_DATE)) | ||
return pep440_version(date, ref) | ||
|
||
|
||
def pep440_version(date, ref, dirty=False): | ||
"""Build a PEP440-compliant version number from the passed information.""" | ||
return '{date}+g{ref}{dirty}'.format(date=date.strftime('%Y%m%d'), | ||
ref=ref, | ||
dirty='.dirty' if dirty else '') | ||
|
||
|
||
def get_version(): | ||
"""Fetch the current application version.""" | ||
# First we try to retrieve the current application version from git. | ||
try: | ||
return git_version() | ||
except (subprocess.CalledProcessError, FileNotFoundError): | ||
pass | ||
|
||
# We are not in a git checkout or extracting the version from git failed, | ||
# so we attempt to read a version written into the header of this file by | ||
# `git archive`. | ||
if not VERSION_GIT_REF.startswith('$'): | ||
return git_archive_version() | ||
|
||
# If neither of these strategies work, we fall back to VERSION_UNKNOWN. | ||
return VERSION_UNKNOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-r requirements.txt | ||
|
||
coverage | ||
mock | ||
prospector | ||
pytest | ||
pytest-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
certifi==2016.9.26 | ||
elasticsearch>=2.0.0,<3.0.0 | ||
gunicorn==19.4.5 | ||
pyramid==1.6.1 | ||
pyramid-jinja2==2.6.2 | ||
requests==2.12.4 | ||
requests-aws4auth==0.9 | ||
raven==5.10.2 | ||
statsd==3.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
[check-manifest] | ||
ignore = | ||
*/test | ||
*/test/* | ||
.* | ||
node_modules | ||
|
||
[pep257] | ||
ignore = D202 | ||
explain = true | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters