-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
datatype()s can declare default values #6374
Changes from all commits
9acfaf9
7c64671
aa00315
2c94bcb
c622065
62153d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from pants.engine.fs import DirectoryDigest | ||
from pants.engine.rules import RootRule, rule | ||
from pants.engine.selectors import Select | ||
from pants.util.objects import DatatypeFieldDecl as F | ||
from pants.util.objects import Exactly, TypeCheckError, datatype | ||
|
||
|
||
|
@@ -23,28 +24,25 @@ class ExecuteProcessRequest(datatype([ | |
('argv', tuple), | ||
('input_files', DirectoryDigest), | ||
('description', text_type), | ||
('env', tuple), | ||
('output_files', tuple), | ||
('output_directories', tuple), | ||
# TODO: allow inferring a default value if a type is provided which has a 0-arg constructor. | ||
F('env', Exactly(tuple, dict, type(None)), default_value=None), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds like a correct analysis and I will do that. |
||
F('output_files', tuple, default_value=()), | ||
F('output_directories', tuple, default_value=()), | ||
# NB: timeout_seconds covers the whole remote operation including queuing and setup. | ||
('timeout_seconds', Exactly(float, int)), | ||
('jdk_home', Exactly(text_type, type(None))), | ||
F('timeout_seconds', Exactly(float, int), default_value=_default_timeout_seconds), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inline |
||
F('jdk_home', Exactly(text_type, type(None)), default_value=None), | ||
])): | ||
"""Request for execution with args and snapshots to extract.""" | ||
|
||
def __new__( | ||
cls, | ||
argv, | ||
input_files, | ||
description, | ||
env=None, | ||
output_files=(), | ||
output_directories=(), | ||
timeout_seconds=_default_timeout_seconds, | ||
jdk_home=None, | ||
): | ||
def __new__(cls, *args, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this this implementation to be more work for me to read, rather than less... Before it massaged param, and then constructed an object as I'd expect; now it has multiple layers of validation, and the provision on the type definition for an intermediate state which would be invalid outside the constructor (having a dict as a field value)... Maybe the answer here is to fall back to the automatically implemented |
||
this_object = super(ExecuteProcessRequest, cls).__new__(cls, *args, **kwargs) | ||
|
||
env = this_object.env | ||
# `env` is a tuple, a dict, or None. | ||
if env is None: | ||
env = () | ||
elif isinstance(env, tuple): | ||
pass | ||
else: | ||
if not isinstance(env, dict): | ||
raise TypeCheckError( | ||
|
@@ -56,17 +54,7 @@ def __new__( | |
) | ||
env = tuple(item for pair in env.items() for item in pair) | ||
|
||
return super(ExecuteProcessRequest, cls).__new__( | ||
cls, | ||
argv=argv, | ||
env=env, | ||
input_files=input_files, | ||
description=description, | ||
output_files=output_files, | ||
output_directories=output_directories, | ||
timeout_seconds=timeout_seconds, | ||
jdk_home=jdk_home, | ||
) | ||
return this_object.copy(env=env) | ||
|
||
|
||
class ExecuteProcessResult(datatype([('stdout', binary_type), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be happy to just remove this TODO; inferring defaults is scary...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussion on slack, agreed and will do.