From bbe8b50eccb5700c44bf793346dd09540bff97ee Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 26 Feb 2022 12:48:11 -0500 Subject: Extract method to validate optimize parameter. --- setuptools/command/easy_install.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 07b45e59..abf25eb9 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -355,15 +355,7 @@ class easy_install(Command): if not self.no_find_links: self.package_index.add_find_links(self.find_links) self.set_undefined_options('install_lib', ('optimize', 'optimize')) - if not isinstance(self.optimize, int): - try: - self.optimize = int(self.optimize) - if self.optimize not in range(3): - raise ValueError - except ValueError as e: - raise DistutilsOptionError( - "--optimize must be 0, 1, or 2" - ) from e + self.optimize = self._validate_optimize(self.optimize) if self.editable and not self.build_directory: raise DistutilsArgError( @@ -375,6 +367,22 @@ class easy_install(Command): self.outputs = [] + @staticmethod + def _validate_optimize(value): + if isinstance(value, int): + return value + + try: + value = int(value) + if value not in range(3): + raise ValueError + except ValueError as e: + raise DistutilsOptionError( + "--optimize must be 0, 1, or 2" + ) from e + + return value + def _fix_install_dir_for_user_site(self): """ Fix the install_dir if "--user" was used. -- cgit v1.2.1