Skip to content

Commit

Permalink
build providers: use PEP-440 compliant version comparison operator (#…
Browse files Browse the repository at this point in the history
…3215)

Now that we're using PEP-440 compliant versioning, use the version
objects provided by pkg_resources for comparison.

Signed-off-by: Chris Patterson <chris.patterson@canonical.com>
  • Loading branch information
Chris Patterson committed Jul 14, 2020
1 parent 4561c43 commit 55cbcf6
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions snapcraft/internal/build_providers/_base_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

import abc
import base64
import logging
import os
import pathlib
import pkg_resources
import platform
import logging
import shlex
import shutil
import sys
Expand Down Expand Up @@ -254,14 +255,6 @@ def launch_instance(self) -> None:
# what is on the host
self._setup_snapcraft()

def _is_compatible_version(self, built_by: str) -> bool:
"""Return True if running version is >= built-by version."""

# We use a bit a of naive string check here. Re-using Python
# versioning comparisons cannot be used because we don't follow
# their spec. Apt version comparison would require running on Linux.
return snapcraft._get_version() >= built_by

def _ensure_compatible_build_environment(self) -> None:
"""Force clean of build-environment if project is not compatible."""

Expand All @@ -285,7 +278,9 @@ def _ensure_compatible_build_environment(self) -> None:
f"Build environment was created with unknown snapcraft version {built_by!r}, cleaning."
)
self.clean_project()
elif not self._is_compatible_version(built_by):
elif pkg_resources.parse_version(
snapcraft._get_version()
) < pkg_resources.parse_version(built_by):
self.echoer.warning(
f"Build environment was created with newer snapcraft version {built_by!r}, cleaning."
)
Expand Down

0 comments on commit 55cbcf6

Please sign in to comment.