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

Adhere to code style #3497

Merged
merged 1 commit into from
Apr 21, 2019
Merged
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
1 change: 0 additions & 1 deletion datadog_checks_dev/datadog_checks/dev/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@

from .tooling.cli import ddev


sys.exit(ddev())
1 change: 0 additions & 1 deletion datadog_checks_dev/datadog_checks/dev/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Licensed under a 3-clause BSD style license (see LICENSE)
import six


if six.PY3:
from json import JSONDecodeError

Expand Down
27 changes: 4 additions & 23 deletions datadog_checks_dev/datadog_checks/dev/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ def __call__(self):

time.sleep(self.wait)
else:
raise RetryError(
'Result: {}\n'
'Error: {}'.format(
repr(last_result),
last_error,
)
)
raise RetryError('Result: {}\n' 'Error: {}'.format(repr(last_result), last_error))


class CheckEndpoints(LazyFunction):
Expand Down Expand Up @@ -82,13 +76,7 @@ def __call__(self):

time.sleep(self.wait)
else:
raise RetryError(
'Endpoint: {}\n'
'Error: {}'.format(
last_endpoint,
last_error
)
)
raise RetryError('Endpoint: {}\n' 'Error: {}'.format(last_endpoint, last_error))


class CheckCommandOutput(LazyFunction):
Expand All @@ -106,8 +94,7 @@ def __init__(self, command, patterns, matches=1, stdout=True, stderr=True, attem
patterns = [patterns]

self.patterns = [
re.compile(pattern, re.M) if isinstance(pattern, string_types) else pattern
for pattern in patterns
re.compile(pattern, re.M) if isinstance(pattern, string_types) else pattern for pattern in patterns
]

if matches == 'all':
Expand Down Expand Up @@ -141,13 +128,7 @@ def __call__(self):
time.sleep(self.wait)
else:
raise RetryError(
u'Command: {}\n'
u'Exit code: {}\n'
u'Captured Output: {}'.format(
self.command,
exit_code,
log_output
)
u'Command: {}\n' u'Exit code: {}\n' u'Captured Output: {}'.format(self.command, exit_code, log_output)
)


Expand Down
4 changes: 2 additions & 2 deletions datadog_checks_dev/datadog_checks/dev/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_container_ip(container_id_or_name):
'inspect',
'-f',
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}',
container_id_or_name
container_id_or_name,
]

return run_command(command, capture='out', check=True).stdout.strip()
Expand Down Expand Up @@ -53,7 +53,7 @@ def docker_run(
log_patterns=None,
conditions=None,
env_vars=None,
wrapper=None
wrapper=None,
):
"""This utility provides a convenient way to safely set up and tear down Docker environments.

Expand Down
10 changes: 1 addition & 9 deletions datadog_checks_dev/datadog_checks/dev/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@


@contextmanager
def environment_run(
up,
down,
sleep=None,
endpoints=None,
conditions=None,
env_vars=None,
wrapper=None
):
def environment_run(up, down, sleep=None, endpoints=None, conditions=None, env_vars=None, wrapper=None):
"""This utility provides a convenient way to safely set up and tear down arbitrary types of environments.

:param up: A custom setup callable.
Expand Down
1 change: 1 addition & 0 deletions datadog_checks_dev/datadog_checks/dev/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ class ManifestError(Exception):
"""
Raised when the manifest.json file is malformed
"""

pass
5 changes: 1 addition & 4 deletions datadog_checks_dev/datadog_checks/dev/plugin/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ def dd_environment_runner(request):
metadata.setdefault('env_vars', {})
metadata['env_vars'].update(get_env_vars(raw=True))

data = {
'config': config,
'metadata': metadata,
}
data = {'config': config, 'metadata': metadata}

# Serialize to json
data = json.dumps(data, separators=(',', ':'))
Expand Down
8 changes: 1 addition & 7 deletions datadog_checks_dev/datadog_checks/dev/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ def run_command(command, capture=None, check=False, encoding='utf-8', shell=Fals

if check and process.returncode != 0:
raise SubprocessError(
'Command: {}\n'
'Exit code: {}\n'
'Captured Output: {}'.format(
command,
process.returncode,
stdout + stderr
)
'Command: {}\n' 'Exit code: {}\n' 'Captured Output: {}'.format(command, process.returncode, stdout + stderr)
)

return SubprocessResult(stdout, stderr, process.returncode)
22 changes: 3 additions & 19 deletions datadog_checks_dev/datadog_checks/dev/tooling/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,11 @@
from glob import iglob
from os.path import join

from .utils import is_package
from ..utils import dir_exists, remove_path
from .utils import is_package

DELETE_IN_ROOT = {
'.cache',
'.coverage',
'.eggs',
'.pytest_cache',
'.tox',
'build',
'dist',
'*.egg-info',
'.benchmarks'
}
DELETE_EVERYWHERE = {
'__pycache__',
'*.pyc',
'*.pyd',
'*.pyo',
'*.whl',
}
DELETE_IN_ROOT = {'.cache', '.coverage', '.eggs', '.pytest_cache', '.tox', 'build', 'dist', '*.egg-info', '.benchmarks'}
DELETE_EVERYWHERE = {'__pycache__', '*.pyc', '*.pyd', '*.pyo', '*.whl'}
ALL_PATTERNS = DELETE_IN_ROOT | DELETE_EVERYWHERE


Expand Down
18 changes: 5 additions & 13 deletions datadog_checks_dev/datadog_checks/dev/tooling/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import click

from ..compat import PermissionError
from ..utils import dir_exists
from .commands import ALL_COMMANDS
from .commands.console import CONTEXT_SETTINGS, echo_success, echo_waiting, echo_warning
from .config import CONFIG_FILE, config_file_exists, load_config, restore_config
from .constants import set_root
from ..compat import PermissionError
from ..utils import dir_exists


@click.group(context_settings=CONTEXT_SETTINGS, invoke_without_command=True)
Expand All @@ -23,28 +23,20 @@
@click.pass_context
def ddev(ctx, core, extras, agent, here, quiet):
if not quiet and not config_file_exists():
echo_waiting(
'No config file found, creating one with default settings now...'
)
echo_waiting('No config file found, creating one with default settings now...')

try:
restore_config()
echo_success('Success! Please see `ddev config`.')
except (IOError, OSError, PermissionError):
echo_warning(
'Unable to create config file located at `{}`. '
'Please check your permissions.'.format(CONFIG_FILE)
'Unable to create config file located at `{}`. ' 'Please check your permissions.'.format(CONFIG_FILE)
)

# Load and store configuration for sub-commands.
config = load_config()

repo_choice = (
'core' if core
else 'extras' if extras
else 'agent' if agent
else config.get('repo', 'core')
)
repo_choice = 'core' if core else 'extras' if extras else 'agent' if agent else config.get('repo', 'core')

config['repo_choice'] = repo_choice
ctx.obj = config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,4 @@
from .test import test
from .validate import validate

ALL_COMMANDS = (
agent,
clean,
config,
create,
dep,
env,
meta,
release,
run,
test,
validate,
)
ALL_COMMANDS = (agent, clean, config, create, dep, env, meta, release, run, test, validate)
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@

from ..console import CONTEXT_SETTINGS
from .changelog import changelog
from .requirements import requirements
from .integrations import integrations
from .requirements import requirements


ALL_COMMANDS = (
changelog,
requirements,
integrations,
)
ALL_COMMANDS = (changelog, requirements, integrations)


@click.group(
context_settings=CONTEXT_SETTINGS,
short_help='A collection of tasks related to the Datadog Agent'
)
@click.group(context_settings=CONTEXT_SETTINGS, short_help='A collection of tasks related to the Datadog Agent')
def agent():
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
# (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import os
import json
import os
from collections import OrderedDict

import click
from six import StringIO, iteritems

from .common import get_agent_tags
from ..console import CONTEXT_SETTINGS, abort, echo_info
from ...constants import get_root, get_agent_release_requirements, get_agent_changelog
from ....utils import read_file, write_file
from ...constants import get_agent_changelog, get_agent_release_requirements, get_root
from ...git import git_show_file
from ...release import get_folder_name, get_package_name, DATADOG_PACKAGE_PREFIX
from ...release import DATADOG_PACKAGE_PREFIX, get_folder_name, get_package_name
from ...utils import parse_agent_req_file
from ....utils import write_file, read_file
from ..console import CONTEXT_SETTINGS, abort, echo_info
from .common import get_agent_tags


@click.command(
context_settings=CONTEXT_SETTINGS,
short_help="Provide a list of updated checks on a given Datadog Agent version, in changelog form"
short_help="Provide a list of updated checks on a given Datadog Agent version, in changelog form",
)
@click.option('--since', help="Initial Agent version", default='6.3.0')
@click.option('--to', help="Final Agent version")
@click.option(
'--write',
'-w',
is_flag=True,
help="Write to the changelog file, if omitted contents will be printed to stdout"
'--write', '-w', is_flag=True, help="Write to the changelog file, if omitted contents will be printed to stdout"
)
@click.option('--force', '-f', is_flag=True, default=False, help="Replace an existing file")
def changelog(since, to, write, force):
Expand Down Expand Up @@ -63,9 +60,11 @@ def changelog(since, to, write, force):
# at some point in the git history, the requirements file erroneusly
# contained the folder name instead of the package name for each check,
# let's be resilient
old_ver = catalog_prev.get(name) \
or catalog_prev.get(get_folder_name(name)) \
old_ver = (
catalog_prev.get(name)
or catalog_prev.get(get_folder_name(name))
or catalog_prev.get(get_package_name(name))
)

# normalize the package name to the check_name
if name.startswith(DATADOG_PACKAGE_PREFIX):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import click
from six import StringIO, iteritems

from .common import get_agent_tags
from ..console import CONTEXT_SETTINGS, abort, echo_info
from ...constants import get_agent_release_requirements, get_agent_integrations_file
from ....utils import write_file
from ...constants import get_agent_integrations_file, get_agent_release_requirements
from ...git import git_show_file
from ...utils import parse_agent_req_file
from ....utils import write_file
from ..console import CONTEXT_SETTINGS, abort, echo_info
from .common import get_agent_tags


@click.command(
context_settings=CONTEXT_SETTINGS,
short_help="Provide a list of updated checks on a given Datadog Agent version, in changelog form"
short_help="Provide a list of updated checks on a given Datadog Agent version, in changelog form",
)
@click.option('--since', help="Initial Agent version", default='6.3.0')
@click.option('--to', help="Final Agent version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
# Licensed under a 3-clause BSD style license (see LICENSE)
import click

from ..console import (
CONTEXT_SETTINGS, echo_failure, echo_info, echo_success
)
from ....utils import write_file_lines
from ...constants import AGENT_V5_ONLY, get_agent_release_requirements
from ...release import get_agent_requirement_line
from ...utils import get_valid_checks, get_version_string
from ....utils import write_file_lines
from ..console import CONTEXT_SETTINGS, echo_failure, echo_info, echo_success


@click.command(
context_settings=CONTEXT_SETTINGS,
short_help="Generate the list of integrations to ship with the Agent and save it to '{}'".format(
get_agent_release_requirements()
)
),
)
@click.pass_context
def requirements(ctx):
Expand Down
Loading