[tor-commits] [stem/master] Drop complex version requirement class

atagar at torproject.org atagar at torproject.org
Wed Feb 26 23:02:10 UTC 2020


commit 156c408fe033f30bf4c1a66bbb3f9bfade0b7b12
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Feb 18 17:36:47 2020 -0800

    Drop complex version requirement class
    
    Removing a private class that supported version rule chains (for example,
    "check if I'm greater than 1.2.2 in the 1.2 series, or 1.3.5 in the 1.3
    series"). This was only used for a single requirement check which has now
    been removed.
    
    We can always revive this class in the future if it's useful.
---
 stem/version.py      | 77 +--------------------------------------------------
 test/unit/version.py | 78 ----------------------------------------------------
 2 files changed, 1 insertion(+), 154 deletions(-)

diff --git a/stem/version.py b/stem/version.py
index 5369f1ad..181aec8a 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -206,90 +206,15 @@ class Version(object):
 
   def __gt__(self, other):
     """
-    Checks if this version meets the requirements for a given feature. We can
-    be compared to either a :class:`~stem.version.Version` or
-    :class:`~stem.version._VersionRequirements`.
+    Checks if this version meets the requirements for a given feature.
     """
 
-    if isinstance(other, _VersionRequirements):
-      for rule in other.rules:
-        if rule(self):
-          return True
-
-      return False
-
     return self._compare(other, lambda s, o: s > o)
 
   def __ge__(self, other):
-    if isinstance(other, _VersionRequirements):
-      for rule in other.rules:
-        if rule(self):
-          return True
-
-      return False
-
     return self._compare(other, lambda s, o: s >= o)
 
 
-class _VersionRequirements(object):
-  """
-  Series of version constraints that can be compared to. For instance, this
-  allows for comparisons like 'if I'm greater than version X in the 0.2.2
-  series, or greater than version Y in the 0.2.3 series'.
-
-  This is a logical 'or' of the series of rules.
-  """
-
-  def __init__(self):
-    self.rules = []
-
-  def greater_than(self, version, inclusive = True):
-    """
-    Adds a constraint that we're greater than the given version.
-
-    :param stem.version.Version version: version we're checking against
-    :param bool inclusive: if comparison is inclusive or not
-    """
-
-    if inclusive:
-      self.rules.append(lambda v: version <= v)
-    else:
-      self.rules.append(lambda v: version < v)
-
-  def less_than(self, version, inclusive = True):
-    """
-    Adds a constraint that we're less than the given version.
-
-    :param stem.version.Version version: version we're checking against
-    :param bool inclusive: if comparison is inclusive or not
-    """
-
-    if inclusive:
-      self.rules.append(lambda v: version >= v)
-    else:
-      self.rules.append(lambda v: version > v)
-
-  def in_range(self, from_version, to_version, from_inclusive = True, to_inclusive = False):
-    """
-    Adds constraint that we're within the range from one version to another.
-
-    :param stem.version.Version from_version: beginning of the comparison range
-    :param stem.version.Version to_version: end of the comparison range
-    :param bool from_inclusive: if comparison is inclusive with the starting version
-    :param bool to_inclusive: if comparison is inclusive with the ending version
-    """
-
-    def new_rule(v):
-      if from_inclusive and to_inclusive:
-        return from_version <= v <= to_version
-      elif from_inclusive:
-        return from_version <= v < to_version
-      else:
-        return from_version < v < to_version
-
-    self.rules.append(new_rule)
-
-
 Requirement = stem.util.enum.Enum(
   ('DORMANT_MODE', Version('0.4.0.1-alpha')),
   ('HSFETCH_V3', Version('0.4.1.1-alpha')),
diff --git a/test/unit/version.py b/test/unit/version.py
index abdb65c0..33439cf8 100644
--- a/test/unit/version.py
+++ b/test/unit/version.py
@@ -177,84 +177,6 @@ class TestVersion(unittest.TestCase):
     self.assert_string_matches('0.1.2.3')
     self.assert_string_matches('0.1.2')
 
-  def test_requirements_greater_than(self):
-    """
-    Checks a VersionRequirements with a single greater_than rule.
-    """
-
-    requirements = stem.version._VersionRequirements()
-    requirements.greater_than(Version('0.2.2.36'))
-
-    self.assertTrue(Version('0.2.2.36') >= requirements)
-    self.assertTrue(Version('0.2.2.37') >= requirements)
-    self.assertTrue(Version('0.2.3.36') >= requirements)
-    self.assertFalse(Version('0.2.2.35') >= requirements)
-    self.assertFalse(Version('0.2.1.38') >= requirements)
-
-    requirements = stem.version._VersionRequirements()
-    requirements.greater_than(Version('0.2.2.36'), False)
-
-    self.assertFalse(Version('0.2.2.35') >= requirements)
-    self.assertFalse(Version('0.2.2.36') >= requirements)
-    self.assertTrue(Version('0.2.2.37') >= requirements)
-
-  def test_requirements_less_than(self):
-    """
-    Checks a VersionRequirements with a single less_than rule.
-    """
-
-    requirements = stem.version._VersionRequirements()
-    requirements.less_than(Version('0.2.2.36'))
-
-    self.assertTrue(Version('0.2.2.36') >= requirements)
-    self.assertTrue(Version('0.2.2.35') >= requirements)
-    self.assertTrue(Version('0.2.1.38') >= requirements)
-    self.assertFalse(Version('0.2.2.37') >= requirements)
-    self.assertFalse(Version('0.2.3.36') >= requirements)
-
-    requirements = stem.version._VersionRequirements()
-    requirements.less_than(Version('0.2.2.36'), False)
-
-    self.assertFalse(Version('0.2.2.37') >= requirements)
-    self.assertFalse(Version('0.2.2.36') >= requirements)
-    self.assertTrue(Version('0.2.2.35') >= requirements)
-
-  def test_requirements_in_range(self):
-    """
-    Checks a VersionRequirements with a single in_range rule.
-    """
-
-    requirements = stem.version._VersionRequirements()
-    requirements.in_range(Version('0.2.2.36'), Version('0.2.2.38'))
-
-    self.assertFalse(Version('0.2.2.35') >= requirements)
-    self.assertTrue(Version('0.2.2.36') >= requirements)
-    self.assertTrue(Version('0.2.2.37') >= requirements)
-    self.assertFalse(Version('0.2.2.38') >= requirements)
-
-    # rule for 'anything in the 0.2.2.x series'
-    requirements = stem.version._VersionRequirements()
-    requirements.in_range(Version('0.2.2.0'), Version('0.2.3.0'))
-
-    for index in range(0, 100):
-      self.assertTrue(Version('0.2.2.%i' % index) >= requirements)
-
-  def test_requirements_multiple_rules(self):
-    """
-    Checks a VersionRequirements is the logical 'or' when it has multiple rules.
-    """
-
-    # rule to say 'anything but the 0.2.2.x series'
-    requirements = stem.version._VersionRequirements()
-    requirements.greater_than(Version('0.2.3.0'))
-    requirements.less_than(Version('0.2.2.0'), False)
-
-    self.assertTrue(Version('0.2.3.0') >= requirements)
-    self.assertFalse(Version('0.2.2.0') >= requirements)
-
-    for index in range(0, 100):
-      self.assertFalse(Version('0.2.2.%i' % index) >= requirements)
-
   def assert_versions_match(self, version, major, minor, micro, patch, status, extra):
     """
     Asserts that the values for a types.Version instance match the given



More information about the tor-commits mailing list