コード例 #1
0
def test_installed_distributions(pip, some_distribution):
    distributions = pip_api.installed_distributions()

    assert some_distribution.name not in distributions

    pip.run("install", some_distribution.filename)

    distributions = pip_api.installed_distributions()

    assert some_distribution.name in distributions

    distribution = distributions[some_distribution.name]

    assert distribution.name == some_distribution.name
    assert distribution.version == some_distribution.version

    # Various versions of `pip` have different behavior here:
    # * `pip` 10.0.0b1 and newer include the `location` key in the JSON output
    # * `pip` 9.0.0 through 10.0.0b0 support JSON, but don't include `location`
    # * `pip` versions before 9.0.0 don't support JSON and don't include
    #   any location information in the textual output that we parse
    if pip_api.PIP_VERSION >= parse("10.0.0b0"):
        # We don't know exactly where the distribution has been installed,
        # but we know it exists and therefore is editable.
        assert os.path.exists(distribution.location)
        assert distribution.editable
    else:
        assert distribution.location is None
        assert not distribution.editable
コード例 #2
0
def test_installed_distributions_legacy_version(pip, data):
    distributions = pip_api.installed_distributions()

    assert "dummyproject" not in distributions

    pip.run("install", data.join("dummyproject-0.23ubuntu1.tar.gz"))

    distributions = pip_api.installed_distributions()

    assert "dummyproject" in distributions
    assert distributions["dummyproject"].version == parse("0.23ubuntu1")
コード例 #3
0
def test_installed_distributions_path(pip, some_distribution, target):
    distributions = pip_api.installed_distributions()
    assert some_distribution.name not in distributions

    # No packages installed under the target directory yet
    if PATH_SUPPORTED:
        distributions = pip_api.installed_distributions(paths=[target])
        assert some_distribution.name not in distributions
    else:
        with pytest.raises(PipError, match=PATH_UNSUPPORTED_MSG):
            pip_api.installed_distributions(paths=[target])

    # Install the package under the target directory
    pip.run("install", "--target", target, some_distribution.filename)

    # If we list packages without pointing `pip-api` to the target directory, we shouldn't find the
    # installed package
    distributions = pip_api.installed_distributions()
    assert some_distribution.name not in distributions

    # If we set the path to the target directory, we should find the installed package
    if PATH_SUPPORTED:
        distributions = pip_api.installed_distributions(paths=[target])
        assert some_distribution.name in distributions
    else:
        with pytest.raises(PipError, match=PATH_UNSUPPORTED_MSG):
            pip_api.installed_distributions(paths=[target])
コード例 #4
0
def test_installed_distributions(pip, some_distribution):
    distributions = pip_api.installed_distributions()

    assert some_distribution.name not in distributions

    pip.run("install", some_distribution.filename)

    distributions = pip_api.installed_distributions()

    assert some_distribution.name in distributions

    distribution = distributions[some_distribution.name]

    assert distribution.name == some_distribution.name
    assert distribution.version == some_distribution.version
    assert distribution.location == some_distribution.location
    assert distribution.editable == some_distribution.editable
コード例 #5
0
ファイル: pytest_reqs.py プロジェクト: luzfcb/pytest-reqs
def check_requirements(config, session, items):
    installed_distributions = dict([
        (packaging.utils.canonicalize_name(name), req)
        for name, req in pip_api.installed_distributions().items()
    ])

    items.extend(
        ReqsItem(filename, installed_distributions, config, session)
        for filename in get_reqs_filenames(config))
コード例 #6
0
ファイル: pytest_reqs.py プロジェクト: di/pytest-reqs
def check_requirements(config, session, items):
    installed_distributions = dict([
        (packaging.utils.canonicalize_name(name), req)
        for name, req in pip_api.installed_distributions().items()
    ])

    items.extend(
        ReqsItem(filename, installed_distributions, config, session)
        for filename in get_reqs_filenames(config)
    )
コード例 #7
0
def test_isolation(pip, some_distribution, should_be_installed):
    """
    Test the isolation between tests. The first time this test is run, the
    package should be installed, the second time, it should not exist
    """

    if should_be_installed:
        pip.run('install', some_distribution.filename)

    installed = pip_api.installed_distributions()

    if should_be_installed:
        assert some_distribution.name in installed
    else:
        assert some_distribution.name not in installed
コード例 #8
0
ファイル: universal.py プロジェクト: vv-monsalve/fontbakery
def com_google_fonts_check_fontbakery_version():
    """Do we have the latest version of FontBakery installed?"""
    import json
    import requests
    import pip_api

    pypi_data = requests.get('https://pypi.org/pypi/fontbakery/json')
    latest = json.loads(pypi_data.content)["info"]["version"]
    installed = str(pip_api.installed_distributions()["fontbakery"].version)

    if not is_up_to_date(installed, latest):
        yield FAIL, (f"Current Font Bakery version is {installed},"
                     f" while a newer {latest} is already available."
                     f" Please upgrade it with 'pip install -U fontbakery'")
    else:
        yield PASS, "Font Bakery is up-to-date"
コード例 #9
0
def test_installed_distributions_local(monkeypatch, pip):
    # Ideally, we'd be able to compare the value of `installed_distributions`
    # with and without the `local` flag. However, to test like this, we'd need
    # to globally-install a package to observe the difference.
    #
    # This isn't practical for the purposes of a unit test, so we'll have to
    # settle for checking that the `--local` flag gets passed in to the `pip`
    # invocation.
    original_call = pip_api._installed_distributions.call

    def mock_call(*args, cwd=None):
        assert "--local" in args
        return original_call(*args, cwd=cwd)

    monkeypatch.setattr(pip_api._installed_distributions, "call", mock_call)

    _ = pip_api.installed_distributions(local=True)
コード例 #10
0
def check_dependency():
    list_deps = []
    missing_deps = []

    with open('requirements.txt') as f:
        list_deps = f.read().splitlines()

    pip_list = sorted([i.lower() for i in pip_api.installed_distributions()])

    for req_dep in list_deps:
        if req_dep not in pip_list:
            missing_deps.append(req_dep)

    if missing_deps:
        print(
            "You are missing {0} packages for Datasploit. Please install them using: "
            .format(missing_deps))
        print("pip install -r requirements.txt")
        sys.exit()
コード例 #11
0
    def check_requirements():
        # Only check requirements in dev environments
        if IS_EXE:
            return

        all_req_files = [
            "requirements.txt",
            "requirements-dev.txt",
        ]
        if is_windows():
            all_req_files.append("requirements-win.txt")

        installed = pip_api.installed_distributions()
        missing_req_files = set()
        for req_file in all_req_files:
            requirements = pip_api.parse_requirements(req_file)

            for req in requirements.values():
                if req.name not in installed:
                    missing_req_files.add(req_file)
                    logger.warning("Missing required package '%s'", req.name)
                    continue

                installed_ver = installed[req.name].version
                if req.specifier.contains(installed_ver):
                    continue
                missing_req_files.add(req_file)
                logger.warning(
                    "Installed version of '%s' is %s, doesen't meet %s",
                    req.name,
                    installed_ver,
                    req.specifier,
                )

        if not missing_req_files:
            return
        r_args = "  ".join([f"-r {r}" for r in missing_req_files])
        logger.warning(
            "Some requirements aren't met. Run pip install --upgrade %s",
            r_args,
        )