Skip to content

Commit

Permalink
mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Feb 20, 2024
1 parent ba8fb09 commit fd3be67
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
3 changes: 1 addition & 2 deletions semantic-conventions/dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ mypy==0.910
pytest==8.0.1
flake8==7.0.0
pylint==3.0.3
isort==5.13.2
requests==2.31.0
isort==5.13.2
4 changes: 4 additions & 0 deletions semantic-conventions/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ ignore_missing_imports = True

[mypy-mistune.*]
ignore_missing_imports = True

[mypy-requests.*]
ignore_missing_imports = True

1 change: 1 addition & 0 deletions semantic-conventions/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ install_requires =
ruamel.yaml~=0.16
Jinja2~=3.0
mistune==2.0.0a6
requests==2.31.0

[options.packages.find]
where = src
Expand Down
14 changes: 8 additions & 6 deletions semantic-conventions/src/opentelemetry/semconv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ def check_compatibility(semconv, args, parser):


def find_yaml(yaml_root: str, exclude: str) -> List[str]:

if yaml_root is not None:
exclude = set(exclude_file_list(yaml_root if yaml_root else "", exclude))
excluded_files = set(exclude_file_list(yaml_root if yaml_root else "", exclude))
yaml_files = set(glob.glob(f"{yaml_root}/**/*.yaml", recursive=True)).union(
set(glob.glob(f"{yaml_root}/**/*.yml", recursive=True))
)
return yaml_files - exclude
return yaml_files - excluded_files

return []


def check_args(arguments, parser):
Expand All @@ -137,7 +138,7 @@ def check_args(arguments, parser):

def parse_only_filter(only: str, parser) -> List[str]:
if not only:
return None
return []

types = [t.strip() for t in only.split(",")]
unknown_types = [t for t in types if t not in CONVENTION_CLS_BY_GROUP_TYPE.keys()]
Expand Down Expand Up @@ -321,8 +322,9 @@ def download_previous_version(version: str) -> str:
f"https://github.com/open-telemetry/semantic-conventions/archive/{filename}"
)

request = requests.get(semconv_vprev, allow_redirects=True)
open(path_to_zip, "wb").write(request.content)
request = requests.get(semconv_vprev, allow_redirects=True, timeout=30)
with open(path_to_zip, "wb") as zip_file:
zip_file.write(request.content)

with zipfile.ZipFile(path_to_zip, "r") as zip_ref:
zip_ref.extractall(path_to_semconv)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from opentelemetry.semconv.model.semantic_attribute import (
EnumAttributeType,
EnumMember,
RequirementLevel,
SemanticAttribute,
Expand All @@ -20,15 +21,16 @@ def __init__(self, signal: str, name: str, message: str, critical: bool = True):
self.signal = signal
self.name = name
self.message = message
self.critical = critical

def __str__(self):
return f"\t {self.signal} '{self.name}': {self.message}"

def __eq__(self, other):
if isinstance(other, self.__class__):
return self.__dict__ == other.__dict__
else:
return False

return False

def __ne__(self, other):
return not self.__eq__(other)
Expand All @@ -46,7 +48,7 @@ def __init__(
self.previous_semconv = previous_semconv

def check(self) -> list[Problem]:
problems = []
problems = [] # type: list[Problem]
for semconv in self.previous_semconv.models.values():
for prev_attr in semconv.attributes_and_templates:
if (
Expand All @@ -59,7 +61,7 @@ def check(self) -> list[Problem]:
self._check_metric(semconv, problems)
return problems

def _check_attribute(self, prev: SemanticAttribute, problems: list[str]):
def _check_attribute(self, prev: SemanticAttribute, problems: list[Problem]):
cur = self.current_semconv._lookup_attribute(prev.fqn)
if cur is None:
problems.append(Problem("attribute", prev.fqn, "was removed"))
Expand All @@ -75,8 +77,8 @@ def _check_attribute(self, prev: SemanticAttribute, problems: list[str]):
)
)

if prev.is_enum:
if not cur.is_enum:
if isinstance(prev.attr_type, EnumAttributeType):
if not isinstance(cur.attr_type, EnumAttributeType):
problems.append(
Problem(
"attribute",
Expand Down Expand Up @@ -107,7 +109,11 @@ def _check_attribute(self, prev: SemanticAttribute, problems: list[str]):
)

def _check_member(
self, fqn: str, prev: EnumMember, members: list[EnumMember], problems: list[str]
self,
fqn: str,
prev: EnumMember,
members: list[EnumMember],
problems: list[Problem],
):
for member in members:
if prev.value == member.value:
Expand All @@ -119,7 +125,7 @@ def _check_member(
)
)

def _check_metric(self, prev: MetricSemanticConvention, problems: list[str]):
def _check_metric(self, prev: MetricSemanticConvention, problems: list[Problem]):
for cur in self.current_semconv.models.values():
if (
isinstance(cur, MetricSemanticConvention)
Expand Down Expand Up @@ -159,7 +165,7 @@ def _check_metric_attributes(
self,
prev: MetricSemanticConvention,
cur: MetricSemanticConvention,
problems: list[str],
problems: list[Problem],
):
if prev.stability == StabilityLevel.STABLE:
prev_default_attributes = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def testMetricAttributeAdded(self):
"metric",
"metric_one",
"attributes changed from '['first.first_attr']' to '['first.first_attr', 'first.second_attr']'",
critical=False,
)
]
self.assert_errors(expected_errors, problems)
Expand Down

0 comments on commit fd3be67

Please sign in to comment.