Skip to content

Commit

Permalink
removed deprecated behavior from JarStep constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
David Marin committed Jun 25, 2015
1 parent 3b745dd commit 185fe36
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 63 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -2,6 +2,7 @@ v0.5.0, 2015-??-?? -- ???
* jobs:
* mr() no longer takes positional arguments (#814)
* removed jar() (use mrjob.step.JarStep)
* JarStep() only takes "args" and "main_class" keyword args
* removed testing methods parse_counters() and parse_output()
* runners:
* All runners:
Expand Down
44 changes: 15 additions & 29 deletions mrjob/step.py
Expand Up @@ -32,9 +32,12 @@

# params to specify how to run the step. need at least one of these
_JOB_STEP_FUNC_PARAMS = _MAPPER_FUNCS + _COMBINER_FUNCS + _REDUCER_FUNCS
# all allowable step params
# all allowable MRStep params
_JOB_STEP_PARAMS = _JOB_STEP_FUNC_PARAMS + _HADOOP_OPTS

# all allowable JarStep constructor keyword args
_JAR_STEP_KWARGS = ['args', 'main_class']


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -91,8 +94,8 @@ def __init__(self, **kwargs):
# limit which keyword args can be specified
bad_kwargs = sorted(set(kwargs) - set(_JOB_STEP_PARAMS))
if bad_kwargs:
raise TypeError(
'mr() got an unexpected keyword argument %r' % bad_kwargs[0])
raise TypeError('MRStep() got an unexpected keyword argument %r' %
bad_kwargs[0])

if not set(kwargs) & set(_JOB_STEP_FUNC_PARAMS):
raise ValueError("Step has no mappers and no reducers")
Expand Down Expand Up @@ -253,8 +256,7 @@ class JarStep(object):
#: with the step's output path
OUTPUT = '<output>'

# in v0.5.0, replace "*args" with "jar"
def __init__(self, *args, **kwargs):
def __init__(self, jar, **kwargs):
"""Define a Java JAR step.
Accepts the following keyword arguments:
Expand All @@ -267,35 +269,19 @@ def __init__(self, *args, **kwargs):
in the jar's manifest file.
:param args: (optional) A list of arguments to the jar
*jar* can also be passed as a positional argument
See :ref:`non-hadoop-streaming-jar-steps` for sample usage.
"""
if args:
self._init_deprecated(*args, **kwargs)
else:
self._init_kwargs(**kwargs)

def _init_deprecated(
self, name, jar, main_class=None, step_args=None, args=None):
log.warning('Positional arguments to JarStep() (other than'
' jar) are deprecated and will be removed in v0.5.0')
bad_kwargs = sorted(set(kwargs) - set(_JAR_STEP_KWARGS))
if bad_kwargs:
raise TypeError('JarStep() got an unexpected keyword argument %r' %
bad_kwargs[0])

self.jar = jar
self.main_class = main_class
self.args = args or step_args or []

def _init_kwargs(
self, jar, main_class=None, args=None, step_args=None, name=None):
# deprecated arguments
if step_args:
log.warning('step_args argument to JarStep() has been'
' renamed to args, and will be removed in v0.5.0')
if name:
log.warning('name argument to JarStep() has no effect, and will'
' be removed in v0.5.0')

self.jar = jar
self.main_class = main_class
self.args = args or step_args or []
self.args = kwargs.get('args') or []
self.main_class = kwargs.get('main_class')

def __repr__(self):
repr_args = []
Expand Down
34 changes: 0 additions & 34 deletions tests/test_step.py
Expand Up @@ -60,40 +60,6 @@ def test_some(self):
self.assertEqual(JarStep(**kwargs).description(0), expected)


class JarStepDeprecatedArgumentsTestCase(TestCase):

def test_positional(self):
with logger_disabled('mrjob.step'):
self.assertEqual(
JarStep('foo', 'bell.jar', 'First', ['one', '2']),
JarStep(jar='bell.jar', main_class='First', args=['one', '2'])
)

def test_mixed(self):
with logger_disabled('mrjob.step'):
self.assertEqual(
JarStep('foo', jar='bell.jar', args=['3', 'four']),
JarStep(jar='bell.jar', args=['3', 'four'])
)

def test_step_args_kwarg(self):
with logger_disabled('mrjob.step'):
self.assertEqual(
JarStep(jar='bell.jar', step_args=['5', 'six']),
JarStep(jar='bell.jar', args=['5', 'six'])
)

def test_name_kwarg(self):
with logger_disabled('mrjob.step'):
self.assertEqual(
JarStep(jar='pickle.jar', name='Bubbies'),
JarStep(jar='pickle.jar')
)

def test_bad_kwarg(self):
self.assertRaises(TypeError, JarStep, foo='bar')


class MRStepInitTestCase(TestCase):

### Basic behavior ###
Expand Down

0 comments on commit 185fe36

Please sign in to comment.