Update chip data chip-config option to work with distutil

Signed-off-by: Caleb Palmer <cnpalmer@us.ibm.com>
Change-Id: Iea68e7b89c96505e993b77951eac630ae6f81ef0
diff --git a/chip_data/setup.py b/chip_data/setup.py
index 4fa62a7..c6cbec1 100644
--- a/chip_data/setup.py
+++ b/chip_data/setup.py
@@ -1,4 +1,5 @@
 import os
+import sys
 
 from parse_chip_data import gen_peltool_json
 from setuptools import setup
@@ -24,22 +25,24 @@
 # Windows. Setuptools will automatically convert the slashes where appropriate.
 package_data_glob = "/".join(data_dir_components)
 
+# These are the possible chip config options to build the PEL parser data json
+# from. By default all configs will be built. The '--chip-config' option can be
+# used in recipes to specify manually.
+chipConfig = ["p10_10", "p10_20", "explorer", "odyssey"]
+
+# The chip-config option is manually handled here, rather than added as a custom
+# option in the my_build_py class to facilitate use with setuptools which will
+# use bdist_wheel in the build. There is currently not a way to indicate a
+# option only for the custom build_py through bdist_wheel. As such the option
+# will be handled generically here with the chipConfig variable only used in the
+# custom build class.
+if "--chip-config" in sys.argv:
+    chipConfig = sys.argv.pop(sys.argv.index("--chip-config") + 1).split(",")
+    sys.argv.remove("--chip-config")
+
 
 # This is a custom build class that is used to dynamically build the data files.
 class my_build_py(build_py):
-    user_options = build_py.user_options + [
-        ("chipConfig=", None, "List of chip IDs to build PEL parser JSON")
-    ]
-
-    def initialize_options(self):
-        # Default chip_config option is all valid chip types
-        self.chipConfig = ["p10_10", "p10_20", "explorer", "odyssey"]
-        return super().initialize_options()
-
-    def finalize_options(self):
-        if not isinstance(self.chipConfig, list):
-            self.chipConfig = self.chipConfig.split(",")
-        return super().finalize_options()
 
     def run(self):
         if not self.dry_run:  # honor --dry-run flag
@@ -50,7 +53,7 @@
             self.mkpath(data_dir)
 
             # Generate the PEL parser data JSON from the Chip Data XML.
-            for chip in self.chipConfig:
+            for chip in chipConfig:
                 gen_peltool_json(chip, data_dir)
 
         # Call the superclass run() to ensure everything else builds.