summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-02-26 12:48:11 -0500
committerJason R. Coombs <jaraco@jaraco.com>2022-02-26 12:48:11 -0500
commitbbe8b50eccb5700c44bf793346dd09540bff97ee (patch)
tree5cff1c06b77f9f3535eec33c55f2d19b40f17128 /setuptools
parentc44e416b44e5e7126f435a7c0b9adc9b88b85cbd (diff)
downloadpython-setuptools-git-bbe8b50eccb5700c44bf793346dd09540bff97ee.tar.gz
Extract method to validate optimize parameter.
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/command/easy_install.py26
1 files changed, 17 insertions, 9 deletions
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.