From b70090c61ecc2478a78c869f1ffd7d0f884920fb Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Tue, 5 Apr 2011 14:50:30 +0000
Subject: [PATCH] Sort of working version with setuptools.

Locations and python paths are correct with respect to the setup.py file.
For development, use
  svn up && python setup.py develop
and for deployment use
  svn up && sudo python setup.py install



git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/branches/refactor-mutalyzer-branch@250 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
---
 AUTHORS                        |  1 +
 README                         |  1 +
 bin/find_log_bugs              |  9 ---------
 bin/mutalyzer-batchd           |  3 ---
 extras/config.example          |  2 +-
 extras/init.d/mutalyzer-batchd |  4 ++--
 mutalyzer/webservice.py        | 21 ++++++++++-----------
 mutalyzer/wsgi.py              | 17 +++++------------
 setup.py                       |  4 ++--
 tests/test_grammar.py          | 14 ++++++--------
 tests/test_mutalyzer.py        | 14 ++++++--------
 tests/test_mutator.py          | 16 +++++++---------
 tests/test_wsgi.py             | 15 ++++++---------
 13 files changed, 47 insertions(+), 74 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index e6a98623..7236e893 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,3 +1,4 @@
+Leiden University Medical Center department of Human Genetics <humgen@lumc.nl>
 Jeroen Laros <j.f.j.laros@lumc.nl>
 Gerben Stouten
 Gerard Schaafsma <g.c.p.schaafsma@lumc.nl>
diff --git a/README b/README
index a64f8f51..72193b94 100644
--- a/README
+++ b/README
@@ -56,6 +56,7 @@ Todo:
 * Develop a large test suite.
 * Create a web interface url to watch the progress of a batch job.
 * Use virtualenv?
+* Perhaps the WSGI file should be somewhere else and be called mutalyzer.wsgi?
 
 
 Notes for server setup (Europium VM copy):
diff --git a/bin/find_log_bugs b/bin/find_log_bugs
index 253be3d7..cea38c2e 100755
--- a/bin/find_log_bugs
+++ b/bin/find_log_bugs
@@ -10,15 +10,6 @@ crashed.
 
 
 import os
-import site
-
-# Todo: Get this from the configuration file
-root_dir = os.path.split(os.path.dirname(__file__))[0]
-site.addsitedir(root_dir)
-# Todo: Fix Mutalyzer to not depend on working directory
-if not __name__ == '__main__':
-        os.chdir(root_dir)
-
 from mutalyzer.config import Config
 
 
diff --git a/bin/mutalyzer-batchd b/bin/mutalyzer-batchd
index 3df71c5b..c7bd0175 100755
--- a/bin/mutalyzer-batchd
+++ b/bin/mutalyzer-batchd
@@ -19,11 +19,8 @@ from daemon import pidlockfile, DaemonContext
 from lockfile import LockTimeout
 import signal
 import time
-import site
 import traceback
 
-site.addsitedir(os.getcwd())
-
 from mutalyzer.config import Config
 from mutalyzer.Db import Batch
 from mutalyzer.Scheduler import Scheduler
diff --git a/extras/config.example b/extras/config.example
index b1d1bc40..89c500b0 100644
--- a/extras/config.example
+++ b/extras/config.example
@@ -110,7 +110,7 @@ mailSubject = "Result of Mutalyzer batch check."
 resultsDir = "/var/cache/mutalyzer"
 
 # Location of the PID file.
-PIDfile = "/var/run/mutalyzer/batchd.pid"
+PIDfile = "/var/run/mutalyzer/mutalyzer-batchd.pid"
 
 # Maximum size for uploaded batch input files in megabytes.
 batchInputMaxSize = 5
diff --git a/extras/init.d/mutalyzer-batchd b/extras/init.d/mutalyzer-batchd
index cc1f0e2b..9c559f24 100755
--- a/extras/init.d/mutalyzer-batchd
+++ b/extras/init.d/mutalyzer-batchd
@@ -16,10 +16,10 @@
 # PATH should only include /usr/* if it runs after the mountnfs.sh script
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 DESC="Mutalyzer batch deamon"
-DAEMON=/home/martijn/projects/mutalyzer/svn/branches/refactor-mutalyzer-branch/bin/batch_daemon
+DAEMON=/home/martijn/projects/mutalyzer/svn/branches/refactor-mutalyzer-branch/bin/mutalyzer-batchd
 DIR=/home/martijn/projects/mutalyzer/svn/branches/refactor-mutalyzer-branch
 NAME=mutalyzer-batchd
-PIDFILE=/var/run/mutalyzer/batchd.pid
+PIDFILE=/var/run/mutalyzer/mutalyzer-batchd.pid
 PIDDIR=/var/run/mutalyzer
 SCRIPTNAME=/etc/init.d/mutalyzer-batchd
 USER=www-data
diff --git a/mutalyzer/webservice.py b/mutalyzer/webservice.py
index 6348138b..2562fa41 100644
--- a/mutalyzer/webservice.py
+++ b/mutalyzer/webservice.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
 """
 Mutalyzer webservices.
 
@@ -24,6 +22,7 @@ Be sure to have this line first if you also define a / alias, like this:
        and we should not create it on every request.
 """
 
+
 # WSGI applications should never print anything to stdout. We redirect to
 # stderr, but eventually Mutalyzer should be fixed to never just 'print'
 # anything.
@@ -47,16 +46,8 @@ from soaplib.core.model.clazz import Array
 from soaplib.core.model.exception import Fault
 from soaplib.core.server import wsgi
 import os
-import site
 from operator import itemgetter, attrgetter
 
-# Todo: Get this from the configuration file
-root_dir = os.path.split(os.path.dirname(__file__))[0]
-site.addsitedir(root_dir)
-# Todo: Fix Mutalyzer to not depend on working directory
-if not __name__ == '__main__':
-    os.chdir(root_dir)
-
 from mutalyzer.config import Config
 from mutalyzer.grammar import Grammar
 from mutalyzer import variantchecker
@@ -892,15 +883,23 @@ class MutalyzerService(DefinitionBase) :
     #sliceChromosome
 #MutalyzerService
 
+
 # WSGI application for use with e.g. Apache/mod_wsgi
 soap_application = Application([MutalyzerService],
                                'http://mutalyzer.nl/2.0/services', # namespace
                                'Mutalyzer')
 application = wsgi.Application(soap_application)
 
+
+# Todo: Fix Mutalyzer to not depend on working directory
+if not __name__ == '__main__':
+    os.chdir(os.path.dirname(__file__))
+
+
 # We can also use the built-in webserver by executing this file directly
 if __name__ == '__main__':
-    # Todo: Setting the working directory probably doesn't work
+    # Todo: add a main() function or something, and create an executable
+    # wrapper in bin/.
     from wsgiref.simple_server import make_server
     print 'Listening to http://localhost:8081/'
     print 'WDSL file is at http://localhost:8081/?wsdl'
diff --git a/mutalyzer/wsgi.py b/mutalyzer/wsgi.py
index 1a937b3e..311dd6e7 100644
--- a/mutalyzer/wsgi.py
+++ b/mutalyzer/wsgi.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
 """
 General WSGI interface.
 
@@ -57,20 +55,12 @@ import os
 import bz2
 import web
 import urllib
-import site
 
 from lxml import etree
 from cStringIO import StringIO
 from simpletal import simpleTALES
 from simpletal import simpleTAL
 
-# Todo: Get this from the configuration file
-root_dir = os.path.split(os.path.dirname(__file__))[0]
-site.addsitedir(root_dir)
-# Todo: Fix Mutalyzer to not depend on working directory
-if not __name__ == '__main__':
-    os.chdir(root_dir)
-
 import mutalyzer
 from mutalyzer import util
 from mutalyzer.config import Config
@@ -203,7 +193,7 @@ class render_tal:
 
 
 # TAL template render
-render = render_tal(os.path.join(root_dir, 'templates'), globals={
+render = render_tal('templates', globals={
     'version': mutalyzer.__version__,
     'nomenclatureVersion': mutalyzer.NOMENCLATURE_VERSION,
     'releaseDate': mutalyzer.__date__,
@@ -1109,10 +1099,13 @@ class Static:
 
 
 if __name__ == '__main__':
-    # Todo: Setting the working directory probably doesn't work
+    # Todo: add a main() function or something, and create an executable
+    # wrapper in bin/.
     # Usage:
     #   ./src/wsgi.py [port]
     app.run()
 else:
     # WSGI application
+    # Todo: Fix Mutalyzer to not depend on working directory
+    os.chdir(os.path.dirname(__file__))
     application = app.wsgifunc()
diff --git a/setup.py b/setup.py
index ccefce08..4dcd083b 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@ setup(
     author_email=distmeta.__contact__,
     url=distmeta.__homepage__,
     license='Not distributable',
-    platform=['any'],
+    platforms=['any'],
     packages=find_packages(exclude=['doc', 'extras', 'tests']),
     include_package_data=True,
     scripts=['bin/mutalyzer-batchd'],
@@ -24,7 +24,7 @@ setup(
 # Things not handled by this setup.py:
 # - Copy extras/config.example to /etc/mutalyzer/config
 # - Database setup
-# - Chown /var/log/mutalyzer.log
+# - Chown /var/log/mutalyzer.log and /var/cache/mutalyzer
 # - Copy extras/init.d/mutalyzer-batchd to /etc/init.d/mutalyzer-batchd
 # - Copy doc to /usr/share/doc
 # Perhaps as a postinstall script?
diff --git a/tests/test_grammar.py b/tests/test_grammar.py
index e0292170..85ab8276 100644
--- a/tests/test_grammar.py
+++ b/tests/test_grammar.py
@@ -2,23 +2,21 @@
 Tests for the mutalyzer.grammar module.
 """
 
+
 #import logging; logging.basicConfig()
 import os
-import site
 from nose.tools import *
 
-# Todo: Get this from the configuration file
-root_dir = os.path.split(os.path.dirname(__file__))[0]
-site.addsitedir(root_dir)
-# Todo: Fix Mutalyzer to not depend on working directory
-if not __name__ == '__main__':
-    os.chdir(root_dir)
-
 from mutalyzer.config import Config
 from mutalyzer.grammar import Grammar
 from mutalyzer.output import Output
 
 
+# Todo: Fix Mutalyzer to not depend on working directory
+root_dir = os.path.split(os.path.dirname(__file__))[0]
+os.chdir(os.path.join(root_dir, 'mutalyzer'))
+
+
 class TestGrammar():
     """
     Test the mytalyzer.grammar module.
diff --git a/tests/test_mutalyzer.py b/tests/test_mutalyzer.py
index fee26626..5304bb17 100644
--- a/tests/test_mutalyzer.py
+++ b/tests/test_mutalyzer.py
@@ -2,26 +2,24 @@
 Tests for the Mutalyzer module.
 """
 
+
 #import logging; logging.basicConfig()
 import re
 import os
 import random
-import site
 from nose.tools import *
 from Bio.Seq import Seq
 
-# Todo: Get this from the configuration file
-root_dir = os.path.split(os.path.dirname(__file__))[0]
-site.addsitedir(root_dir)
-# Todo: Fix Mutalyzer to not depend on working directory
-if not __name__ == '__main__':
-    os.chdir(root_dir)
-
 from mutalyzer.config import Config
 from mutalyzer.output import Output
 from mutalyzer.variantchecker import check_variant
 
 
+# Todo: Fix Mutalyzer to not depend on working directory
+root_dir = os.path.split(os.path.dirname(__file__))[0]
+os.chdir(os.path.join(root_dir, 'mutalyzer'))
+
+
 class TestMutalyzer():
     """
     Test the Mutalyzer module.
diff --git a/tests/test_mutator.py b/tests/test_mutator.py
index dc9a3449..766270d4 100644
--- a/tests/test_mutator.py
+++ b/tests/test_mutator.py
@@ -2,26 +2,24 @@
 Tests for the mutalyzer.mutator module.
 """
 
+
 #import logging; logging.basicConfig()
 import re
 import os
 import random
-import site
 from nose.tools import *
 from Bio.Seq import Seq
 
-# Todo: Get this from the configuration file
-root_dir = os.path.split(os.path.dirname(__file__))[0]
-site.addsitedir(root_dir)
-# Todo: Fix Mutalyzer to not depend on working directory
-if not __name__ == '__main__':
-    os.chdir(root_dir)
-        
 from mutalyzer.config import Config
 from mutalyzer.output import Output
 from mutalyzer import mutator
 
 
+# Todo: Fix Mutalyzer to not depend on working directory
+root_dir = os.path.split(os.path.dirname(__file__))[0]
+os.chdir(os.path.join(root_dir, 'mutalyzer'))
+
+
 def _seq(length):
     """
     Return random DNA sequence of given length.
@@ -180,7 +178,7 @@ class TestMutator():
         sites = [4, 9, 14, 17, 25, 27]
         m = self._mutator(_seq(l))
         m.delM(17, 17)   # g.17del
-        assert_equal(m.newSplice(sites), [4, 9, 14, 16, 24, 26])
+        assert_equal(m.newSplice(sites), [4, 9, 14, 16, 24, 27])
 
     def test_newSplice_don_del_after(self):
         """
diff --git a/tests/test_wsgi.py b/tests/test_wsgi.py
index b57d2547..fc8d4964 100644
--- a/tests/test_wsgi.py
+++ b/tests/test_wsgi.py
@@ -13,22 +13,19 @@ I just installed webtest by 'easy_install webtest'.
 
 #import logging; logging.basicConfig()
 import os
-import site
 import re
 import time
 from nose.tools import *
 from webtest import TestApp
 
-# Todo: Get this from the configuration file
-root_dir = os.path.split(os.path.dirname(__file__))[0]
-site.addsitedir(root_dir)
-# Todo: Fix Mutalyzer to not depend on working directory
-if not __name__ == '__main__':
-    os.chdir(root_dir)
-
 from mutalyzer.wsgi import application
 
 
+# Todo: Fix Mutalyzer to not depend on working directory
+root_dir = os.path.split(os.path.dirname(__file__))[0]
+os.chdir(os.path.join(root_dir, 'mutalyzer'))
+
+
 class TestWSGI():
     """
     Test the Mutalyzer WSGI interface.
@@ -510,7 +507,7 @@ facilisi."""
 
         @todo: Test if returned genomic reference can indeed be used now.
         """
-        test_genbank_file = 'tests/data/AB026906.1.gb'
+        test_genbank_file = '../tests/data/AB026906.1.gb'
         r = self.app.get('/upload')
         form = r.forms[0]
         form['invoermethode'] = 'file'
-- 
GitLab