コード例 #1
0
ファイル: test_appdirs.py プロジェクト: benesch/pip
    def test_user_cache_dir_osx(self, monkeypatch):
        monkeypatch.setattr(appdirs, "WINDOWS", False)
        monkeypatch.setattr(os, "path", posixpath)
        monkeypatch.setenv("HOME", "/home/test")
        monkeypatch.setattr(sys, "platform", "darwin")

        assert appdirs.user_cache_dir("pip") == "/home/test/Library/Caches/pip"
コード例 #2
0
ファイル: test_install.py プロジェクト: yuanshenjian/pip
def test_install_builds_wheels(script, data):
    # NB This incidentally tests a local tree + tarball inputs
    # see test_install_editable_from_git_autobuild_wheel for editable
    # vcs coverage.
    script.pip('install', 'wheel')
    to_install = data.packages.join('requires_wheelbroken_upper')
    res = script.pip('install',
                     '--no-index',
                     '-f',
                     data.find_links,
                     to_install,
                     expect_stderr=True)
    expected = ("Successfully installed requires-wheelbroken-upper-0"
                " upper-2.0 wheelbroken-0.1")
    # Must have installed it all
    assert expected in str(res), str(res)
    root = appdirs.user_cache_dir('pip')
    wheels = []
    for top, dirs, files in os.walk(root):
        wheels.extend(files)
    # and built wheels for upper and wheelbroken
    assert "Running setup.py bdist_wheel for upper" in str(res), str(res)
    assert "Running setup.py bdist_wheel for wheelb" in str(res), str(res)
    # But not requires_wheel... which is a local dir and thus uncachable.
    assert "Running setup.py bdist_wheel for requir" not in str(res), str(res)
    # wheelbroken has to run install
    # into the cache
    assert wheels != [], str(res)
    # and installed from the wheel
    assert "Running setup.py install for upper" not in str(res), str(res)
    # the local tree can't build a wheel (because we can't assume that every
    # build will have a suitable unique key to cache on).
    assert "Running setup.py install for requires-wheel" in str(res), str(res)
    # wheelbroken has to run install
    assert "Running setup.py install for wheelb" in str(res), str(res)
コード例 #3
0
ファイル: test_install.py プロジェクト: MathewJennings/pip
def test_install_builds_wheels(script, data):
    # NB This incidentally tests a local tree + tarball inputs
    # see test_install_editable_from_git_autobuild_wheel for editable
    # vcs coverage.
    script.pip('install', 'wheel')
    to_install = data.packages.join('requires_wheelbroken_upper')
    res = script.pip(
        'install', '--no-index', '-f', data.find_links,
        to_install, expect_stderr=True)
    expected = ("Successfully installed requires-wheelbroken-upper-0"
                " upper-2.0 wheelbroken-0.1")
    # Must have installed it all
    assert expected in str(res), str(res)
    root = appdirs.user_cache_dir('pip')
    wheels = []
    for top, dirs, files in os.walk(root):
        wheels.extend(files)
    # and built wheels for upper and wheelbroken
    assert "Running setup.py bdist_wheel for upper" in str(res), str(res)
    assert "Running setup.py bdist_wheel for wheelb" in str(res), str(res)
    # But not requires_wheel... which is a local dir and thus uncachable.
    assert "Running setup.py bdist_wheel for requir" not in str(res), str(res)
    # wheelbroken has to run install
    # into the cache
    assert wheels != [], str(res)
    # and installed from the wheel
    assert "Running setup.py install for upper" not in str(res), str(res)
    # the local tree can't build a wheel (because we can't assume that every
    # build will have a suitable unique key to cache on).
    assert "Running setup.py install for requires-wheel" in str(res), str(res)
    # wheelbroken has to run install
    assert "Running setup.py install for wheelb" in str(res), str(res)
コード例 #4
0
    def test_user_cache_dir_osx(self, monkeypatch):
        monkeypatch.setattr(appdirs, "WINDOWS", False)
        monkeypatch.setattr(os, "path", posixpath)
        monkeypatch.setenv("HOME", "/home/test")
        monkeypatch.setattr(sys, "platform", "darwin")

        assert appdirs.user_cache_dir("pip") == "/home/test/Library/Caches/pip"
コード例 #5
0
ファイル: setup.py プロジェクト: jfelectron/magnitude
def delete_pip_files():
    """Delete random pip files"""
    try:
        from pip.utils.appdirs import user_cache_dir
    except BaseException:
        try:
            from pip._internal.utils.appdirs import user_cache_dir
        except BaseException:
            return
    for root, dirnames, filenames in os.walk(user_cache_dir('pip/wheels')):
        for filename in fnmatch.filter(filenames, PACKAGE_NAME + '-*.whl'):
            try:
                whl = os.path.join(root, filename)
                print("Deleting...", whl)
                os.remove(whl)
            except BaseException:
                pass
    try:
        import site
        if hasattr(site, 'getsitepackages'):
            site_packages = site.getsitepackages()
        else:
            from distutils.sysconfig import get_python_lib
            site_packages = [get_python_lib()]
        if hasattr(site, 'getusersitepackages'):
            site_packages = site_packages + [site.getusersitepackages()]
        for sitepack in site_packages:
            for globbed in glob(sitepack + '/' + PACKAGE_NAME + '*/'):
                try:
                    if globbed.endswith('.dist-info/'):
                        shutil.rmtree(globbed)
                except BaseException:
                    pass
    except BaseException:
        pass
コード例 #6
0
def test_install_no_binary_disables_building_wheels(script, data):
    script.pip('install', 'wheel')
    to_install = data.packages.join('requires_wheelbroken_upper')
    res = script.pip(
        'install', '--no-index', '--no-binary=upper', '-f', data.find_links,
        to_install, expect_stderr=True)
    expected = ("Successfully installed requires-wheelbroken-upper-0"
                " upper-2.0 wheelbroken-0.1")
    # Must have installed it all
    assert expected in str(res), str(res)
    root = appdirs.user_cache_dir('pip')
    wheels = []
    for top, dirs, files in os.walk(root):
        wheels.extend(files)
    # and built wheels for wheelbroken only
    assert "Running setup.py bdist_wheel for wheelb" in str(res), str(res)
    # But not requires_wheel... which is a local dir and thus uncachable.
    assert "Running setup.py bdist_wheel for requir" not in str(res), str(res)
    # Nor upper, which was blacklisted
    assert "Running setup.py bdist_wheel for upper" not in str(res), str(res)
    # wheelbroken has to run install
    # into the cache
    assert wheels != [], str(res)
    # the local tree can't build a wheel (because we can't assume that every
    # build will have a suitable unique key to cache on).
    assert "Running setup.py install for requires-wheel" in str(res), str(res)
    # And these two fell back to sdist based installed.
    assert "Running setup.py install for wheelb" in str(res), str(res)
    assert "Running setup.py install for upper" in str(res), str(res)
コード例 #7
0
ファイル: conftest.py プロジェクト: wvangeit/pip
def virtualenv(tmpdir, monkeypatch, isolate):
    """
    Return a virtual environment which is unique to each test function
    invocation created inside of a sub directory of the test function's
    temporary directory. The returned object is a
    ``tests.lib.venv.VirtualEnvironment`` object.
    """
    # Force shutil to use the older method of rmtree that didn't use the fd
    # functions. These seem to fail on Travis (and only on Travis).
    monkeypatch.setattr(shutil, "_use_fd_functions", False, raising=False)

    # Copy over our source tree so that each virtual environment is self
    # contained
    pip_src = tmpdir.join("pip_src").abspath
    shutil.copytree(
        SRC_DIR,
        pip_src,
        ignore=shutil.ignore_patterns(
            "*.pyc",
            "__pycache__",
            "contrib",
            "docs",
            "tasks",
            "*.txt",
            "tests",
            "pip.egg-info",
            "build",
            "dist",
            ".tox",
            ".git",
        ),
    )

    # Create the virtual environment
    venv = VirtualEnvironment.create(
        tmpdir.join("workspace", "venv"),
        pip_source_dir=pip_src,
    )

    # Clean out our cache: creating the venv injects wheels into it.
    if os.path.exists(appdirs.user_cache_dir("pip")):
        shutil.rmtree(appdirs.user_cache_dir("pip"))

    # Undo our monkeypatching of shutil
    monkeypatch.undo()

    return venv
コード例 #8
0
    def test_user_cache_dir_linux_override(self, monkeypatch):
        monkeypatch.setattr(appdirs, "WINDOWS", False)
        monkeypatch.setattr(os, "path", posixpath)
        monkeypatch.setenv("XDG_CACHE_HOME", "/home/test/.other-cache")
        monkeypatch.setenv("HOME", "/home/test")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_cache_dir("pip") == "/home/test/.other-cache/pip"
コード例 #9
0
ファイル: test_appdirs.py プロジェクト: benesch/pip
    def test_user_cache_dir_linux_override(self, monkeypatch):
        monkeypatch.setattr(appdirs, "WINDOWS", False)
        monkeypatch.setattr(os, "path", posixpath)
        monkeypatch.setenv("XDG_CACHE_HOME", "/home/test/.other-cache")
        monkeypatch.setenv("HOME", "/home/test")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_cache_dir("pip") == "/home/test/.other-cache/pip"
コード例 #10
0
    def test_user_cache_dir_linux_home_slash(self, monkeypatch):
        monkeypatch.setattr(appdirs, "WINDOWS", False)
        monkeypatch.setattr(os, "path", posixpath)
        # Verify that we are not affected by http://bugs.python.org/issue14768
        monkeypatch.delenv("XDG_CACHE_HOME")
        monkeypatch.setenv("HOME", "/")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_cache_dir("pip") == "/.cache/pip"
コード例 #11
0
ファイル: test_appdirs.py プロジェクト: benesch/pip
    def test_user_cache_dir_linux_home_slash(self, monkeypatch):
        monkeypatch.setattr(appdirs, "WINDOWS", False)
        monkeypatch.setattr(os, "path", posixpath)
        # Verify that we are not affected by http://bugs.python.org/issue14768
        monkeypatch.delenv("XDG_CACHE_HOME")
        monkeypatch.setenv("HOME", "/")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_cache_dir("pip") == "/.cache/pip"
コード例 #12
0
ファイル: conftest.py プロジェクト: Larry7/pip
def virtualenv(tmpdir, monkeypatch, isolate):
    """
    Return a virtual environment which is unique to each test function
    invocation created inside of a sub directory of the test function's
    temporary directory. The returned object is a
    ``tests.lib.venv.VirtualEnvironment`` object.
    """
    # Force shutil to use the older method of rmtree that didn't use the fd
    # functions. These seem to fail on Travis (and only on Travis).
    monkeypatch.setattr(shutil, "_use_fd_functions", False, raising=False)

    # Copy over our source tree so that each virtual environment is self
    # contained
    pip_src = tmpdir.join("pip_src").abspath
    shutil.copytree(
        SRC_DIR,
        pip_src,
        ignore=shutil.ignore_patterns(
            "*.pyc", "__pycache__", "contrib", "docs", "tasks", "*.txt",
            "tests", "pip.egg-info", "build", "dist", ".tox", ".git",
        ),
    )

    # Create the virtual environment
    venv = VirtualEnvironment.create(
        tmpdir.join("workspace", "venv"),
        pip_source_dir=pip_src,
    )

    # Clean out our cache: creating the venv injects wheels into it.
    if os.path.exists(appdirs.user_cache_dir("pip")):
        shutil.rmtree(appdirs.user_cache_dir("pip"))

    # Undo our monkeypatching of shutil
    monkeypatch.undo()

    return venv
コード例 #13
0
ファイル: test_appdirs.py プロジェクト: Yasumoto/pip
    def test_user_cache_dir_win(self, monkeypatch):
        @pretend.call_recorder
        def _get_win_folder(base):
            return "C:\\Users\\test\\AppData\\Local"

        monkeypatch.setattr(
            appdirs,
            "_get_win_folder",
            _get_win_folder,
            raising=False,
        )
        monkeypatch.setattr(appdirs, "WINDOWS", True)

        assert (appdirs.user_cache_dir("pip").replace("/", "\\")
                == "C:\\Users\\test\\AppData\\Local\\pip\\Cache")
        assert _get_win_folder.calls == [pretend.call("CSIDL_LOCAL_APPDATA")]
コード例 #14
0
ファイル: test_appdirs.py プロジェクト: zdexter/docker
    def test_user_cache_dir_win(self, monkeypatch):
        @pretend.call_recorder
        def _get_win_folder(base):
            return "C:\\Users\\test\\AppData\\Local"

        monkeypatch.setattr(
            appdirs,
            "_get_win_folder",
            _get_win_folder,
            raising=False,
        )
        monkeypatch.setattr(appdirs, "WINDOWS", True)

        assert (appdirs.user_cache_dir("pip").replace(
            "/", "\\") == "C:\\Users\\test\\AppData\\Local\\pip\\Cache")
        assert _get_win_folder.calls == [pretend.call("CSIDL_LOCAL_APPDATA")]
コード例 #15
0
    def test_user_cache_dir_unicode(self, monkeypatch):
        if sys.platform != 'win32':
            return

        def my_get_win_folder(csidl_name):
            return u"\u00DF\u00E4\u03B1\u20AC"

        monkeypatch.setattr(appdirs, "_get_win_folder", my_get_win_folder)

        # Do not use the isinstance expression directly in the
        # assert statement, as the Unicode characters in the result
        # cause pytest to fail with an internal error on Python 2.7
        result_is_str = isinstance(appdirs.user_cache_dir('test'), str)
        assert result_is_str, "user_cache_dir did not return a str"

        # Test against regression #3463
        from pip import create_main_parser
        create_main_parser().print_help()  # This should not crash
コード例 #16
0
ファイル: test_appdirs.py プロジェクト: benesch/pip
    def test_user_cache_dir_unicode(self, monkeypatch):
        if sys.platform != 'win32':
            return

        def my_get_win_folder(csidl_name):
            return u"\u00DF\u00E4\u03B1\u20AC"

        monkeypatch.setattr(appdirs, "_get_win_folder", my_get_win_folder)

        # Do not use the isinstance expression directly in the
        # assert statement, as the Unicode characters in the result
        # cause pytest to fail with an internal error on Python 2.7
        result_is_str = isinstance(appdirs.user_cache_dir('test'), str)
        assert result_is_str, "user_cache_dir did not return a str"

        # Test against regression #3463
        from pip import create_main_parser
        create_main_parser().print_help()  # This should not crash
コード例 #17
0
import os
from shutil import rmtree

from .click import secho
from pip.utils.appdirs import user_cache_dir

# The user_cache_dir helper comes straight from pip itself
CACHE_DIR = user_cache_dir('pip-tools')

# NOTE
# We used to store the cache dir under ~/.pip-tools, which is not the
# preferred place to store caches for any platform.  This has been addressed
# in pip-tools==1.0.5, but to be good citizens, we point this out explicitly
# to the user when this directory is still found.
LEGACY_CACHE_DIR = os.path.expanduser('~/.pip-tools')

if os.path.exists(LEGACY_CACHE_DIR):
    secho('Removing old cache dir {} (new cache dir is {})'.format(
        LEGACY_CACHE_DIR, CACHE_DIR),
          fg='yellow')
    rmtree(LEGACY_CACHE_DIR)
コード例 #18
0
ファイル: locations.py プロジェクト: Josquin95/Triqui
"""Locations where we look for configs, install stuff, etc"""
from __future__ import absolute_import

import os
import os.path
import site
import sys
from distutils import sysconfig
from distutils.command.install import install, SCHEME_KEYS  # noqa

from pip.compat import WINDOWS, expanduser
from pip.utils import appdirs

# Application Directories
USER_CACHE_DIR = appdirs.user_cache_dir("pip")

DELETE_MARKER_MESSAGE = '''\
This file is placed here by pip to indicate the source was put
here by pip.

Once this package is successfully installed this source code will be
deleted (unless you remove this file).
'''
PIP_DELETE_MARKER_FILENAME = 'pip-delete-this-directory.txt'


def write_delete_marker_file(directory):
    """
    Write the pip delete marker file into this directory.
    """
    filepath = os.path.join(directory, PIP_DELETE_MARKER_FILENAME)
コード例 #19
0
ファイル: locations.py プロジェクト: Yankur/Web-application
from __future__ import absolute_import

import os
import os.path
import site
import sys

from distutils import sysconfig
from distutils.command.install import install, SCHEME_KEYS  # noqa

from pip.compat import WINDOWS, expanduser
from pip.utils import appdirs


# Application Directories
USER_CACHE_DIR = appdirs.user_cache_dir("pip")
>>>>>>> 54eef0be98b1b67c8507db91f4cfa90b64991027


DELETE_MARKER_MESSAGE = '''\
This file is placed here by pip to indicate the source was put
here by pip.

Once this package is successfully installed this source code will be
deleted (unless you remove this file).
'''
PIP_DELETE_MARKER_FILENAME = 'pip-delete-this-directory.txt'

<<<<<<< HEAD
=======
コード例 #20
0
# -*- coding: utf-8 -*-

from pip.utils.appdirs import user_cache_dir

CACHE_DIR = user_cache_dir('pypoet')
コード例 #21
0
#Joblib is optimized to be fast and robust on large data in particular and has 
#specific optimizations for numpy arrays.


#To know where is the cache dir
import pip
from distutils.version import LooseVersion

if LooseVersion(pip.__version__) < LooseVersion('10'):
    # older pip version
    from pip.utils.appdirs import user_cache_dir
else:
    # newer pip version
    from pip._internal.utils.appdirs import user_cache_dir

print(user_cache_dir('pip'))
print(user_cache_dir('wheel'))




#
cachedir = 'your_cache_location_directory'
#
>>> from joblib import Memory
>>> memory = Memory(cachedir, verbose=0)

>>> @memory.cache
... def f(x):
...     print('Running f(%s)' % x)
...     return x
コード例 #22
0
from pip.utils.appdirs import user_cache_dir

# The user_cache_dir helper comes straight from pip itself
CACHE_DIR = user_cache_dir('prequ')
コード例 #23
0
import os
from shutil import rmtree

from .click import secho
from pip.utils.appdirs import user_cache_dir

# The user_cache_dir helper comes straight from pip itself
CACHE_DIR = user_cache_dir('pip-tools')

# NOTE
# We used to store the cache dir under ~/.pip-tools, which is not the
# preferred place to store caches for any platform.  This has been addressed
# in pip-tools==1.0.5, but to be good citizens, we point this out explicitly
# to the user when this directory is still found.
LEGACY_CACHE_DIR = os.path.expanduser('~/.pip-tools')

if os.path.exists(LEGACY_CACHE_DIR):
    secho('Removing old cache dir {} (new cache dir is {})'.format(LEGACY_CACHE_DIR, CACHE_DIR), fg='yellow')
    rmtree(LEGACY_CACHE_DIR)
コード例 #24
0
ファイル: test_appdirs.py プロジェクト: zdexter/docker
    def test_user_cache_dir_linux(self, monkeypatch):
        monkeypatch.delenv("XDG_CACHE_HOME")
        monkeypatch.setenv("HOME", "/home/test")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_cache_dir("pip") == "/home/test/.cache/pip"
コード例 #25
0
ファイル: test_appdirs.py プロジェクト: Yasumoto/pip
    def test_user_cache_dir_linux(self, monkeypatch):
        monkeypatch.delenv("XDG_CACHE_HOME")
        monkeypatch.setenv("HOME", "/home/test")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_cache_dir("pip") == "/home/test/.cache/pip"