Esempio n. 1
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
Esempio n. 2
0
def test_unsupported_twine(*_):
    with setupmeta.temp_resource() as temp:
        copy_to(setupmeta.project_path("examples", "single", "setup.py"), temp)
        copy_to(setupmeta.project_path("examples", "single", "single.py"),
                temp)
        run_setup_py(["twine"],
                     "twine command not supported on pypy",
                     folder=temp)
Esempio n. 3
0
def test_brand_new_project():
    with setupmeta.temp_resource():
        conftest.run_git("init")
        with open("setup.py", "w") as fh:
            fh.write(SAMPLE_EMPTY_PROJECT)

        # Test that we avoid warning about no tags etc on brand new empty git repos
        output = setupmeta.run_program(sys.executable, "setup.py", "--version", capture="all")
        output = conftest.cleaned_output(output)
        assert output == "0.0.0"
Esempio n. 4
0
def sample_project():
    """Yield a sample git project, seeded with files from tests/sample"""
    old_cd = os.getcwd()
    try:
        with setupmeta.temp_resource() as temp:
            source = resource("sample")
            dest = os.path.join(temp, "sample")
            shutil.copytree(source, dest)
            files = os.listdir(dest)
            run_git("init", cwd=dest)
            run_git("add", *files, cwd=dest)
            run_git("commit", "-m", "Initial commit", cwd=dest)
            os.chdir(dest)
            yield dest

    finally:
        os.chdir(old_cd)
Esempio n. 5
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()
Esempio n. 6
0
def test_clean():
    with setupmeta.temp_resource() as temp:
        touch(temp, True, ".idea", "build", "dd", "dd/__pycache__",
              "foo.egg-info")
        touch(temp, False, "foo", "a.pyc", ".pyo", "bar.pyc", "setup.py",
              "dd/__pycache__/a.pyc")
        run_setup_py(
            ["cleanall"],
            """
            deleted build
            deleted foo.egg-info
            deleted dd.__pycache__
            deleted 2 .pyc files, 1 .pyo files
            """,
            folder=temp,
        )
        # Run a 2nd time: nothing to be cleaned anymore
        run_setup_py(["cleanall"],
                     "all clean, no deletable files found",
                     folder=temp)
Esempio n. 7
0
def parse_requirements(requirements):
    """Parse requirements with pip"""
    # Note: we can't assume pip is installed
    pip_parse_requirements, pip_session = get_pip()
    if not pip_parse_requirements or not requirements:
        return None, None

    reqs = []
    links = []
    session = pip_session()
    try:
        if not isinstance(requirements, list):
            # Parse given file path as-is (when not abstracting)
            for ir in pip_parse_requirements(requirements, session=session):
                if ir.link:
                    if ir.name:
                        reqs.append(ir.name)
                    links.append(ir.link.url)
                else:
                    reqs.append(str(ir.req))

            return reqs, links

        with temp_resource(is_folder=False) as temp:
            # Passed list is "complex reqs" that were not abstracted by the simple convention described here:
            # https://github.com/zsimic/setupmeta/blob/master/docs/requirements.rst
            with open(temp, "wt") as fh:
                fh.write("\n".join(requirements))

            for ir in pip_parse_requirements(temp, session=session):
                if ir.link:
                    if ir.name:
                        reqs.append(ir.name)
                    links.append(ir.link.url)
                else:
                    reqs.append(str(ir.req))

    except Exception:
        return None, None

    return reqs, links
Esempio n. 8
0
def parse_requirements(requirements):
    """Parse requirements with pip"""
    # Note: we can't assume pip is installed
    pip_parse_requirements, pip_session = get_pip()
    if not pip_parse_requirements:
        return None, None

    reqs = []
    links = []
    session = pip_session()
    with temp_resource(is_folder=False) as temp:
        with open(temp, "wt") as fh:
            fh.write("\n".join(requirements))
        for ir in pip_parse_requirements(temp, session=session):
            if ir.link:
                if ir.name:
                    reqs.append(ir.name)
                links.append(ir.link.url)
            else:
                reqs.append(str(ir.req))

    return reqs, links
Esempio n. 9
0
def test_brand_new_project():
    with setupmeta.temp_resource():
        conftest.run_git("init")
        with open("setup.py", "w") as fh:
            fh.write(SAMPLE_EMPTY_PROJECT)

        # Test that we avoid warning about no tags etc on brand new empty git repos
        check_version_output("0.0.0")

        # Now stage a file
        conftest.run_git("add", "setup.py")
        check_version_output("0.0.0+dirty")

        # Unstage it
        conftest.run_git("reset", "setup.py")
        check_version_output("0.0.0")

        # Commit it, and touch a new file
        conftest.run_git("add", "setup.py")
        conftest.run_git("commit", "-m", "Initial commit")
        with open("foo", "w") as fh:
            fh.write("foo\n")

        check_version_output("0.0.1")
Esempio n. 10
0
def test_twine():
    with setupmeta.temp_resource() as temp:
        copy_to(setupmeta.project_path("examples", "single", "setup.py"), temp)
        copy_to(setupmeta.project_path("examples", "single", "single.py"),
                temp)

        run_setup_py(["twine"],
                     "Specify at least one of: --egg, --dist or --wheel",
                     folder=temp)
        run_setup_py(["twine", "--egg=all"],
                     "twine is not installed",
                     folder=temp)

        copy_to(setupmeta.project_path("tests", "mock-twine"),
                temp,
                basename="twine")

        run_setup_py(
            ["twine", "--egg=all"],
            """
                Dryrun, use --commit to effectively build/publish
                Would build egg distribution: .*python.* setup.py bdist_egg
                Would upload to PyPi via twine
            """,
            folder=temp,
        )

        run_setup_py(
            ["twine", "--commit", "--egg=all", "--wheel=1.0"],
            """
                python.* setup.py bdist_egg
                Uploading to PyPi via twine
                Running: <target>/twine upload <target>/dist/single-0.1.0-.+.egg
                Deleting <target>/build
            """,
            folder=temp,
        )

        run_setup_py(
            ["twine", "--egg=all"],
            """
                Would delete .*/dist
                Would build egg distribution: .*python.* setup.py bdist_egg
                Would upload to PyPi via twine
            """,
            folder=temp,
        )

        run_setup_py(
            [
                "twine", "--commit", "--rebuild", "--egg=all", "--sdist=all",
                "--wheel=all"
            ],
            """
                Deleting <target>/dist
                python.* setup.py bdist_egg
                python.* setup.py sdist
                python.* setup.py bdist_wheel
                Uploading to PyPi via twine
                Running: <target>/twine upload <target>/dist
                Deleting <target>/build
            """,
            folder=temp,
        )

        run_setup_py(
            ["twine", "--commit", "--rebuild", "--egg=1.0"],
            """
                Deleting <target>/dist
                No files found in <target>/dist
            """,
            folder=temp,
        )
Esempio n. 11
0
def scenario_folder(request):
    """Yield one test per scenario"""
    with setupmeta.temp_resource():
        yield request.param