Skip to content

Commit

Permalink
fix pyproject exclusion and ddev (#14257)
Browse files Browse the repository at this point in the history
* fix pyproject exclusion and ddev

* revert a change to the incorrect file

* revert a change to the incorrect file

* add skip QAs to template files (#14258)

* fix

* Final linting fixes (#14266)

* linting fixes

* linting fixes

* fix vsphere
  • Loading branch information
steveny91 committed Mar 30, 2023
1 parent 246b4d8 commit f4a182a
Show file tree
Hide file tree
Showing 48 changed files with 407 additions and 388 deletions.
2 changes: 1 addition & 1 deletion cloudera/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from contextlib import nullcontext as does_not_raise

import pytest
from tests.common import METRICS

from datadog_checks.base.types import ServiceCheck
from datadog_checks.cloudera.metrics import TIMESERIES_METRICS
from tests.common import METRICS


@pytest.mark.usefixtures('dd_environment')
Expand Down
2 changes: 1 addition & 1 deletion cloudera/tests/test_unit_autodiscover.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import mock
import pytest
from packaging.version import Version
from tests.common import query_time_series

from datadog_checks.base.types import ServiceCheck
from datadog_checks.cloudera.metrics import NATIVE_METRICS, TIMESERIES_METRICS
from tests.common import query_time_series

pytestmark = [pytest.mark.unit]

Expand Down
2 changes: 1 addition & 1 deletion cloudera/tests/test_unit_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import mock
import pytest
from packaging.version import Version
from tests.common import query_time_series

from datadog_checks.base.types import ServiceCheck
from datadog_checks.cloudera.metrics import TIMESERIES_METRICS
from tests.common import query_time_series

pytestmark = [pytest.mark.unit]

Expand Down
2 changes: 1 addition & 1 deletion cloudera/tests/test_unit_disks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import mock
import pytest
from packaging.version import Version
from tests.common import query_time_series

from datadog_checks.base.types import ServiceCheck
from datadog_checks.cloudera.metrics import TIMESERIES_METRICS
from tests.common import query_time_series

pytestmark = [pytest.mark.unit]

Expand Down
2 changes: 1 addition & 1 deletion cloudera/tests/test_unit_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import mock
import pytest
from packaging.version import Version
from tests.common import query_time_series

from datadog_checks.base.types import ServiceCheck
from datadog_checks.cloudera.metrics import NATIVE_METRICS, TIMESERIES_METRICS
from tests.common import query_time_series

pytestmark = [pytest.mark.unit]

Expand Down
2 changes: 1 addition & 1 deletion cloudera/tests/test_unit_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import mock
import pytest
from packaging.version import Version
from tests.common import query_time_series

from datadog_checks.base.types import ServiceCheck
from datadog_checks.cloudera.metrics import TIMESERIES_METRICS
from tests.common import query_time_series

pytestmark = [pytest.mark.unit]

Expand Down
15 changes: 14 additions & 1 deletion datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@
import unicodedata
from collections import deque
from os.path import basename
from typing import TYPE_CHECKING, Any, AnyStr, Callable, Deque, Dict, List, Optional, Sequence, Set, Tuple, Union # noqa: F401
from typing import ( # noqa: F401
TYPE_CHECKING,
Any,
AnyStr,
Callable,
Deque,
Dict,
List,
Optional,
Sequence,
Set,
Tuple,
Union,
)

import yaml
from six import PY2, binary_type, iteritems, raise_from, text_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def __init__(self, check, config):
)

self.exclude_metrics_by_labels[label] = (
lambda label_value, pattern=re.compile('|'.join(values)): pattern.search(label_value) # noqa: B008, E501
lambda label_value, pattern=re.compile('|'.join(values)): pattern.search( # noqa: B008
label_value
) # noqa: B008, E501
is not None
)
else:
Expand Down
3 changes: 1 addition & 2 deletions datadog_checks_base/tests/base/checks/test_agent_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import pytest
from six import PY3

from datadog_checks.base import AgentCheck
from datadog_checks.base import AgentCheck, to_native_string
from datadog_checks.base import __version__ as base_package_version
from datadog_checks.base import to_native_string
from datadog_checks.base.checks.base import datadog_agent
from datadog_checks.dev.testing import requires_py3

Expand Down
4 changes: 3 additions & 1 deletion datadog_checks_dev/datadog_checks/dev/plugin/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ def pytest_collection_modifyitems(config, items):
if PY2:
for option in ("--memray",):
if config.getoption(option):
warnings.warn("`{}` option ignored as it's not supported for py2 environments.".format(option)) # noqa: B028, E501
warnings.warn( # noqa: B028
"`{}` option ignored as it's not supported for py2 environments.".format(option)
) # noqa: B028, E501

skip_latest_metrics = pytest.mark.skip(reason="need --run-latest-metrics option to run")
for item in items:
Expand Down
3 changes: 1 addition & 2 deletions datadog_checks_dev/datadog_checks/dev/plugin/tox.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ def add_style_formatter(config, sections, make_envconfig, reader):
# Run formatter AFTER sorting imports
'commands': '\n'.join(
[
'ruff . --config ../pyproject.toml'
'black . --config ../pyproject.toml',
'ruff . --config ../pyproject.toml' 'black . --config ../pyproject.toml',
'python -c "print(\'\\n[NOTE] ruff may still report style errors for things it cannot fix, '
'these will need to be fixed manually.\')"',
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ def generate_traps_db(mib_sources, output_dir, output_file, output_format, no_de
if not os.path.isdir(mibs_sources_dir):
os.mkdir(mibs_sources_dir)

mib_sources = (
sorted({pathlib.Path(x).parent.as_uri() for x in mib_files if os.path.sep in x}) + mib_sources
)
mib_sources = sorted({pathlib.Path(x).parent.as_uri() for x in mib_files if os.path.sep in x}) + mib_sources

mib_files = [os.path.basename(x) for x in mib_files]
searchers = [AnyFileSearcher(compiled_mibs_sources).setOptions(exts=['.json'])]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{license_header}
from typing import Any
from typing import Any # noqa: F401

from datadog_checks.base import AgentCheck
from datadog_checks.base import AgentCheck # noqa: F401

# from datadog_checks.base.utils.db import QueryManager
# from requests.exceptions import ConnectionError, HTTPError, InvalidURL, Timeout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{license_header}

from typing import Any, Callable, Dict
from typing import Any, Callable, Dict # noqa: F401

from datadog_checks.base import AgentCheck
from datadog_checks.base.stubs.aggregator import AggregatorStub
from datadog_checks.base import AgentCheck # noqa: F401
from datadog_checks.base.stubs.aggregator import AggregatorStub # noqa: F401
from datadog_checks.dev.utils import get_metadata_metrics
from datadog_checks.{check_name} import {check_class}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{license_header}
from typing import Any
from typing import Any # noqa: F401

import pytest

from datadog_checks.base import AgentCheck
from datadog_checks.base.stubs.aggregator import AggregatorStub
from datadog_checks.base.stubs.aggregator import AggregatorStub # noqa: F401

from .common import CHECK_CONFIG
from .metrics import METRICS
Expand Down
2 changes: 1 addition & 1 deletion datadog_checks_dev/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ cli = [
"toml>=0.9.4, <1.0.0",
"tomli>=1.1.0",
"tomli-w>=1.0.0",
"tox>=3.12.1, <4.0.0",
"tox>=3.12.1, <4.0.0",
"twine>=1.11.0",
"virtualenv",
# TODO: Remove once every check has a pyproject.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import mock
import pytest
import tests.tooling.manifest_validator.input_constants as input_constants

import datadog_checks.dev.tooling.manifest_validator.common.validator as common
import datadog_checks.dev.tooling.manifest_validator.v2.validator as v2_validators
import tests.tooling.manifest_validator.input_constants as input_constants
from datadog_checks.dev.tooling.constants import get_root, set_root
from datadog_checks.dev.tooling.datastructures import JSONDict
from datadog_checks.dev.tooling.manifest_validator.constants import V2
Expand Down
2 changes: 1 addition & 1 deletion datadog_checks_downloader/tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
from freezegun import freeze_time
from packaging.version import parse as parse_version
from tenacity import retry, stop_after_attempt, wait_exponential
from tests.local_http import local_http_server, local_http_server_local_dir
from tuf.api.exceptions import DownloadError, ExpiredMetadataError, RepositoryError, UnsignedMetadataError

import datadog_checks.downloader
from datadog_checks.downloader.cli import download
from datadog_checks.downloader.download import REPOSITORY_URL_PREFIX
from datadog_checks.downloader.exceptions import NonDatadogPackage, NoSuchDatadogPackage
from tests.local_http import local_http_server, local_http_server_local_dir

_LOGGER = logging.getLogger("test_downloader")

Expand Down
4 changes: 1 addition & 3 deletions datadog_checks_tests_helper/datadog_test_libs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
# Licensed under a 3-clause BSD style license (see LICENSE)
from .__about__ import __version__

__all__ = [
'__version__'
]
__all__ = ['__version__']
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def mock_local(src_to_dest_mapping):
If port is None or evaluates to False, then only the host will be overridden and not the port.
"""
import socket

_orig_getaddrinfo = socket.getaddrinfo
_orig_connect = socket.socket.connect

Expand Down
12 changes: 3 additions & 9 deletions datadog_checks_tests_helper/datadog_test_libs/win/pdh_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ def pdh_mocks_fixture():
pdhcollectquerydata = mock.patch('win32pdh.CollectQueryData', mock_CollectQueryData)
pdhvalidatepath = mock.patch('win32pdh.ValidatePath', mock_ValidatePath)

yield regqueryvalueex.start(), pdhlookupbyindex.start(), \
pdhenumobjectitems.start(), pdhmakecounterpath.start(), \
pdhaddcounter.start(), pdhgetformattedcountervalue.start(), pdhcollectquerydata.start(), \
pdhvalidatepath.start()
yield regqueryvalueex.start(), pdhlookupbyindex.start(), pdhenumobjectitems.start(), pdhmakecounterpath.start(), pdhaddcounter.start(), pdhgetformattedcountervalue.start(), pdhcollectquerydata.start(), pdhvalidatepath.start() # noqa: E501

regqueryvalueex.stop()
pdhlookupbyindex.stop()
Expand All @@ -62,10 +59,7 @@ def pdh_mocks_fixture_bad_perf_strings():
pdhcollectquerydata = mock.patch('win32pdh.CollectQueryData', mock_CollectQueryData)
pdhvalidatepath = mock.patch('win32pdh.ValidatePath', mock_ValidatePath)

yield regqueryvalueex.start(), pdhlookupbyindex.start(), \
pdhenumobjectitems.start(), pdhmakecounterpath.start(), \
pdhaddcounter.start(), pdhgetformattedcountervalue.start(), pdhcollectquerydata.start(), \
pdhvalidatepath.start()
yield regqueryvalueex.start(), pdhlookupbyindex.start(), pdhenumobjectitems.start(), pdhmakecounterpath.start(), pdhaddcounter.start(), pdhgetformattedcountervalue.start(), pdhcollectquerydata.start(), pdhvalidatepath.start() # noqa: E501

regqueryvalueex.stop()
pdhlookupbyindex.stop()
Expand Down Expand Up @@ -159,7 +153,7 @@ def load_registry_values(fname):
idx = 0
idx_max = len(idx_array)
while idx < idx_max:
ctr_index[int(idx_array[idx])] = idx_array[idx+1]
ctr_index[int(idx_array[idx])] = idx_array[idx + 1]
idx += 2
return idx_array, ctr_index

Expand Down
5 changes: 0 additions & 5 deletions datadog_checks_tests_helper/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def get_requirements(fpath):
setup(
# Version should always match one from an agent release
version=ABOUT["__version__"],

name='datadog_checks_tests_helper',
description='The Datadog Check Tests Helpers',
long_description=LONG_DESC,
Expand All @@ -37,7 +36,6 @@ def get_requirements(fpath):
author='Datadog',
author_email='packages@datadoghq.com',
license='BSD',

# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand All @@ -47,10 +45,7 @@ def get_requirements(fpath):
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
],

packages=find_packages(),

include_package_data=True,
install_requires=get_requirements('requirements.in'),

)
11 changes: 0 additions & 11 deletions ddev/.flake8

This file was deleted.

54 changes: 46 additions & 8 deletions ddev/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,49 @@ line-length = 120
skip-string-normalization = true
target-version = ["py38"]

[tool.isort]
default_section = "THIRDPARTY"
force_grid_wrap = 0
include_trailing_comma = true
known_first_party = ["ddev"]
line_length = 120
multi_line_output = 3
use_parentheses = true
[tool.ruff]
exclude = [
".eggs",
".tox",
"build",
"compat.py",
"__init__.py",
"**/datadog_checks/dev/tooling/templates/*",
"**/datadog_checks/*/vendor/*",
]
target-version = "py37"
line-length = 120
select = [
"B",
"C",
"E",
"F",
"G",
"W",
"I",
]
ignore = [
# From legacy flake8 settings
"E722",
"E741",
"B015",
"B904",
# Allow non-abstract empty methods in abstract base classes
"B027",
# Ignore McCabe complexity
"C901",
]
unfixable = [
# Don't touch unused imports
"F401",
]

[tool.ruff.isort]
known-first-party = ["{template_config['package_name']}"]

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.per-file-ignores]
#Tests can use assertions and relative imports
"**/tests/**/*" = ["I252"]
1 change: 0 additions & 1 deletion ddev/tests/cli/config/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os

import pytest

from ddev.config.constants import ConfigEnvVars


Expand Down
1 change: 0 additions & 1 deletion ddev/tests/cli/status/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import pytest

from ddev.config.constants import AppEnvVars
from ddev.utils.structures import EnvVars

Expand Down
1 change: 0 additions & 1 deletion ddev/tests/cli/validate/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import json

import pytest

from ddev.utils.structures import EnvVars


Expand Down
1 change: 0 additions & 1 deletion ddev/tests/config/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os

import pytest

from ddev.config.model import ConfigurationError, RootConfig


Expand Down
Loading

0 comments on commit f4a182a

Please sign in to comment.