1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ from abc import ABC , abstractmethod
1516from collections import OrderedDict
17+ from datetime import datetime
18+ from logging import getLogger
1619from os import environ
1720from pathlib import Path
18- from re import compile as re_compile
19- from abc import ABC , abstractmethod
20- from logging import getLogger
21- from datetime import datetime
2221from random import random
23-
22+ from re import compile as re_compile
2423from typing import Optional , Sequence
25- from opentelemetry .trace import Link , SpanKind
26- from opentelemetry .trace .span import TraceState
27- from opentelemetry .util .types import Attributes
28- from opentelemetry .context import Context
2924
25+ from black import Mode , format_str
3026from ipdb import set_trace
3127from jinja2 import Environment , FileSystemLoader
3228from jsonref import JsonRef
3329from jsonref import loads as jsonref_loads
3430from jsonschema .validators import Draft202012Validator
3531from yaml import safe_load
36- from black import format_str , Mode
37- from opentelemetry .util ._importlib_metadata import entry_points
3832
39- from opentelemetry .file_configuration ._internal .path_function import path_function
33+ from opentelemetry .context import Context
34+ from opentelemetry .file_configuration ._internal .path_function import (
35+ path_function ,
36+ )
4037from opentelemetry .sdk .trace .sampling import Sampler , SamplingResult
38+ from opentelemetry .trace import Link , SpanKind
39+ from opentelemetry .trace .span import TraceState
40+ from opentelemetry .util ._importlib_metadata import entry_points
41+ from opentelemetry .util .types import Attributes
4142
4243_logger = getLogger (__file__ )
4344
@@ -66,7 +67,6 @@ def set_path_function(path_function: dict) -> None:
6667
6768
6869class FileConfigurationPlugin (ABC ):
69-
7070 @property
7171 @abstractmethod
7272 def schema (self ) -> dict :
@@ -122,7 +122,6 @@ def get_description(self) -> str:
122122
123123
124124class SometimesMondaysOnSamplerPlugin (FileConfigurationPlugin ):
125-
126125 @property
127126 def schema (self ) -> tuple :
128127 """
@@ -134,11 +133,9 @@ def schema(self) -> tuple:
134133 "type" : "object" ,
135134 "additionalProperties" : False ,
136135 "properties" : {
137- "probability" : {
138- "type" : "number"
139- },
140- }
141- }
136+ "probability" : {"type" : "number" },
137+ },
138+ },
142139 )
143140
144141 @property
@@ -151,7 +148,7 @@ def schema_path(self) -> list:
151148 "tracer_provider" ,
152149 "properties" ,
153150 "sampler" ,
154- "properties"
151+ "properties" ,
155152 ]
156153
157154 @staticmethod
@@ -187,7 +184,7 @@ def resolve_schema(json_file_path) -> dict:
187184 _logger .warning (
188185 "Unable to add plugin %s to schema: wrong schema path %s" ,
189186 entry_point .name ,
190- "," .join (schema_path )
187+ "," .join (schema_path ),
191188 )
192189 break
193190 else :
@@ -201,16 +198,14 @@ def resolve_schema(json_file_path) -> dict:
201198 if schema_path_part == "properties" :
202199 continue
203200
204- sub_path_function = (
205- sub_path_function [schema_path_part ]["children" ]
206- )
201+ sub_path_function = sub_path_function [schema_path_part ]["children" ]
207202
208203 sub_path_function [plugin .schema [0 ]] = {}
209204 sub_path_function [plugin .schema [0 ]]["function" ] = plugin .function
210205 sub_path_function [plugin .schema [0 ]]["children" ] = {}
211- sub_path_function [plugin .schema [0 ]]["recursive_path" ] = (
212- plugin . recursive_path
213- )
206+ sub_path_function [plugin .schema [0 ]][
207+ " recursive_path"
208+ ] = plugin . recursive_path
214209
215210 set_path_function (original_path_function )
216211
@@ -225,8 +220,7 @@ def load_file_configuration(file_configuration_file_path: str) -> dict:
225220
226221
227222def validate_file_configuration (
228- schema : dict ,
229- file_configuration : dict
223+ schema : dict , file_configuration : dict
230224) -> None :
231225 Draft202012Validator (schema ).validate (file_configuration )
232226
@@ -270,19 +264,17 @@ def traverse(
270264
271265 for positional_attribute in positional_attributes :
272266
273- result_positional_attributes [positional_attribute ] = (
274- _type_type [
275- schema_properties [ positional_attribute ][ "type" ]
276- ]. __name__
277- )
267+ result_positional_attributes [
268+ positional_attribute
269+ ] = _type_type [
270+ schema_properties [ positional_attribute ][ "type" ]
271+ ]. __name__
278272
279273 for optional_attribute in optional_attributes :
280274
281- result_optional_attributes [optional_attribute ] = (
282- _type_type [
283- schema_properties [optional_attribute ]["type" ]
284- ].__name__
285- )
275+ result_optional_attributes [optional_attribute ] = _type_type [
276+ schema_properties [optional_attribute ]["type" ]
277+ ].__name__
286278
287279 children = {}
288280
@@ -436,7 +428,7 @@ def create_object(
436428 file_configuration : dict ,
437429 processed_schema : dict ,
438430 object_name : str ,
439- dry_run = False
431+ dry_run = False ,
440432) -> object :
441433 def create_object (
442434 file_configuration : dict ,
@@ -449,7 +441,10 @@ def create_object(
449441 positional_arguments = []
450442 optional_arguments = {}
451443
452- for file_configuration_key , file_configuration_value in file_configuration .items ():
444+ for (
445+ file_configuration_key ,
446+ file_configuration_value ,
447+ ) in file_configuration .items ():
453448
454449 if isinstance (file_configuration_value , dict ):
455450
@@ -467,7 +462,9 @@ def create_object(
467462 new_processed_schema = new_processed_schema [
468463 file_configuration_key
469464 ]
470- new_path_function = new_path_function [file_configuration_key ]
465+ new_path_function = new_path_function [
466+ file_configuration_key
467+ ]
471468 else :
472469 new_processed_schema = processed_schema ["children" ][
473470 file_configuration_key
@@ -493,7 +490,9 @@ def create_object(
493490 object_ .append (
494491 create_object (
495492 element ,
496- processed_schema ["children" ][file_configuration_key ],
493+ processed_schema ["children" ][
494+ file_configuration_key
495+ ],
497496 path_function ["children" ][file_configuration_key ],
498497 original_processed_schema ,
499498 original_path_function ,
@@ -539,7 +538,10 @@ def traverse(
539538 original_processed_schema : dict ,
540539 ):
541540
542- for file_configuration_key , file_configuration_value in file_configuration .items ():
541+ for (
542+ file_configuration_key ,
543+ file_configuration_value ,
544+ ) in file_configuration .items ():
543545
544546 if file_configuration_key not in processed_schema .keys ():
545547 continue
@@ -558,10 +560,14 @@ def traverse(
558560 children = children [recursive_path ]["children" ]
559561
560562 else :
561- children = processed_schema [file_configuration_key ]["children" ]
563+ children = processed_schema [file_configuration_key ][
564+ "children"
565+ ]
562566
563567 traverse (
564- file_configuration_value , children , original_processed_schema
568+ file_configuration_value ,
569+ children ,
570+ original_processed_schema ,
565571 )
566572
567573 elif isinstance (file_configuration_value , list ):
@@ -570,13 +576,17 @@ def traverse(
570576 if isinstance (element , dict ):
571577 traverse (
572578 element ,
573- processed_schema [file_configuration_key ]["children" ],
579+ processed_schema [file_configuration_key ][
580+ "children"
581+ ],
574582 original_processed_schema ,
575583 )
576584
577585 elif isinstance (file_configuration_value , str ):
578586
579- match = _environment_variable_regex .match (file_configuration_value )
587+ match = _environment_variable_regex .match (
588+ file_configuration_value
589+ )
580590
581591 if match is not None :
582592
0 commit comments