Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce future and depracted options, and log.future #838

Merged
merged 11 commits into from Feb 7, 2014
1 change: 1 addition & 0 deletions easybuild/main.py
Expand Up @@ -157,6 +157,7 @@ def main(testing_data=(None, None, None)):
'debug': options.debug,
'dry_run': options.dry_run,
'easyblock': options.easyblock,
'experimental': options.experimental,
'force': options.force,
'ignore_dirs': options.ignore_dirs,
'only_blocks': options.only_blocks,
Expand Down
17 changes: 16 additions & 1 deletion easybuild/tools/build_log.py
Expand Up @@ -43,6 +43,12 @@
# EasyBuild message prefix
EB_MSG_PREFIX = "=="

# the version seen by log.deprecated
CURRENT_VERSION = VERSION

# allow some experimental experimental code
EXPERIMENTAL = False


class EasyBuildError(Exception):
"""
Expand Down Expand Up @@ -77,9 +83,18 @@ def caller_info(self):
break
return "(at %s:%s in %s)" % (os.path.join(*filepath_dirs), line, function_name)

def experimental(self, msg, *args, **kwargs):
"""Handle experimental functionality if EXPERIMENTAL is True, otherwise log error"""
if EXPERIMENTAL:
msg = 'Experimental functionality. Behaviour might change/be removed later. ' + msg
self.warning(msg, *args, **kwargs)
else:
msg = 'Experimental functionality. Behaviour might change/be removed later (use --experimental option to enable). ' + msg
self.error(msg, *args)

def deprecated(self, msg, max_ver):
"""Print deprecation warning or raise an EasyBuildError, depending on max version allowed."""
fancylogger.FancyLogger.deprecated(self, msg, str(VERSION), max_ver, exception=EasyBuildError)
fancylogger.FancyLogger.deprecated(self, msg, str(CURRENT_VERSION), max_ver, exception=EasyBuildError)

def error(self, msg, *args, **kwargs):
"""Print error message and raise an EasyBuildError."""
Expand Down
17 changes: 17 additions & 0 deletions easybuild/tools/options.py
Expand Up @@ -36,6 +36,11 @@
import os
import re
import sys

from distutils.version import LooseVersion

import easybuild.tools.build_log
import easybuild.tools.config
from easybuild.framework.easyblock import EasyBlock, get_class
from easybuild.framework.easyconfig.constants import constant_documentation
from easybuild.framework.easyconfig.default import convert_to_help
Expand Down Expand Up @@ -146,6 +151,12 @@ def override_options(self):
'pretend': (("Does the build/installation in a test directory located in $HOME/easybuildinstall"),
None, 'store_true', False, 'p'),
'skip-test-cases': ("Skip running test cases", None, 'store_true', False, 't'),
'deprecated': ("Run pretending to be (future) version, to test removal of deprecated code.",
None, 'store', None),
'experimental': ("Allow experimental code (with behaviour that can be changed or removed at any given time).",
None, 'store_true', False),
'oldstyleconfig': ("Look for and use the oldstyle configuration file.",
None, 'store_true', True),
})

self.log.debug("override_options: descr %s opts %s" % (descr, opts))
Expand Down Expand Up @@ -307,6 +318,12 @@ def validate(self):

def postprocess(self):
"""Do some postprocessing, in particular print stuff"""
easybuild.tools.build_log.EXPERIMENTAL = self.options.experimental
easybuild.tools.config.SUPPORT_OLDSTYLE = self.options.oldstyleconfig

if self.options.deprecated:
easybuild.tools.build_log.CURRENT_VERSION = LooseVersion(self.options.deprecated)

if self.options.unittest_file:
fancylogger.logToFile(self.options.unittest_file)

Expand Down
70 changes: 69 additions & 1 deletion test/framework/options.py
Expand Up @@ -37,6 +37,7 @@
from unittest import TestCase, TestLoader
from unittest import main as unittestmain

import easybuild.tools.build_log
import easybuild.tools.options as eboptions
from easybuild.main import main
from easybuild.framework.easyconfig import BUILD, CUSTOM, DEPENDENCIES, EXTENSIONS, FILEMANAGEMENT, LICENSE
Expand All @@ -46,6 +47,7 @@
from easybuild.tools.filetools import read_file, write_file
from easybuild.tools.modules import modules_tool
from easybuild.tools.options import EasyBuildOptions
from easybuild.tools.version import VERSION
from vsc import fancylogger

class CommandLineOptionsTest(TestCase):
Expand Down Expand Up @@ -679,7 +681,7 @@ def test_dry_run(self):
try:
main((args, dummylogfn, False))
except (SystemExit, Exception), err:
print "err: %s" % err
pass
outtxt = open(self.logfile, 'r').read()

info_msg = r"Dry run: printing build status of easyconfigs and dependencies"
Expand Down Expand Up @@ -851,6 +853,72 @@ def test_ignore_osdeps(self):
regex = re.compile("stop provided 'notavalidstop' is not valid", re.M)
self.assertTrue(regex.search(outtxt), "Validations are performed with --ignore-osdeps, outtxt: %s" % outtxt)

def test_experimental(self):
"""Test the experimental option"""
orig_value = easybuild.tools.build_log.EXPERIMENTAL
# make sure it's off by default
self.assertFalse(orig_value)

log = fancylogger.getLogger()

# force it to False
topt = EasyBuildOptions(
go_args=['--disable-experimental'],
)
try:
log.experimental('x')
# sanity check, should never be reached if it works.
self.assertTrue(False, "Experimental logging should be disabled by setting the --disable-experimental option")
except easybuild.tools.build_log.EasyBuildError, err:
# check error message
self.assertTrue('Experimental functionality.' in str(err))

# toggle experimental
topt = EasyBuildOptions(
go_args=['--experimental'],
)
try:
log.experimental('x')
except:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except easybuild.tools.build_log.EasyBuildError, err:?

self.assertTrue(False, 'Experimental logging should be allowed by the --experimental option.')

# set it back
easybuild.tools.build_log.EXPERIMENTAL = orig_value

def test_deprecated(self):
"""Test the deprecated option"""
orig_value = easybuild.tools.build_log.CURRENT_VERSION

# make sure it's off by default
self.assertEqual(orig_value, VERSION)

log = fancylogger.getLogger()

# force it to current version
topt = EasyBuildOptions(
go_args=['--deprecated=%s' % orig_value],
)

try:
log.deprecated('x', str(orig_value))
except easybuild.tools.build_log.EasyBuildError, err:
self.assertTrue(False, 'Deprecated logging should work')

# force higher version by prefixing it with 1
topt = EasyBuildOptions(
go_args=['--deprecated=1%s' % orig_value],
)
try:
log.deprecated('x', str(orig_value))
# not supposed to get here
self.assertTrue(False, 'Deprecated logging should throw EasyBuildError')
except easybuild.tools.build_log.EasyBuildError, err2:
self.assertTrue('DEPRECATED' in str(err2))

# set it back
easybuild.tools.build_log.CURRENT_VERSION = orig_value


def suite():
""" returns all the testcases in this module """
return TestLoader().loadTestsFromTestCase(CommandLineOptionsTest)
Expand Down