コード例 #1
0
def test_setup_py_determination():
    initial = sys.argv[0]
    sys.argv[0] = "foo/setup.py"
    meta = SetupMeta(dict(_setup_py_path=None))
    assert not meta.definitions
    assert not meta.version
    sys.argv[0] = initial
コード例 #2
0
def test_snapshot_with_version_file():
    with setupmeta.temp_resource() as temp:
        with conftest.capture_output() as logged:
            with open(os.path.join(temp, setupmeta.VERSION_FILE), "w") as fh:
                fh.write("v1.2.3-4-g1234567")

            setup_py = os.path.join(temp, "setup.py")
            meta = SetupMeta().finalize(
                dict(_setup_py_path=setup_py,
                     name="just-testing",
                     versioning="post",
                     setup_requires="setupmeta"))

            versioning = meta.versioning
            assert meta.version == "1.2.3.post4"
            assert not versioning.generate_version_file
            assert versioning.scm.program is None
            assert str(versioning.scm).startswith("snapshot ")
            assert not versioning.scm.is_dirty()
            assert versioning.scm.get_branch() == "HEAD"

            # Trigger artificial rewriting of version file
            versioning.generate_version_file = True
            versioning.auto_fill_version()
            assert "WARNING: No 'packages' or 'py_modules' defined" in logged
コード例 #3
0
def new_meta(versioning, name="just-testing", scm=None, setup_py=None, **kwargs):
    setup_py = setup_py or conftest.resouce("setup.py")
    upstream = dict(versioning=versioning, scm=scm, _setup_py_path=setup_py)
    if name:
        # Allow to test "missing name" case
        upstream["name"] = name

    upstream.update(kwargs)
    return SetupMeta().finalize(upstream=upstream)
コード例 #4
0
ファイル: hook.py プロジェクト: reallistic/setupmeta
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)
コード例 #5
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)
コード例 #6
0
def test_snapshot_with_version_file():
    with setupmeta.temp_resource() as temp:
        with open(os.path.join(temp, setupmeta.VERSION_FILE), "w") as fh:
            fh.write("v1.2.3-4-g1234567")

        setup_py = os.path.join(temp, "setup.py")
        meta = SetupMeta(dict(_setup_py_path=setup_py, versioning="post", setup_requires="setupmeta"))

        versioning = meta.versioning
        assert meta.version == "1.2.3.post4"
        assert not versioning.generate_version_file
        assert versioning.scm.program is None
        assert str(versioning.scm).startswith("snapshot ")
        assert not versioning.scm.is_dirty()
        assert versioning.scm.get_branch() == "HEAD"

        # Trigger artificial rewriting of version file
        versioning.generate_version_file = True
        versioning.auto_fill_version()
コード例 #7
0
def test_snapshot():
    temp = tempfile.mkdtemp()
    try:
        with open(os.path.join(temp, setupmeta.VERSION_FILE), 'w') as fh:
            fh.write('v1.2.3-4-g1234567')

        setup_py = os.path.join(temp, 'setup.py')
        meta = SetupMeta(dict(_setup_py_path=setup_py, versioning='post', setup_requires='setupmeta'))
        versioning = meta.versioning
        assert meta.version == '1.2.3.post4'
        assert not versioning.generate_version_file

        assert versioning.scm.program is None
        assert str(versioning.scm).startswith('snapshot ')
        assert not versioning.scm.is_dirty()
        assert versioning.scm.get_branch() == 'HEAD'

        # Trigger artificial rewriting of version file
        versioning.generate_version_file = True
        versioning.auto_fill_version()

    finally:
        shutil.rmtree(temp)
コード例 #8
0
def new_meta(versioning, scm=None, setup_py=None, **kwargs):
    setup_py = setup_py or conftest.resouce("setup.py")
    upstream = dict(versioning=versioning, scm=scm, _setup_py_path=setup_py)
    upstream.update(kwargs)
    return SetupMeta(upstream=upstream)
コード例 #9
0
ファイル: conftest.py プロジェクト: admdev8/setupmeta
 def __enter__(self):
     self.old_pd = setupmeta.MetaDefs.project_dir
     return SetupMeta().finalize(self.upstream)
コード例 #10
0
def bogus_project(**attrs):
    return SetupMeta(
        dict(_setup_py_path="/foo/bar/shouldnotexist/setup.py", **attrs))