Skip to content

Commit

Permalink
Fix deprecation warnings with semver (#12967)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentClarret authored and steveny91 committed Oct 27, 2022
1 parent 62fc707 commit b322c90
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import time
from typing import Any, Dict, Generator, Tuple

import semver
from requests.exceptions import HTTPError, RequestException
from semver import VersionInfo
from six.moves.urllib_parse import urlparse

from datadog_checks.base import AgentCheck
Expand Down Expand Up @@ -94,7 +94,7 @@ def discover_api(self):
raise CheckException("Unable to collect API version and/or UAA URL from links {}".format(links))

api_version = "v2"
if semver.parse_version_info(api_v3_version) >= MIN_V3_VERSION:
if VersionInfo.parse(api_v3_version) >= MIN_V3_VERSION:
api_version = "v3"
self.log.info("Discovered API `%s` and UAA URL `%s`", api_version, uaa_url)
return api_version, uaa_url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under a 3-clause BSD style license (see LICENSE)
import os

from semver import parse_version_info
from semver import VersionInfo

from ...constants import get_agent_release_requirements
from ...git import git_show_file, git_tag_list
Expand All @@ -16,15 +16,15 @@ def get_agent_tags(since, to):
Return a list of tags from integrations-core representing an Agent release,
sorted by more recent first.
"""
agent_tags = sorted(parse_version_info(t) for t in git_tag_list(r'^\d+\.\d+\.\d+$'))
agent_tags = sorted(VersionInfo.parse(t) for t in git_tag_list(r'^\d+\.\d+\.\d+$'))

# default value for `to` is the latest tag
if to:
to = parse_version_info(to)
to = VersionInfo.parse(to)
else:
to = agent_tags[-1]

since = parse_version_info(since)
since = VersionInfo.parse(since)

# filter out versions according to the interval [since, to]
agent_tags = [t for t in agent_tags if since <= t <= to]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from io import StringIO

import click
from semver import parse_version_info
from semver import VersionInfo

from ....fs import stream_file_lines, write_file
from ...constants import CHANGELOG_TYPE_NONE, CHANGELOG_TYPES_ORDERED, get_root
Expand Down Expand Up @@ -64,7 +64,7 @@ def changelog(
'following SemVer and matches the provided tag_prefix and/or tag_pattern.'
)

if not no_semver and parse_version_info(version.replace(tag_prefix, '', 1)) <= parse_version_info(
if not no_semver and VersionInfo.parse(version.replace(tag_prefix, '', 1)) <= VersionInfo.parse(
cur_version.replace(tag_prefix, '', 1)
):
abort(f'Current version is {cur_version}, cannot bump to {version}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from contextlib import suppress

import click
from semver import finalize_version, parse_version_info
from semver import VersionInfo, finalize_version

from ...constants import BETA_PACKAGES, NOT_CHECKS, VERSION_BUMP, get_agent_release_requirements
from ...git import get_current_branch, git_commit
Expand Down Expand Up @@ -110,8 +110,8 @@ def make(ctx, checks, version, end, initial_release, skip_sign, sign_only, exclu
version = VERSION_BUMP[method](prev_version)
prev_version = version

p_version = parse_version_info(version)
p_current = parse_version_info(cur_version)
p_version = VersionInfo.parse(version)
p_current = VersionInfo.parse(cur_version)
if p_version <= p_current:
if initial_release:
continue
Expand Down
4 changes: 2 additions & 2 deletions datadog_checks_dev/datadog_checks/dev/tooling/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import re

from semver import parse_version_info
from semver import VersionInfo

from ..fs import chdir
from ..subprocess import run_command
Expand Down Expand Up @@ -171,7 +171,7 @@ def get_latest_tag(pattern=None, tag_prefix='v'):
"""
if not pattern:
pattern = rf'^({tag_prefix})?\d+\.\d+\.\d+.*'
all_tags = sorted((parse_version_info(t.replace(tag_prefix, '', 1)), t) for t in git_tag_list(pattern))
all_tags = sorted((VersionInfo.parse(t.replace(tag_prefix, '', 1)), t) for t in git_tag_list(pattern))
if not all_tags:
return
else:
Expand Down
19 changes: 9 additions & 10 deletions postgres/datadog_checks/postgres/version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
# Licensed under Simplified BSD License (see LICENSE)
import re

import semver
from semver import VersionInfo

from datadog_checks.base.log import get_check_logger

V8_3 = VersionInfo(**semver.parse("8.3.0"))
V9 = VersionInfo(**semver.parse("9.0.0"))
V9_1 = VersionInfo(**semver.parse("9.1.0"))
V9_2 = VersionInfo(**semver.parse("9.2.0"))
V9_4 = VersionInfo(**semver.parse("9.4.0"))
V9_6 = VersionInfo(**semver.parse("9.6.0"))
V10 = VersionInfo(**semver.parse("10.0.0"))
V8_3 = VersionInfo.parse("8.3.0")
V9 = VersionInfo.parse("9.0.0")
V9_1 = VersionInfo.parse("9.1.0")
V9_2 = VersionInfo.parse("9.2.0")
V9_4 = VersionInfo.parse("9.4.0")
V9_6 = VersionInfo.parse("9.6.0")
V10 = VersionInfo.parse("10.0.0")


class VersionUtils(object):
Expand Down Expand Up @@ -43,7 +42,7 @@ def is_aurora(self, db):
def parse_version(raw_version):
try:
# Only works for MAJOR.MINOR.PATCH(-PRE_RELEASE)
return semver.parse_version_info(raw_version)
return VersionInfo.parse(raw_version)
except ValueError:
pass
try:
Expand All @@ -58,7 +57,7 @@ def parse_version(raw_version):
match = re.match(r'(\d+)([a-zA-Z]+)(\d+)', raw_version)
if match:
version = list(match.groups())
return semver.parse_version_info('{}.0.0-{}.{}'.format(*version))
return VersionInfo.parse('{}.0.0-{}.{}'.format(*version))
raise Exception("Cannot determine which version is {}".format(raw_version))

@staticmethod
Expand Down

0 comments on commit b322c90

Please sign in to comment.