Exemplo n.º 1
0
def parse_command_line(dist, *args, **kwargs):  # noqa: E302 (keep override close to function it replaces)
    """ distutils.dist.Distribution.parse_command_line replacement

    This allows us to insert setupmeta's imputed values for various attributes
    after all configuration has interpreted and read from config files, and just
    before any commands are run. We then call `parse_command_line` to continue
    normal execution.
    """
    dist._setupmeta.finalize(dist)
    MetaDefs.fill_dist(dist, dist._setupmeta.to_dict())

    return parse_command_line_orig(dist, *args, **kwargs)
Exemplo n.º 2
0
def distutils_hook(dist, *args, **kwargs):
    """ distutils.dist.Distribution.parse_command_line replacement

    distutils calls this right after having processed 'setup_requires'
    It really calls self.parse_command_line(command), we jump in
    so we can decorate the 'dist' object appropriately for our own commands
    """
    if dist.script_args and not hasattr(dist, "_setupmeta"):
        # Add our ._setupmeta object (distutils calls this several times, we need only one)
        dist._setupmeta = SetupMeta(dist)
        MetaDefs.fill_dist(dist, dist._setupmeta.to_dict())
    return dd_original(dist, *args, **kwargs)
Exemplo n.º 3
0
def finalize_dist(dist, setup_requires=None):
    """
    Hook into setuptools' Distribution class before attributes are interpreted.

    This is called before Distribution attributes are finalized and validated,
    allowing us to transform attribute values before they have to conform to
    the usual spec. This step is *before* configuration is additionally read
    from config files.
    """
    setup_requires = setup_requires or dist.setup_requires
    setup_requires = setup_requires if isinstance(setup_requires, list) else [setup_requires]

    if any(dep.startswith('setupmeta') for dep in setup_requires):
        dist._setupmeta = SetupMeta().preprocess(dist)
        MetaDefs.fill_dist(dist, dist._setupmeta.to_dict(only_meaningful=False))

        # Override parse_command_line for this instance only.
        dist.parse_command_line = functools.partial(parse_command_line, dist)