From 1aad1bee489473b8a3b8b51b505a200ef5b9e756 Mon Sep 17 00:00:00 2001 From: Sasha Romijn Date: Fri, 29 May 2020 12:14:51 +0000 Subject: [PATCH] Add Python 2 compatibility for schedule builder with functools32 - Legacy-Id: 17895 --- .../management/commands/schedule_generator.py | 13 ++++++++----- requirements.txt | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ietf/meeting/management/commands/schedule_generator.py b/ietf/meeting/management/commands/schedule_generator.py index 52bbf19e6..e76612a10 100644 --- a/ietf/meeting/management/commands/schedule_generator.py +++ b/ietf/meeting/management/commands/schedule_generator.py @@ -6,9 +6,13 @@ import datetime import math import random import string -import functools from collections import defaultdict +try: + from functools import lru_cache +except ImportError: + from functools32 import lru_cache + from django.core.management.base import BaseCommand, CommandError from django.db.models import Q @@ -583,7 +587,7 @@ class Session(object): self.last_cost = cost return violations, cost - @functools.lru_cache(maxsize=10000) + @lru_cache(maxsize=10000) def _calculate_cost_overlapping_groups(self, overlapping_sessions): violations, cost = [], 0 for other in overlapping_sessions: @@ -603,7 +607,7 @@ class Session(object): cost += len(conflict_people) * self.conflict_people_penalty return violations, cost - @functools.lru_cache(maxsize=10000) + @lru_cache(maxsize=10000) def _calculate_cost_business_logic(self, overlapping_sessions): violations, cost = [], 0 for other in overlapping_sessions: @@ -645,8 +649,7 @@ class Session(object): cost += self.business_constraint_costs['session_overlap_ad'] return violations, cost - # TODO: Python 2 compatibility - @functools.lru_cache(maxsize=10000) + @lru_cache(maxsize=10000) def _calculate_cost_my_other_sessions(self, my_sessions): violations, cost = [], 0 my_sessions = list(my_sessions) diff --git a/requirements.txt b/requirements.txt index 336e60196..aadc204bd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -70,4 +70,4 @@ Unidecode>=0.4.18 xml2rfc>=2.35.0 xym>=0.4.4,!=0.4.7,<1.0 #zxcvbn-python>=4.4.14 # Not needed until we do back-end password entropy validation - +functools32==3.2.3-2; python_version < '3' \ No newline at end of file