Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Provide a setuptools-based build infrastructure #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
*.pyc
*.swp
*.log
settings.py
dump.rdb
nohup.out
/build
/dist
*.egg
/nosetests.xml
*.egg-info
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ install:
- PYTHONPATH= PATH=/home/travis/anaconda/bin:$PATH pip install -r requirements.txt --use-mirrors
- PYTHONPATH= PATH=/home/travis/anaconda/bin:$PATH pip install patsy --use-mirrors
- PYTHONPATH= PATH=/home/travis/anaconda/bin:$PATH pip install msgpack_python --use-mirrors
- cp src/settings.py.example src/settings.py
- pip install pep8 --use-mirrors
script:
- PYTHONPATH= PATH=/home/travis/anaconda/bin:$PATH nosetests -v --nocapture
- PYTHONPATH= python setup.py test
- pep8 --exclude=migrations --ignore=E501,E251,E265 ./
notifications:
email: false
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
recursive-include src/skyline/webapp/static *
recursive-include src/skyline/webapp/templates *
14 changes: 11 additions & 3 deletions bin/analyzer.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.."
RETVAL=0

# Determine the script to run depending on whether this script is in the source
# tree or installed
SCRIPT="${BASEDIR}/bin/analyzer-agent"
if [ -e "${BASEDIR}/setup.py" ]
then
SCRIPT="${BASEDIR}/src/skyline/analyzer/agent.py"
fi

start () {
rm -f $BASEDIR/src/analyzer/*.pyc
/usr/bin/env python $BASEDIR/src/analyzer/analyzer-agent.py start
/usr/bin/env python $SCRIPT start
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo "started analyzer-agent"
Expand All @@ -20,7 +28,7 @@ start () {
stop () {
# TODO: write a real kill script
ps aux | grep 'analyzer-agent.py start' | grep -v grep | awk '{print $2 }' | xargs sudo kill -9
/usr/bin/env python $BASEDIR/src/analyzer/analyzer-agent.py stop
/usr/bin/env python $SCRIPT stop
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo "stopped analyzer-agent"
Expand All @@ -32,7 +40,7 @@ stop () {

run () {
echo "running analyzer"
/usr/bin/env python $BASEDIR/src/analyzer/analyzer-agent.py run
/usr/bin/env python $SCRIPT run
}

# See how we were called.
Expand Down
14 changes: 11 additions & 3 deletions bin/horizon.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.."
RETVAL=0

# Determine the script to run depending on whether this script is in the source
# tree or installed
SCRIPT="${BASEDIR}/bin/horizon-agent"
if [ -e "${BASEDIR}/setup.py" ]
then
SCRIPT="${BASEDIR}/src/skyline/horizon/agent.py"
fi

start () {
rm $BASEDIR/src/horizon/*.pyc
/usr/bin/env python $BASEDIR/src/horizon/horizon-agent.py start
/usr/bin/env python $SCRIPT start
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo "started horizon-agent"
Expand All @@ -20,7 +28,7 @@ start () {
stop () {
# TODO: write a real kill script
ps aux | grep 'horizon-agent.py start' | grep -v grep | awk '{print $2 }' | xargs sudo kill -9
/usr/bin/env python $BASEDIR/src/horizon/horizon-agent.py stop
/usr/bin/env python $SCRIPT stop
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo "stopped horizon-agent"
Expand All @@ -32,7 +40,7 @@ stop () {

run () {
echo "running horizon"
/usr/bin/env python $BASEDIR/src/horizon/horizon-agent.py run
/usr/bin/env python $SCRIPT run
}

# See how we were called.
Expand Down
16 changes: 12 additions & 4 deletions bin/webapp.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.."
RETVAL=0

# Determine the script to run depending on whether this script is in the source
# tree or installed
SCRIPT="${BASEDIR}/bin/skyline-webapp"
if [ -e "${BASEDIR}/setup.py" ]
then
SCRIPT="${BASEDIR}/src/skyline/webapp/webapp.py"
fi

start () {
rm -f $BASEDIR/src/webapp/*.pyc
/usr/bin/env python $BASEDIR/src/webapp/webapp.py start
/usr/bin/env python $SCRIPT start
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo "started webapp"
Expand All @@ -18,7 +26,7 @@ start () {
}

stop () {
/usr/bin/env python $BASEDIR/src/webapp/webapp.py stop
/usr/bin/env python $SCRIPT stop
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo "stopped webapp"
Expand All @@ -30,7 +38,7 @@ stop () {

restart () {
rm -f $BASEDIR/src/webapp/*.pyc
/usr/bin/env python $BASEDIR/src/webapp/webapp.py restart
/usr/bin/env python $SCRIPT restart
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo "restarted webapp"
Expand All @@ -42,7 +50,7 @@ restart () {

run () {
echo "running webapp"
/usr/bin/env python $BASEDIR/src/webapp/webapp.py run
/usr/bin/env python $SCRIPT run
}

# See how we were called.
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[nosetests]
tests = tests
49 changes: 49 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from setuptools import setup, find_packages

# work around a nose test bug: http://bugs.python.org/issue15881#msg170215
try:
import multiprocessing
except ImportError:
pass

setup(name='skyline',
version='0.1.0',
description='''
It'll detect your anomalies!
''',
author='etsy',
author_email='',
license='MIT',
url='https://github.com/etsy/skyline',
keywords=['anomaly detection', 'timeseries', 'monitoring'],
classifiers=['Programming Language :: Python'],

setup_requires=['nose>=1.0', 'unittest2', 'mock'],
install_requires=['redis==2.7.2',
'hiredis==0.1.1',
'python-daemon==1.6',
'flask==0.9',
'simplejson==2.0.9',
'numpy',
'scipy',
'pandas',
'patsy',
'statsmodels',
'msgpack_python'],

packages=find_packages('src'),
package_dir={'': 'src'},
include_package_data=True,

entry_points={
'console_scripts': [
'analyzer-agent = skyline.analyzer.agent:run',
'horizon-agent = skyline.horizon.agent:run',
'skyline-webapp = skyline.webapp.webapp:run'
]
},

scripts=['bin/analyzer.d', 'bin/horizon.d', 'bin/webapp.d'],

test_suite='nose.collector',
)
Empty file added src/skyline/__init__.py
Empty file.
Empty file.
20 changes: 11 additions & 9 deletions src/analyzer/analyzer-agent.py → src/skyline/analyzer/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
import sys
import traceback
from os import getpid
from os.path import dirname, abspath, isdir
from os.path import isdir
from daemon import runner
from time import sleep, time

# add the shared settings file to namespace
sys.path.insert(0, dirname(dirname(abspath(__file__))))
import settings
from skyline import settings
from skyline.analyzer.analyzer import Analyzer

from analyzer import Analyzer
logger = logging.getLogger("AnalyzerLog")


class AnalyzerAgent():
Expand All @@ -28,7 +27,8 @@ def run(self):
while 1:
sleep(100)

if __name__ == "__main__":

def run():
"""
Start the Analyzer agent.
"""
Expand All @@ -42,9 +42,9 @@ def run(self):

# Make sure we can run all the algorithms
try:
from algorithms import *
from skyline.analyzer import algorithms
timeseries = map(list, zip(map(float, range(int(time()) - 86400, int(time()) + 1)), [1] * 86401))
ensemble = [globals()[algorithm](timeseries) for algorithm in settings.ALGORITHMS]
ensemble = [getattr(algorithms, algorithm)(timeseries) for algorithm in settings.ALGORITHMS]
except KeyError as e:
print "Algorithm %s deprecated or not defined; check settings.ALGORITHMS" % e
sys.exit(1)
Expand All @@ -55,7 +55,6 @@ def run(self):

analyzer = AnalyzerAgent()

logger = logging.getLogger("AnalyzerLog")
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s :: %(process)s :: %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
handler = logging.FileHandler(settings.LOG_PATH + '/analyzer.log')
Expand All @@ -68,3 +67,6 @@ def run(self):
daemon_runner = runner.DaemonRunner(analyzer)
daemon_runner.daemon_context.files_preserve = [handler.stream]
daemon_runner.do_action()

if __name__ == "__main__":
run()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from email.MIMEImage import MIMEImage
from smtplib import SMTP
import alerters
import settings
from skyline import settings


"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from msgpack import unpackb, packb
from redis import StrictRedis

from settings import (
from skyline.settings import (
ALGORITHMS,
CONSENSUS,
FULL_DURATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import traceback
import operator
import socket
import settings
from skyline import settings

from alerters import trigger_alert
from algorithms import run_selected_algorithm
Expand Down
Empty file added src/skyline/horizon/__init__.py
Empty file.
12 changes: 7 additions & 5 deletions src/horizon/horizon-agent.py → src/skyline/horizon/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
from multiprocessing import Queue
from daemon import runner

# add the shared settings file to namespace
sys.path.insert(0, dirname(dirname(abspath(__file__))))
import settings
from skyline import settings

from listen import Listen
from roomba import Roomba
from worker import Worker

# TODO: http://stackoverflow.com/questions/6728236/exception-thrown-in-multiprocessing-pool-not-detected

logger = logging.getLogger("HorizonLog")

class Horizon():
def __init__(self):
Expand Down Expand Up @@ -60,7 +59,8 @@ def run(self):
while 1:
time.sleep(100)

if __name__ == "__main__":

def run():
"""
Start the Horizon agent.
"""
Expand All @@ -74,7 +74,6 @@ def run(self):

horizon = Horizon()

logger = logging.getLogger("HorizonLog")
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s :: %(process)s :: %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
handler = logging.FileHandler(settings.LOG_PATH + '/horizon.log')
Expand All @@ -87,3 +86,6 @@ def run(self):
daemon_runner = runner.DaemonRunner(horizon)
daemon_runner.daemon_context.files_preserve = [handler.stream]
daemon_runner.do_action()

if __name__ == "__main__":
run()
7 changes: 6 additions & 1 deletion src/horizon/listen.py → src/skyline/horizon/listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from msgpack import unpackb

import logging
import settings
from skyline import settings

logger = logging.getLogger("HorizonLog")

Expand All @@ -18,6 +18,11 @@
import pickle
USING_CPICKLE = False

try:
from cStringIO import StringIO
except:
from StringIO import StringIO

# This whole song & dance is due to pickle being insecure
# yet performance critical for carbon. We leave the insecure
# mode (which is faster) as an option (USE_INSECURE_UNPICKLER).
Expand Down
2 changes: 1 addition & 1 deletion src/horizon/roomba.py → src/skyline/horizon/roomba.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from time import time, sleep

import logging
import settings
from skyline import settings

logger = logging.getLogger("HorizonLog")

Expand Down
2 changes: 1 addition & 1 deletion src/horizon/worker.py → src/skyline/horizon/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import logging
import socket
import settings
from skyline import settings

logger = logging.getLogger("HorizonLog")

Expand Down
File renamed without changes.
Empty file added src/skyline/webapp/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var handle_data = function(data) {
// The callback to this function is handle_data()
var pull_data = function() {
$.ajax({
url: "/static/dump/anomalies.json",
url: "/anomalies.json",
dataType: 'jsonp'
});
}
Expand Down
Loading