Fix namespace declaration

melange/__init__.py may not exist depending on order of installation.

Change-Id: I875152afbd691e221414ef700371317730237506
This commit is contained in:
Jason Kölker 2012-02-09 11:27:02 -06:00
parent b4707d28ea
commit 05612066e9
14 changed files with 70 additions and 58 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ tags
*~
ChangeLog
melange/vcsversion.py
requirements.txt

View File

@ -26,11 +26,17 @@ This script can be run as a cron job on the melange server.
"""
import logging
#TODO(jkoelker) Convert this to an entry_point
import gettext
import optparse
import os
import sys
gettext.install('melange', unicode=1)
# If ../melange/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),

View File

@ -16,11 +16,16 @@
# License for the specific language governing permissions and limitations
# under the License.
#TODO(jkoelker) Convert this to an entry_point
import gettext
import optparse
import os
import re
import sys
import time
gettext.install('melange', unicode=1)
# If ../melange/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
@ -32,7 +37,6 @@ if os.path.exists(os.path.join(possible_topdir, 'melange', '__init__.py')):
from melange import version
from melange.common import config
from melange.common import wsgi
from melange.common import utils
from melange.db import db_api

View File

@ -16,11 +16,16 @@
# License for the specific language governing permissions and limitations
# under the License.
#TODO(jkoelker) Convert this to an entry_point
import gettext
import optparse
import os
import re
import sys
import time
gettext.install('melange', unicode=1)
# If ../melange/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...

View File

@ -14,25 +14,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import gettext
import pkgutil
import os
__path__ = pkgutil.extend_path(__path__, __name__)
gettext.install('melange', unicode=1)
def melange_root_path():
return os.path.dirname(__file__)
def melange_bin_path(filename="."):
return os.path.join(melange_root_path(), "..", "bin", filename)
def melange_etc_path(filename="."):
return os.path.join(melange_root_path(), "..", "etc", "melange", filename)
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

View File

@ -14,3 +14,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import gettext
gettext.install('melange', unicode=1)

View File

@ -15,14 +15,37 @@
# License for the specific language governing permissions and limitations
# under the License.
import mox
# See http://code.google.com/p/python-nose/issues/detail?id=373
# The code below enables nosetests to work with i18n _() blocks
import __builtin__
setattr(__builtin__, '_', lambda x: x)
import os
import unittest
import urlparse
import mox
from melange.db import db_api
from melange.common import utils
def melange_root_path():
return os.path.join(os.path.dirname(__file__), "..", "..")
def melange_bin_path(filename="."):
return os.path.join(melange_root_path(), "bin", filename)
def melange_etc_path(filename="."):
return os.path.join(melange_root_path(), "etc", "melange", filename)
def test_config_file():
return melange_etc_path("melange.conf.sample")
class BaseTest(unittest.TestCase):
def setUp(self):

View File

@ -18,17 +18,13 @@
import os
import subprocess
import melange
from melange import tests
from melange.common import config
from melange.db import db_api
def test_config_file():
return melange.melange_etc_path("melange.conf.sample")
def setup():
options = dict(config_file=test_config_file())
options = dict(config_file=tests.test_config_file())
_db_sync(options)
_configure_db(options)
@ -60,7 +56,7 @@ def execute(cmd, raise_error=True):
# Make sure that we use the programs in the
# current source directory's bin/ directory.
env['PATH'] = melange.melange_bin_path() + ':' + env['PATH']
env['PATH'] = tests.melange_bin_path() + ':' + env['PATH']
process = subprocess.Popen(cmd,
shell=True,
stdin=subprocess.PIPE,

View File

@ -26,8 +26,8 @@ from melange.tests import functional
def run_melange_manage(command):
melange_manage = melange.melange_bin_path('melange-manage')
config_file = functional.test_config_file()
melange_manage = tests.melange_bin_path('melange-manage')
config_file = tests.test_config_file()
return functional.execute("%(melange_manage)s %(command)s "
"--config-file=%(config_file)s" % locals())
@ -56,8 +56,8 @@ class TestDeleteDeallocatedIps(tests.BaseTest):
days = config.Config.get('keep_deallocated_ips_for_days')
self._push_back_deallocated_date(ip, days)
script = melange.melange_bin_path('melange-delete-deallocated-ips')
config_file = functional.test_config_file()
script = tests.melange_bin_path('melange-delete-deallocated-ips')
config_file = tests.test_config_file()
functional.execute("{0} --config-file={1}".format(script, config_file))
self.assertIsNone(models.IpAddress.get(ip.id))

View File

@ -15,25 +15,16 @@
# License for the specific language governing permissions and limitations
# under the License.
# See http://code.google.com/p/python-nose/issues/detail?id=373
# The code below enables nosetests to work with i18n _() blocks
import __builtin__
setattr(__builtin__, '_', lambda x: x)
import json
import webtest
import melange
from melange import tests
from melange.common import config
from melange.common import utils
from melange.common import wsgi
from melange.db import db_api
def test_config_path():
return melange.melange_etc_path("melange.conf.sample")
def sanitize(data):
serializer = wsgi.JSONDictSerializer()
return json.loads(serializer.serialize(data))
@ -79,7 +70,7 @@ class TestApp(webtest.TestApp):
def setup():
options = {"config_file": test_config_path()}
options = {"config_file": tests.test_config_file()}
conf = config.Config.load_paste_config("melangeapp", options, None)
db_api.drop_db(conf)

View File

@ -19,15 +19,15 @@ import routes
import unittest
import webtest
from melange import tests
from melange.common import config
from melange.common import wsgi
from melange.tests import unit
class TestExtensions(unittest.TestCase):
def test_extension_loads_with_melange_xmlns(self):
options = {'config_file': unit.test_config_path()}
options = {'config_file': tests.test_config_file()}
conf, app = config.Config.load_paste_app('melangeapi',
options, None)
test_app = webtest.TestApp(app)

View File

@ -17,7 +17,6 @@
import string
import unittest
import mox
import netaddr
import routes
import webob.exc
@ -41,7 +40,7 @@ class ControllerTestBase(tests.BaseTest):
def setUp(self):
super(ControllerTestBase, self).setUp()
conf, melange_app = config.Config.load_paste_app('melangeapp',
{"config_file": unit.test_config_path()}, None)
{"config_file": tests.test_config_file()}, None)
self.app = unit.TestApp(melange_app)

View File

@ -19,14 +19,13 @@ import webtest
from melange.common import config
from melange import tests
from melange.tests import unit
class TestVersionsController(tests.BaseTest):
def setUp(self):
conf, melange_app = config.Config.load_paste_app('melange',
{"config_file": unit.test_config_path()}, None)
{"config_file": tests.test_config_file()}, None)
self.test_app = webtest.TestApp(melange_app)
super(TestVersionsController, self).setUp()

View File

@ -96,4 +96,6 @@ setup(name='melange',
'bin/melange-manage',
'bin/melange-delete-deallocated-ips',
],
py_modules=[])
py_modules=[],
namespace_packages=['melange'],
)