cleanup version_handling.py
@@ -14,81 +14,6 @@ from readthedocs.builds.constants import (
LATEST_VERBOSE_NAME, STABLE_VERBOSE_NAME, TAG)
-def get_major(version):
- """
- Return the major version.
-
- :param version: version to get the major
- :type version: packaging.version.Version
- """
- # pylint: disable=protected-access
- return version._version.release[0]
-
-
-def get_minor(version):
- """
- Return the minor version.
-
- :param version: version to get the minor
- :type version: packaging.version.Version
- """
- # pylint: disable=protected-access
- try:
- return version._version.release[1]
- except IndexError:
- return 0
-
-
-class VersionManager(object):
-
- """Prune list of versions based on version windows."""
-
- def __init__(self):
- self._state = defaultdict(lambda: defaultdict(list))
-
- def add(self, version):
- self._state[get_major(version)][get_minor(version)].append(version)
-
- def prune_major(self, num_latest):
- all_keys = sorted(set(self._state.keys()))
- major_keep = []
- for __ in range(num_latest):
- if all_keys:
- major_keep.append(all_keys.pop(-1))
- for to_remove in all_keys:
- del self._state[to_remove]
-
- def prune_minor(self, num_latest):
- for major, minors in list(self._state.items()):
- all_keys = sorted(set(minors.keys()))
- minor_keep = []
- for __ in range(num_latest):
- if all_keys:
- minor_keep.append(all_keys.pop(-1))
- for to_remove in all_keys:
- del self._state[major][to_remove]
-
- def prune_point(self, num_latest):
- for major, minors in list(self._state.items()):
- for minor in list(minors.keys()):
- try:
- self._state[major][minor] = sorted(
- set(self._state[major][minor]))[-num_latest:]
- except TypeError: # pylint: disable=try-except-raise
- # Raise these for now.
- raise
-
- def get_version_list(self):
- versions = []
- for major_val in list(self._state.values()):
- for version_list in list(major_val.values()):
- versions.extend(version_list)
- versions = sorted(versions)
- return [
- version.public for version in versions if not version.is_prerelease
- ]
-
-
def parse_version_failsafe(version_string):
"""
Parse a version in string form and return Version object.
