First pass at upgrading to EAPI 3.
[g-pypi.git] / g_pypi / ebuild.py
index 151d9845aacb3b735df09f556aed2931f2aee430..b33f8f35fa163c71995d167133b97f9ec03fd047 100755 (executable)
@@ -77,7 +77,9 @@ class Ebuild:
 
         #Variables that will be passed to the Cheetah template
         self.vars = {
-                'need_python': '',
+                'python_depend': '*',
+                'restrict_python_abis': '',
+                'supported_python_versions': '',
                 'python_modname': '',
                 'description': '',
                 'homepage': '',
@@ -188,6 +190,38 @@ class Ebuild:
 
         self.vars['license'] = "%s" % my_license
 
+        self.get_python_depend()
+
+    def get_python_depend(self):
+        """Generate PYTHON_DEPEND and RESTRICT_PYTHON_ABIS strings
+        """
+        possible_versions = [(2, i) for i in range(2, 8)]
+        possible_versions.extend([(3, i) for i in range(3)])
+
+        allowed_versions = []
+        allowed_version_strings = []
+        start = 'Programming Language :: Python ::'
+        for data in self.metadata.get('classifiers', []):
+            if data.startswith(start):
+                version = data[len(start):].strip()
+                allowed_version_strings.append(version)
+                allowed_versions.append(
+                    [int(x) for x in version.split('.')])
+
+        # TODO: also use PEP 345's Requires-Python
+
+        self.logger.info('supported Python versions: %s' %
+                         ', '.join(sorted(allowed_version_strings)))
+        major_versions = set([v[0] for v in allowed_versions])
+        v3 = 3 in major_versions
+        v2 = 2 in major_versions 
+        # HACK!  need an algorithm for determining these
+        self.vars['python_depend'] = '*:2.6'
+        self.vars['restrict_python_abis'] = '3.*'
+        self.vars['supported_python_versions'] = ', '.join(
+            sorted(allowed_version_strings))
+
     def add_warning(self, warning):
         """Add warning to be shown after ebuild is created"""
         if warning not in self.warnings: