[Distutils] Draft PEP for JSON based metadata published

Nick Coghlan ncoghlan at gmail.com
Wed May 29 16:50:53 CEST 2013

On Thu, May 30, 2013 at 12:32 AM, Daniel Holth <dholth at gmail.com> wrote:
> On Wed, May 29, 2013 at 10:25 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> On Thu, May 30, 2013 at 12:14 AM, Daniel Holth <dholth at gmail.com> wrote:
>>> Request the test extra to also install
>>> test_requires
>>> test_may_require
>>> "
>>> If test requirements are not actually extras then I would prefer
>>> having no special-cased extra names at all, or a special extra-like
>>> syntax used for pip-install'ing different categories of dependencies.
>> No, I still like the idea of using the existing extras syntax to
>> request their installation when you do want them, rather than needing
>> a special mechanism in the command line tools.
>> The declaration just got broken out to a separate field as otherwise
>> it wasn't clear whether test dependencies should be listed in
>> may_require, dev_requires or dev_may_require.
> I just mean something like pip install package[:test:], using any
> character that is not allowed in extra names to avoid a collision.

Hmm, I'll have to think about that one. It doesn't cause any data
modelling issues any more (since the dedicated fields have been broken
out to store the test dependencies), and you're right, lifting the
"any name except test" restriction on the extras field itself would be

>>> Is there a function to get the metadata keys from the category name?
>>> It would be something like:
>>> f('test') -> 'test_requires', 'test_may_require'
>>> def f(category):
>>> if category == 'install': category = ''
>>> conditional = [category, 'may_require']
>>> unconditional = [category, '_requires']
>>> return ('_'.join(unconditional).strip('_'), '_'.join(conditional).strip('_'))
>> Possibly, but API details aren't a question for this PEP. If you look
>> at the deployment scenarios in the PEP, that's not actually the way
>> the mapping works anyway (development mode gets everything, not just
>> the dev dependencies).
> I think the naming of the two keys is slightly inelegant, with the
> 'may' in the middle and the requires / require, but there aren't any
> short english words that would look good simply appended to the end
> 'test_requires', 'test_requires_conditional'.

Yeah, I picked the syntax I did for readability. I've seen similar
APIs along the lines of "requires" and "requires_maybe" and they're
ugly. In terms of how you deal with it programmatically, you would
likely want to have your mandatory and conditional handling separated
out anyway, so iterators are a natural fit:

    def iter_dependencies(metadata, field, prefixes):
        for prefix in prefixes:
           if prefix:
               field_name = prefix + "_" + field
               field_name = field
           data = metadata.get(field_name)
           if data is None:
           yield from data

    def iter_requires(metadata, prefixes):
        yield from iter_dependencies(metadata, "requires", prefixes)

    def iter_may_require(metadata, prefixes):
        yield from iter_dependencies(metadata, "may_require", prefixes)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Distutils-SIG mailing list