def test_without_extras(pathlib_tmpdir):
    """Tests a setup.py or setup.cfg parse when extras returns None for some
    files."""
    setup_dir = pathlib_tmpdir.joinpath("sanitized-package")
    setup_dir.mkdir()
    assert setup_dir.is_dir()
    setup_py = setup_dir.joinpath("setup.py")
    setup_py.write_text("""
# -*- coding: utf-8 -*-
from setuptools import setup

setup(
    name="sanitized-package",
    version="0.0.1",
    install_requires=["raven==5.32.0"],
    extras_require={
        'PDF': ["socks"]
    }
)
    """.strip())
    setup_dict = None
    with vistir.contextmanagers.cd(setup_dir.as_posix()):
        pipfile_entry = {
            "path": os.path.abspath(os.curdir),
            "editable": True,
            "extras": ["socks"],
        }
        r = Requirement.from_pipfile("e1839a8", pipfile_entry)
        r.run_requires()
        setup_dict = r.req.setup_info.as_dict()
        assert sorted(list(setup_dict.get("requires").keys())) == ["raven"]
def test_local_editable_ref(monkeypatch):
    with monkeypatch.context() as m:
        m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
        path = Path(ARTIFACTS_DIR) / "git/requests"
        req = Requirement.from_pipfile(
            "requests", {"editable": True, "git": path.as_uri(), "ref": "2.18.4"}
        )
        assert req.as_line() == "-e git+{0}@2.18.4#egg=requests".format(path.as_uri())
def test_extras(pathlib_tmpdir):
    """Test named extras as a dependency"""
    setup_dir = pathlib_tmpdir.joinpath("test_package")
    setup_dir.mkdir()
    assert setup_dir.is_dir()
    setup_py = setup_dir.joinpath("setup.py")
    setup_py.write_text(u"""
import os
from setuptools import setup, find_packages

thisdir = os.path.abspath(os.path.dirname(__file__))
version = "1.0.0"

testing_extras = [
    'coverage',
    'flaky',
]

setup(
    name='test_package',
    version=version,
    description="The Backend HTTP Server",
    long_description="This is a package",
    install_requires=[
        'six',
    ],
    tests_require=testing_extras,
    extras_require={
        'testing': testing_extras,
    },
    package_dir={"": "src"},
    packages=['test_package'],
    include_package_data=True,
    zip_safe=False,
)
    """.strip())
    src_dir = setup_dir.joinpath("src")
    src_dir.mkdir()
    pkg_dir = src_dir.joinpath("test_package")
    pkg_dir.mkdir()
    pkg_dir.joinpath("__init__.py").write_text(u"")
    pipfile_entry = {
        "path": "./{0}".format(setup_dir.name),
        "extras": ["testing"],
        "editable": True
    }
    setup_dict = None
    with vistir.contextmanagers.cd(pathlib_tmpdir.as_posix()):
        r = Requirement.from_pipfile("test-package", pipfile_entry)
        assert r.name == "test-package"
        r.req.setup_info.get_info()
        setup_dict = r.req.setup_info.as_dict()
        assert sorted(list(setup_dict.get("requires").keys())) == [
            "coverage", "flaky", "six"
        ], setup_dict
def test_convert_from_pipfile_vcs(monkeypatch):
    """ssh VCS links should be converted correctly"""
    with monkeypatch.context() as m:
        m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
        pkg_name = "shellingham"
        pkg_pipfile = {"editable": True, "git": "[email protected]:sarugaku/shellingham.git"}
        req = Requirement.from_pipfile(pkg_name, pkg_pipfile)
        assert (
            req.req.link.url
            == "git+ssh://[email protected]/sarugaku/shellingham.git#egg=shellingham"
        )
def test_convert_from_pipfile(monkeypatch, requirement, expected):
    with monkeypatch.context() as m:
        m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
        m.setattr(SetupInfo, "get_info", mock_run_requires)
        m.setattr(Requirement, "run_requires", mock_run_requires)
        pkg_name = first(requirement.keys())
        pkg_pipfile = requirement[pkg_name]
        req = Requirement.from_pipfile(pkg_name, pkg_pipfile)
        if " (" in expected and expected.endswith(")"):
            # To strip out plette[validation] (>=0.1.1)
            expected = expected.replace(" (", "").rstrip(")")
        assert req.as_line() == expected.lower() if "://" not in expected else expected
Beispiel #6
0
def test_vcs_requirement_with_env_vars():
    with temp_environ():
        os.environ["GIT_URL"] = "github.com"
        r = Requirement.from_pipfile("click", {
            "git": "https://${GIT_URL}/pallets/click.git",
            "ref": "6.7"
        })
        assert (r.as_ireq().link.url_without_fragment ==
                "git+https://github.com/pallets/[email protected]")
        assert r.as_line(
        ) == "git+https://${GIT_URL}/pallets/[email protected]#egg=click"
        assert r.as_pipfile(
        )["click"]["git"] == "https://${GIT_URL}/pallets/click.git"
        assert r.commit_hash == "df0e37dd890d36fc997986ae6d2b6c255f3ed1dc"
Beispiel #7
0
def test_file_url_with_percent_encoding():
    r = Requirement.from_pipfile(
        "torch",
        {
            "file":
            "https://download.pytorch.org/whl/cpu/torch-1.7.0%2Bcpu-cp38-cp38-linux_x86_64.whl#egg=torch"
        },
    )
    assert (
        r.req.uri ==
        "https://download.pytorch.org/whl/cpu/torch-1.7.0%2Bcpu-cp38-cp38-linux_x86_64.whl"
    )
    assert (
        r.as_line() ==
        "https://download.pytorch.org/whl/cpu/torch-1.7.0%2Bcpu-cp38-cp38-linux_x86_64.whl#egg=torch"
    )
def test_extras(pathlib_tmpdir, setup_py_dir, setup_py_name, extras, dependencies):
    """Test named extras as a dependency."""
    setup_dir = pathlib_tmpdir.joinpath("test_package")
    shutil.copytree(setup_py_dir.joinpath(setup_py_name).as_posix(), setup_dir.as_posix())
    assert setup_dir.is_dir()
    pipfile_entry = {
        "path": "./{0}".format(setup_dir.name),
        "extras": extras,
        "editable": True,
    }
    setup_dict = None
    with vistir.contextmanagers.cd(pathlib_tmpdir.as_posix()):
        r = Requirement.from_pipfile("test-package", pipfile_entry)
        assert r.name == "test-package"
        r.req.setup_info.get_info()
        setup_dict = r.req.setup_info.as_dict()
        assert sorted(list(setup_dict.get("requires").keys())) == dependencies
Beispiel #9
0
def test_get_requirements(monkeypatch_if_needed):
    # Test eggs in URLs
    # m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
    # m.setattr(SetupInfo, "get_info", mock_run_requires)
    url_with_egg = Requirement.from_line(
        "https://github.com/IndustriaTech/django-user-clipboard/archive/0.6.1.zip#egg=django-user-clipboard"
    ).requirement
    assert (
        url_with_egg.url ==
        "https://github.com/IndustriaTech/django-user-clipboard/archive/0.6.1.zip"
    )
    assert url_with_egg.name == "django-user-clipboard"
    # Test URLs without eggs pointing at installable zipfiles
    url = Requirement.from_line(
        "https://codeload.github.com/kennethreitz/tablib/zip/v0.12.1"
    ).requirement
    assert url.url == "https://codeload.github.com/kennethreitz/tablib/zip/v0.12.1"
    wheel_line = "https://github.com/pypa/pipenv/raw/master/tests/test_artifacts/six-1.11.0+mkl-py2.py3-none-any.whl"
    wheel = Requirement.from_line(wheel_line)
    assert wheel.as_pipfile() == {
        "six": {
            "file":
            "https://github.com/pypa/pipenv/raw/master/tests/test_artifacts/six-1.11.0+mkl-py2.py3-none-any.whl"
        }
    }
    # Requirementslib inserts egg fragments as names when possible if we know the appropriate name
    # this allows for custom naming
    assert (Requirement.from_pipfile(
        wheel.name,
        list(wheel.as_pipfile().values())[0]).as_line().split("#")[0] ==
            wheel_line)
    # Test VCS urls with refs and eggnames
    vcs_url = Requirement.from_line(
        "git+https://github.com/kennethreitz/tablib.git@master#egg=tablib"
    ).requirement
    assert (vcs_url.vcs == "git" and vcs_url.name == "tablib"
            and vcs_url.revision == "master")
    assert vcs_url.url == "git+https://github.com/kennethreitz/tablib.git"
    # Test normal package requirement
    normal = Requirement.from_line("tablib").requirement
    assert normal.name == "tablib"
    # Pinned package  requirement
    spec = Requirement.from_line("tablib==0.12.1").requirement
    assert spec.name == "tablib" and spec.specs == [("==", "0.12.1")]
    # Test complex package with both extras and markers
    extras_markers = Requirement.from_line(
        "requests[security]; os_name=='posix'").requirement
    assert list(extras_markers.extras) == ["security"]
    assert extras_markers.name == "requests"
    assert str(extras_markers.marker) == 'os_name == "posix"'
    # Test VCS uris get generated correctly, retain git+git@ if supplied that way, and are named according to egg fragment
    git_reformat = Requirement.from_line(
        "-e [email protected]:pypa/pipenv.git#egg=pipenv").requirement
    assert git_reformat.url == "git+ssh://[email protected]/pypa/pipenv.git"
    assert git_reformat.name == "pipenv"
    assert git_reformat.editable
    # Previously VCS uris were being treated as local files, so make sure these are not handled that way
    assert not git_reformat.local_file
    # Test regression where VCS uris were being handled as paths rather than VCS entries
    assert git_reformat.vcs == "git"
    assert git_reformat.link.url == "git+ssh://[email protected]/pypa/pipenv.git#egg=pipenv"
    # Test VCS requirements being added with extras for constraint_line
    git_extras = Requirement.from_line(
        "-e git+https://github.com/requests/requests.git@master#egg=requests[security]"
    )
    assert (
        git_extras.as_line() ==
        "-e git+https://github.com/requests/requests.git@master#egg=requests[security]"
    )
    assert (
        git_extras.constraint_line ==
        "-e git+https://github.com/requests/requests.git@master#egg=requests[security]"
    )