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

Drop Python2 #1726

Open
wants to merge 7 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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
+step1:
sh>: echo this should fail
py>: bar
python: python3
36 changes: 10 additions & 26 deletions digdag-standards/src/main/resources/digdag/standards/py/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ def store(self, params={}, **kwds):

def add_subtask(self, function=None, **params):
if function is not None and not isinstance(function, dict):
if hasattr(function, "im_class"):
# Python 2
command = ".".join([function.im_class.__module__, function.im_class.__name__, function.__name__])
else:
# Python 3
command = ".".join([function.__module__, function.__qualname__])
command = ".".join([function.__module__, function.__qualname__])
config = params
config["py>"] = command
else:
Expand All @@ -66,7 +61,7 @@ def add_subtask(self, function=None, **params):
try:
json.dumps(config)
except Exception as error:
raise TypeError("Parameters must be serializable using JSON: %s" % str(error))
raise TypeError(f"Parameters must be serializable using JSON: {str(error)}")
self.subtask_config["+subtask" + str(self.subtask_index)] = config
self.subtask_index += 1

Expand All @@ -87,14 +82,14 @@ def digdag_inspect_command(command):
try:
callable_type = getattr(mod, method_name)
except AttributeError as error:
raise AttributeError("Module '%s' has no attribute '%s'" % (".".join(fragments), method_name))
raise AttributeError(f"Module '{'.'.join(fragments)}' has no attribute '{method_name}'")
except ImportError as error:
class_name = fragments.pop()
mod = __import__(".".join(fragments), fromlist=[class_name])
try:
class_type = getattr(mod, class_name)
except AttributeError as error:
raise AttributeError("Module '%s' has no attribute '%s'" % (".".join(fragments), method_name))
raise AttributeError(f"Module '{'.'.join(fragments)}' has no attribute '{method_name}'")

if type(callable_type) == type:
class_type = callable_type
Expand All @@ -109,12 +104,8 @@ def digdag_inspect_arguments(callable_type, exclude_self, params):
if callable_type == object.__init__:
# object.__init__ accepts *varargs and **keywords but it throws exception
return {}
if hasattr(inspect, 'getfullargspec'): # Python3
spec = inspect.getfullargspec(callable_type)
keywords_ = spec.varkw
else: # Python 2
spec = inspect.getargspec(callable_type)
keywords_ = spec.keywords
spec = inspect.getfullargspec(callable_type)
keywords_ = spec.varkw

args = {}
for idx, key in enumerate(spec.args):
Expand All @@ -125,15 +116,8 @@ def digdag_inspect_arguments(callable_type, exclude_self, params):
else:
if spec.defaults is None or idx < len(spec.args) - len(spec.defaults):
# this keyword is required but not in params. raising an error.
if hasattr(callable_type, '__qualname__'):
# Python 3
name = callable_type.__qualname__
elif hasattr(callable_type, 'im_class'):
# Python 2
name = "%s.%s" % (callable_type.im_class.__name__, callable_type.__name__)
else:
name = callable_type.__name__
raise TypeError("Method '%s' requires parameter '%s' but not set" % (name, key))
name = callable_type.__qualname__
raise TypeError(f"Method '{name}' requires parameter '{key}' but not set")
if keywords_:
# above code was only for validation
return params
Expand Down Expand Up @@ -162,9 +146,9 @@ def digdag_inspect_arguments(callable_type, exclude_self, params):
except SystemExit as e:
# SystemExit only shows an exit code and it is not kind to users. So this block creates a specific error message.
# This error will happen if called python module name and method name are equal to those of the standard library module. (e.g. tokenize.main)
error = Exception("Failed to call python command with code:%d" % e.code, "Possible cause: Invalid python module call, duplicate module name with standard library")
error = Exception(f"Failed to call python command with code:{str(e.code)}", "Possible cause: Ivalid python module call, duplicate module name with standard library")
error_type, error_value, _tb = sys.exc_info()
error_message = "%s %s" % (error.args[0], error.args[1])
error_message = " ".join(error.args[:2])
error_traceback = traceback.format_exception(error_type, error_value, _tb)
except Exception as e:
error = e
Expand Down
4 changes: 2 additions & 2 deletions digdag-tests/src/test/java/acceptance/PyIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public void verifyConfigurationPythonOption()
assertThat(attempt.getSuccess(), is(true));

final String logs = getAttemptLogs(client, attempt.getId());
assertThat(logs, containsString("python python"));
assertThat(logs, containsString("python [u'python', u'-v']"));
assertThat(logs, containsString("python python3"));
assertThat(logs, containsString("python ['python3', '-v']"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
+foo:
py>: scripts.echo_params.echo_params
python: python3
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import digdag

def echo_params():
Expand Down
1 change: 0 additions & 1 deletion digdag-tests/src/test/resources/acceptance/emr/pi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
+initialize:
+task:
py>: helper.store_v
python: python3
value: initial

+loop:
Expand All @@ -20,6 +21,7 @@
if>: true
_do:
py>: helper.store_v
python: python3
value: override_${outer}_${inner}

+dynamic_get_in_parallel:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
+stores:
+store:
py>: helper.store_v
python: python3
value: simple_store

+simple_store:
sh>: echo ${v} > simple_store.out

+overwrite:
py>: helper.store_v
python: python3
value: store_overwrite

+store_overwrite:
Expand All @@ -29,6 +31,7 @@
+parallel_store_fork:
+prepare:
py>: helper.store_v
python: python3
value: prepare

+fork:
Expand All @@ -37,6 +40,7 @@
+a:
+store:
py>: helper.store_v
python: python3
value: a

+dump:
Expand All @@ -45,6 +49,7 @@
+b:
+store:
py>: helper.store_v
python: python3
value: b

+dump:
Expand All @@ -62,15 +67,18 @@

+a:
py>: helper.store_v
python: python3
value: a

+b:
py>: helper.store_v
python: python3
value: b
_after: [+a]

+c:
py>: helper.store_v
python: python3
value: c

+dump:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

+python_string_option:
py>: scripts.echo_params.echo_params
python: "python"
python: "python3"

+python_array_option:
py>: scripts.echo_params.echo_params
python: ["python", "-v"]
python: ["python3", "-v"]
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
+task1:
py>: tokenize.main
python: python3
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
+stacktrace_python:
py>: scripts.stacktrace.run
python: python3

_error:
echo>: ERROR_MESSAGE_BEGIN ${error.message} ERROR_MESSAGE_END
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
+task1:
py>: scripts.syntax_error.func1
python: python3
1 change: 0 additions & 1 deletion examples/tasks/check_task.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import digdag

def generate():
Expand Down
1 change: 0 additions & 1 deletion examples/tasks/conditions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import re
import digdag

Expand Down
1 change: 0 additions & 1 deletion examples/tasks/error_task.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import digdag

def fails():
Expand Down
1 change: 0 additions & 1 deletion examples/tasks/export_params.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import digdag

def set_my_param():
Expand Down
1 change: 0 additions & 1 deletion examples/tasks/generate_subtasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import digdag

class ParallelProcess(object):
Expand Down
1 change: 0 additions & 1 deletion examples/tasks/params.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import digdag

def simple(data, number):
Expand Down
1 change: 0 additions & 1 deletion examples/tasks/python_args.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import digdag

def required_arguments(required1, required2):
Expand Down