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

CDRIVER-4637: No AUTO features #1269

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
97 changes: 50 additions & 47 deletions .evergreen/generated_configs/legacy-config.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,42 @@

import sys
from collections import OrderedDict as OD
from typing import Any, Iterable, Mapping, MutableMapping, MutableSequence, Sequence, Union

Scalar = Union[str, bool, int, None, float]
"YAML simple schema scalar types"
ValueSequence = Sequence["Value"]
"Sequence of YAML simple values"
MutableValueArray = MutableSequence["Value"]
"A mutable sequence of JSON values"
ValueMapping = Mapping[Scalar, "Value"]
"A YAML mapping type (arbitrary scalars as keys)"
MutableValueMapping = MutableMapping[Scalar, "Value"]
"A mutable YAML mapping type"
Value = Union[ValueSequence, ValueMapping, Scalar]
"Any YAML simple value"
MutableValue = Union[MutableValueMapping, MutableValueArray, Scalar]
"Any YAML simple value, which may be a mutable sequence or map"

ValueOrderedDict = OD[Scalar, Value]
"An OrderedDict of YAML values"


try:
import yaml
import yamlordereddictloader
import yamlordereddictloader # type: ignore
except ImportError:
sys.stderr.write(
"try 'pip install -r evergreen_config_generator/requirements.txt'\n")
sys.stderr.write("try 'pip install -r evergreen_config_generator/requirements.txt'\n")
raise


class ConfigObject(object):
def __init__(self, *args, **kwargs):
super(ConfigObject, self).__init__()

@property
def name(self):
return 'UNSET'
def name(self) -> str:
return "UNSET"

def to_dict(self):
return OD([('name', self.name)])
def to_dict(self) -> Value:
return OD([("name", self.name)])


# We want legible YAML tasks:
Expand All @@ -51,36 +67,38 @@ def to_dict(self):
# Write values compactly except multiline strings, which use "|" style. Write
# tag sets as lists.


class _Dumper(yamlordereddictloader.Dumper):
def __init__(self, *args, **kwargs):
super(_Dumper, self).__init__(*args, **kwargs)
def __init__(self, *args: Value, **kwargs: Value):
super().__init__(*args, **kwargs) # type: ignore
self.add_representer(set, type(self).represent_set)
# Use "multi_representer" to represent all subclasses of ConfigObject.
self.add_multi_representer(ConfigObject,
type(self).represent_config_object)
self.add_multi_representer(ConfigObject, type(self).represent_config_object)

def represent_scalar(self, tag, value, style=None):
if isinstance(value, (str)) and '\n' in value:
style = '|'
return super(_Dumper, self).represent_scalar(tag, value, style)
def represent_scalar(self, tag: str, value: Value, style: str | None = None) -> yaml.ScalarNode:
if isinstance(value, (str)) and "\n" in value:
style = "|"
return super().represent_scalar(tag, value, style) # type: ignore

def represent_set(self, data):
return super(_Dumper, self).represent_list(sorted(data))
def represent_set(self, data: Iterable[Value]) -> yaml.MappingNode:
return super().represent_list(sorted(set(data))) # type: ignore

def represent_config_object(self, obj):
return super(_Dumper, self).represent_data(obj.to_dict())
def represent_config_object(self, obj: ConfigObject) -> yaml.Node:
d = obj.to_dict()
return super().represent_data(d) # type: ignore


def yaml_dump(obj):
def yaml_dump(obj: Any):
return yaml.dump(obj, Dumper=_Dumper, default_flow_style=False)


def generate(config, path):
def generate(config: Any, path: str):
"""Dump config to a file as YAML.
config is a dict, preferably an OrderedDict. path is a file path.
"""
f = open(path, 'w+')
f.write('''####################################
f = open(path, "w+")
f.write(
"""####################################
# Evergreen configuration
#
# Generated with evergreen_config_generator from
Expand All @@ -89,5 +107,6 @@ def generate(config, path):
# DO NOT EDIT THIS FILE
#
####################################
''')
"""
)
f.write(yaml_dump(config))
Original file line number Diff line number Diff line change
Expand Up @@ -17,96 +17,106 @@

from evergreen_config_generator import ConfigObject

from . import Value, MutableValueMapping, ValueMapping, ValueOrderedDict

def func(func_name, **kwargs):
od = OD([('func', func_name)])

def func(func_name: str, **kwargs: Value) -> MutableValueMapping:
od: MutableValueMapping = OD([("func", func_name)])
if kwargs:
od['vars'] = OD(sorted(kwargs.items()))
od["vars"] = OD(sorted(kwargs.items()))

return od


def s3_put(remote_file, project_path=True, **kwargs):
def s3_put(remote_file: str, project_path: bool = True, **kwargs: Value) -> ValueMapping:
if project_path:
remote_file = '${project}/' + remote_file

od = OD([
('command', 's3.put'),
('params', OD([
('aws_key', '${aws_key}'),
('aws_secret', '${aws_secret}'),
('remote_file', remote_file),
('bucket', 'mciuploads'),
('permissions', 'public-read')]))])

od['params'].update(kwargs)
return od


def strip_lines(s):
return '\n'.join(line for line in s.split('\n') if line.strip())


def shell_exec(script,
test=True,
errexit=True,
xtrace=False,
silent=False,
continue_on_err=False,
working_dir=None,
background=False,
add_expansions_to_env=False,
redirect_standard_error_to_output=False,
):
dedented = ''
remote_file = "${project}/" + remote_file

return ValueOrderedDict(
[
("command", "s3.put"),
(
"params",
ValueOrderedDict(
(
("aws_key", "${aws_key}"),
("aws_secret", "${aws_secret}"),
("remote_file", remote_file),
("bucket", "mciuploads"),
("permissions", "public-read"),
*kwargs.items(),
)
),
),
]
)


def strip_lines(s: str) -> str:
return "\n".join(line for line in s.split("\n") if line.strip())


def shell_exec(
script: str,
test: bool = True,
errexit: bool = True,
xtrace: bool = False,
silent: bool = False,
continue_on_err: bool = False,
working_dir: str | None = None,
background: bool = False,
add_expansions_to_env: bool = False,
redirect_standard_error_to_output: bool = False,
) -> ValueMapping:
dedented = ""
if errexit:
dedented += 'set -o errexit\n'
dedented += "set -o errexit\n"

if xtrace:
dedented += 'set -o xtrace\n'
dedented += "set -o xtrace\n"

dedented += dedent(strip_lines(script))
command = OD([('command', 'shell.exec')])
command = ValueOrderedDict([("command", "shell.exec")])
if test:
command['type'] = 'test'
command["type"] = "test"

command['params'] = OD()
command["params"] = OD()
if silent:
command['params']['silent'] = True
command["params"]["silent"] = True

if working_dir is not None:
command['params']['working_dir'] = working_dir
command["params"]["working_dir"] = working_dir

if continue_on_err:
command['params']['continue_on_err'] = True
command["params"]["continue_on_err"] = True

if background:
command['params']['background'] = True
command["params"]["background"] = True

if add_expansions_to_env:
command['params']['add_expansions_to_env'] = True
command["params"]["add_expansions_to_env"] = True

if redirect_standard_error_to_output:
command['params']['redirect_standard_error_to_output'] = True
command["params"]["redirect_standard_error_to_output"] = True

command['params']['shell'] = 'bash'
command['params']['script'] = dedented
command["params"]["shell"] = "bash"
command["params"]["script"] = dedented
return command


def targz_pack(target, source_dir, *include):
return OD([
('command', 'archive.targz_pack'),
('params', OD([
('target', target),
('source_dir', source_dir),
('include', list(include))]))])
def targz_pack(target: str, source_dir: str, *include: str) -> ValueMapping:
return OD(
[
("command", "archive.targz_pack"),
("params", OD([("target", target), ("source_dir", source_dir), ("include", list(include))])),
]
)


class Function(ConfigObject):
def __init__(self, *commands):
def __init__(self, *commands: Value):
super(Function, self).__init__()
self.commands = commands

def to_dict(self):
def to_dict(self) -> Value:
return list(self.commands)
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,48 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import MutableMapping
from evergreen_config_generator import ConfigObject

from . import Value, ValueSequence


class TaskGroup(ConfigObject):
def __init__(self, name):
super(TaskGroup, self).__init__()
def __init__(self, name: str):
self._task_group_name = name
self.setup_group: ValueSequence | None = None
self.teardown_group: ValueSequence | None = None
self.setup_task: str | None = None
self.teardown_task: str | None = None
self.max_hosts: str | None = None
self.timeout: str | None = None
self.setup_group_can_fail_task: bool | None = None
self.setup_group_timeout_secs: int | None = None
self.share_processes: str | None = None
self.tasks: ValueSequence | None = None

@property
def name(self):
def name(self) -> str:
return self._task_group_name

def to_dict(self):
v = super(TaskGroup, self).to_dict()
def to_dict(self) -> Value:
v = super().to_dict()
assert isinstance(v, MutableMapping)
# See possible TaskGroup attributes from the Evergreen wiki:
# https://github.com/evergreen-ci/evergreen/wiki/Project-Configuration-Files#task-groups
attrs = [
'setup_group',
'teardown_group',
'setup_task',
'teardown_task',
'max_hosts',
'timeout',
'setup_group_can_fail_task',
'setup_group_timeout_secs',
'setup_group_can_fail_task',
'share_processes',
'tasks'
]

"setup_group",
"teardown_group",
"setup_task",
"teardown_task",
"max_hosts",
"timeout",
"setup_group_can_fail_task",
"setup_group_timeout_secs",
"share_processes",
"tasks",
]

for i in attrs:
if getattr(self, i, None):
v[i] = getattr(self, i)
Expand Down
Loading