1. PyPA
  2. Python Packaging Authority Projects
  3. distlib

Commits

Vinay Sajip  committed da04c48

Improved extras handling.

  • Participants
  • Parent commits 23ba306
  • Branches default

Comments (0)

Files changed (5)

File distlib/locators.py

View file
  • Ignore whitespace
         self.reqts = {}
 
         meta_extras = set(meta_extras or [])
+        if ':*:' in meta_extras:
+            meta_extras.remove(':*:')
+            # :meta: and :run: are implicitly included
+            meta_extras |= set([':test:', ':build:', ':dev:'])
+
         if isinstance(requirement, Distribution):
             dist = odist = requirement
             logger.debug('passed %s as requirement', odist)

File distlib/metadata.py

View file
  • Ignore whitespace
 from . import DistlibException, __version__
 from .compat import StringIO, string_types, text_type
 from .markers import interpret
-from .util import extract_by_key
+from .util import extract_by_key, get_extras
 from .version import get_scheme, PEP426_VERSION_RE
 
 logger = logging.getLogger(__name__)
             result = reqts
         else:
             result = []
-            extras = set(extras or [])
+            extras = get_extras(extras or [], self.extras)
             for d in reqts:
                 if 'extra' not in d and 'environment' not in d:
                     # unconditional

File distlib/util.py

View file
  • Ignore whitespace
     d = m.groupdict()
     return d['name'].strip().lower(), d['ver']
 
+def get_extras(requested, available):
+    result = set()
+    requested = set(requested or [])
+    available = set(available or [])
+    if '*' in requested:
+        requested.remove('*')
+        result |= available
+    for r in requested:
+        if r == '-':
+            result.add(r)
+        elif r.startswith('-'):
+            unwanted = r[1:]
+            if unwanted not in available:
+                logger.warning('undeclared extra: %s' % unwanted)
+            if unwanted in result:
+                result.remove(unwanted)
+        else:
+            if r not in available:
+                logger.warning('undeclared extra: %s' % r)
+            result.add(r)
+    return result
 #
 # Extended metadata functionality
 #

File tests/test_database.py

View file
  • Ignore whitespace
     @unittest.skip('not implemented yet')
     def test_list_installed_files(self):
         # EggInfoDistribution defines list_installed_files but there is no
-        # test for it yet; someone with setuptools expertise needs to add a
-        # file with the list of installed files for one of the egg fake dists
-        # and write the support code to populate self.records (and then delete
-        # this method)
+        # test for it yet; someone needs to add a file with the list of
+        # installed files for one of the egg fake dists and write the support
+        # code to populate self.records (and then delete this method)
         pass
 
 

File tests/test_util.py

View file
  • Ignore whitespace
                           get_cache_base, path_to_cache_dir, zip_dir,
                           parse_credentials, ensure_slash, split_filename,
                           EventMixin, Sequencer, unarchive, Progress,
-                          iglob, RICH_GLOB, parse_requirement,
+                          iglob, RICH_GLOB, parse_requirement, get_extras,
                           Configurator, read_exports, write_exports,
                           FileOperator, is_string_sequence, get_package_data)
 
         finally:
             os.remove(fn)
 
-
+    def test_get_extras(self):
+        cases = (
+            (['*'], ['i18n'], set(['i18n'])),
+            (['*', '-bar'], ['foo', 'bar'], set(['foo'])),
+        )
+        for requested, available, expected in cases:
+            actual = get_extras(requested, available)
+            self.assertEqual(actual, expected)
 if __name__ == '__main__':  # pragma: no cover
     unittest.main()