Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Mar 9, 2023
1 parent df4e77e commit 018e874
Showing 4 changed files with 20 additions and 10 deletions.
19 changes: 15 additions & 4 deletions semantic-conventions/src/opentelemetry/semconv/main.py
Original file line number Diff line number Diff line change
@@ -37,7 +37,11 @@ def parse_semconv(args, parser) -> SemanticConventionSet:
semconv.parse(file)

if args.reference_only is not None:
reference_files = [f for f in glob_file_list(args.yaml_root, args.reference_only) if is_yaml_file(f)]
reference_files = [
f
for f in glob_file_list(args.yaml_root, args.reference_only)
if is_yaml_file(f)
]
for file in sorted(reference_files):
semconv.parse(file, True)

@@ -46,9 +50,11 @@ def parse_semconv(args, parser) -> SemanticConventionSet:
sys.exit(1)
return semconv


def is_yaml_file(file: str) -> bool:
return file.endswith(".yaml") or file.endswith(".yml")


def glob_file_list(folder: str, pattern: str) -> List[str]:
if not pattern:
return []
@@ -105,9 +111,11 @@ def find_yaml(args):
glob_file_list(args.yaml_root if args.yaml_root else "", args.exclude)
)
reference_only = set(
glob_file_list(args.yaml_root if args.yaml_root else "", args.reference_only)
glob_file_list(
args.yaml_root if args.yaml_root else "", args.reference_only
)
)
exclude.update(reference_only)
exclude.update(reference_only)

yaml_files = set(
glob.glob(f"{args.yaml_root}/**/*.yaml", recursive=True)
@@ -237,7 +245,10 @@ def setup_parser():
"--exclude", "-e", help="Exclude the matching files using GLOB syntax", type=str
)
parser.add_argument(
"--reference-only", "-r", help="Additional files to resolve references only (and extends) using GLOB syntax", type=str
"--reference-only",
"-r",
help="Additional files to resolve references only (and extends) using GLOB syntax",
type=str,
)
parser.add_argument(
"files",
Original file line number Diff line number Diff line change
@@ -300,7 +300,9 @@ class SemanticConventionSet:

debug: bool
models: typing.Dict[str, BaseSemanticConvention] = field(default_factory=dict)
extended_models: typing.Dict[str, BaseSemanticConvention] = field(default_factory=dict)
extended_models: typing.Dict[str, BaseSemanticConvention] = field(
default_factory=dict
)
errors: bool = False

def parse(self, file, ref_only=False):
Original file line number Diff line number Diff line change
@@ -244,7 +244,6 @@ def render(
template.stream(data).dump(output_name)
else:
data = self.get_data_single_file(semconvset, template_path)
print (data)
template = env.get_template(file_name, globals=data)
template.globals["now"] = datetime.datetime.utcnow()
template.globals["version"] = os.environ.get("ARTIFACT_VERSION", "dev")
Original file line number Diff line number Diff line change
@@ -735,7 +735,7 @@ def test_reference_only_ref(self):
semconv.finish()

self.assertEqual(len(semconv.models), 3)

def test_reference_only_extends(self):
semconv = SemanticConventionSet(debug=False)
semconv.parse(self.load_file("yaml/extends/child.http.yaml"))
@@ -750,9 +750,7 @@ def test_reference_only_extends(self):
"prefix": "child.http",
"extends": "http.server",
"n_constraints": 1,
"attributes": [
"http.server_name",
],
"attributes": ["http.server_name"],
}
self.semantic_convention_check(list(semconv.models.values())[0], expected)

0 comments on commit 018e874

Please sign in to comment.