Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Aug 23, 2024
1 parent 6e60ee6 commit 69fa172
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 97 deletions.
3 changes: 2 additions & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[codespell]
# skipping auto generated folders
skip = ./.tox,./.mypy_cache,./docs/_build,./target,*/LICENSE,./venv,.git,./opentelemetry-semantic-conventions,*-requirements*.txt
skip = ./.tox,./.mypy_cache,./docs/_build,./target,*/LICENSE,./venv,.git,./opentelemetry-semantic-conventions,*-requirements*.txt,./_file_configuration/.nox

ignore-words-list = ans,ue,ot,hist,ro
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exclude =
.hg
.svn
.tox
.nox
CVS
.venv*/
venv*/
Expand Down
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ profile=black
; docs: https://github.com/timothycrosley/isort#multi-line-output-modes
multi_line_output=3
skip=target
skip_glob=**/gen/*,.venv*/*,venv*/*,**/proto/*,.tox/*
skip_glob=**/gen/*,.venv*/*,venv*/*,**/proto/*,.tox/*,_file_configuration/.nox/*
known_first_party=opentelemetry,opentelemetry_example_app
known_third_party=psutil,pytest,redis,redis_opentracing
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension-pkg-whitelist=

# Add list of files or directories to be excluded. They should be base names, not
# paths.
ignore=CVS,gen,proto
ignore=CVS,gen,proto,_file_configuration

# Add files or directories matching the regex patterns to be excluded. The
# regex matches against base names, not paths.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@


from opentelemetry.file_configuration._internal import (
SometimesMondaysOnSamplerPlugin,
create_object,
load_file_configuration,
process_schema,
render_schema,
resolve_schema,
substitute_environment_variables,
validate_file_configuration,
SometimesMondaysOnSamplerPlugin
)

__all__ = [
Expand All @@ -37,5 +37,5 @@
"create_object",
"load_file_configuration",
"substitute_environment_variables",
"SometimesMondayOnSamplerPlugin"
"SometimesMondaysOnSamplerPlugin",
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from abc import ABC, abstractmethod
from collections import OrderedDict
from datetime import datetime
from logging import getLogger
from os import environ
from pathlib import Path
from re import compile as re_compile
from abc import ABC, abstractmethod
from logging import getLogger
from datetime import datetime
from random import random

from re import compile as re_compile
from typing import Optional, Sequence
from opentelemetry.trace import Link, SpanKind
from opentelemetry.trace.span import TraceState
from opentelemetry.util.types import Attributes
from opentelemetry.context import Context

from black import Mode, format_str
from ipdb import set_trace
from jinja2 import Environment, FileSystemLoader
from jsonref import JsonRef
from jsonref import loads as jsonref_loads
from jsonschema.validators import Draft202012Validator
from yaml import safe_load
from black import format_str, Mode
from opentelemetry.util._importlib_metadata import entry_points

from opentelemetry.file_configuration._internal.path_function import path_function
from opentelemetry.context import Context
from opentelemetry.file_configuration._internal.path_function import (
path_function,
)
from opentelemetry.sdk.trace.sampling import Sampler, SamplingResult
from opentelemetry.trace import Link, SpanKind
from opentelemetry.trace.span import TraceState
from opentelemetry.util._importlib_metadata import entry_points
from opentelemetry.util.types import Attributes

_logger = getLogger(__file__)

Expand Down Expand Up @@ -66,7 +67,6 @@ def set_path_function(path_function: dict) -> None:


class FileConfigurationPlugin(ABC):

@property
@abstractmethod
def schema(self) -> dict:
Expand Down Expand Up @@ -122,7 +122,6 @@ def get_description(self) -> str:


class SometimesMondaysOnSamplerPlugin(FileConfigurationPlugin):

@property
def schema(self) -> tuple:
"""
Expand All @@ -134,11 +133,9 @@ def schema(self) -> tuple:
"type": "object",
"additionalProperties": False,
"properties": {
"probability": {
"type": "number"
},
}
}
"probability": {"type": "number"},
},
},
)

@property
Expand All @@ -151,7 +148,7 @@ def schema_path(self) -> list:
"tracer_provider",
"properties",
"sampler",
"properties"
"properties",
]

@staticmethod
Expand Down Expand Up @@ -187,7 +184,7 @@ def resolve_schema(json_file_path) -> dict:
_logger.warning(
"Unable to add plugin %s to schema: wrong schema path %s",
entry_point.name,
",".join(schema_path)
",".join(schema_path),
)
break
else:
Expand All @@ -201,16 +198,14 @@ def resolve_schema(json_file_path) -> dict:
if schema_path_part == "properties":
continue

sub_path_function = (
sub_path_function[schema_path_part]["children"]
)
sub_path_function = sub_path_function[schema_path_part]["children"]

sub_path_function[plugin.schema[0]] = {}
sub_path_function[plugin.schema[0]]["function"] = plugin.function
sub_path_function[plugin.schema[0]]["children"] = {}
sub_path_function[plugin.schema[0]]["recursive_path"] = (
plugin.recursive_path
)
sub_path_function[plugin.schema[0]][
"recursive_path"
] = plugin.recursive_path

set_path_function(original_path_function)

Expand All @@ -225,8 +220,7 @@ def load_file_configuration(file_configuration_file_path: str) -> dict:


def validate_file_configuration(
schema: dict,
file_configuration: dict
schema: dict, file_configuration: dict
) -> None:
Draft202012Validator(schema).validate(file_configuration)

Expand Down Expand Up @@ -270,19 +264,17 @@ def traverse(

for positional_attribute in positional_attributes:

result_positional_attributes[positional_attribute] = (
_type_type[
schema_properties[positional_attribute]["type"]
].__name__
)
result_positional_attributes[
positional_attribute
] = _type_type[
schema_properties[positional_attribute]["type"]
].__name__

for optional_attribute in optional_attributes:

result_optional_attributes[optional_attribute] = (
_type_type[
schema_properties[optional_attribute]["type"]
].__name__
)
result_optional_attributes[optional_attribute] = _type_type[
schema_properties[optional_attribute]["type"]
].__name__

children = {}

Expand Down Expand Up @@ -436,7 +428,7 @@ def create_object(
file_configuration: dict,
processed_schema: dict,
object_name: str,
dry_run=False
dry_run=False,
) -> object:
def create_object(
file_configuration: dict,
Expand All @@ -449,7 +441,10 @@ def create_object(
positional_arguments = []
optional_arguments = {}

for file_configuration_key, file_configuration_value in file_configuration.items():
for (
file_configuration_key,
file_configuration_value,
) in file_configuration.items():

if isinstance(file_configuration_value, dict):

Expand All @@ -467,7 +462,9 @@ def create_object(
new_processed_schema = new_processed_schema[
file_configuration_key
]
new_path_function = new_path_function[file_configuration_key]
new_path_function = new_path_function[
file_configuration_key
]
else:
new_processed_schema = processed_schema["children"][
file_configuration_key
Expand All @@ -493,7 +490,9 @@ def create_object(
object_.append(
create_object(
element,
processed_schema["children"][file_configuration_key],
processed_schema["children"][
file_configuration_key
],
path_function["children"][file_configuration_key],
original_processed_schema,
original_path_function,
Expand Down Expand Up @@ -539,7 +538,10 @@ def traverse(
original_processed_schema: dict,
):

for file_configuration_key, file_configuration_value in file_configuration.items():
for (
file_configuration_key,
file_configuration_value,
) in file_configuration.items():

if file_configuration_key not in processed_schema.keys():
continue
Expand All @@ -558,10 +560,14 @@ def traverse(
children = children[recursive_path]["children"]

else:
children = processed_schema[file_configuration_key]["children"]
children = processed_schema[file_configuration_key][
"children"
]

traverse(
file_configuration_value, children, original_processed_schema
file_configuration_value,
children,
original_processed_schema,
)

elif isinstance(file_configuration_value, list):
Expand All @@ -570,13 +576,17 @@ def traverse(
if isinstance(element, dict):
traverse(
element,
processed_schema[file_configuration_key]["children"],
processed_schema[file_configuration_key][
"children"
],
original_processed_schema,
)

elif isinstance(file_configuration_value, str):

match = _environment_variable_regex.match(file_configuration_value)
match = _environment_variable_regex.match(
file_configuration_value
)

if match is not None:

Expand Down
Loading

0 comments on commit 69fa172

Please sign in to comment.