Example #1
0
def test_walk_prefix(tmpdir):  # tmpdir is a py.test utility
    # Each directory is a dict whose keys are names. If the value is
    # None, then that key represents a file. If it's another dict, that key is
    # a file
    mock_directory = {
        "LICENSE.txt": None,
        "envs": {"ignore1": None,
                 "ignore2": None},
        "python.app": None,
        "bin": {"activate": None,
                "conda": None,
                "deactivate": None,
                "testfile": None},
        "testdir1": {"testfile": None,
                     "testdir2": {"testfile": None}},
        "testfile1": None,
    }

    make_mock_directory(tmpdir, mock_directory)

    # walk_prefix has windows_forward_slahes on by default, so we don't need
    # any special-casing there

    answer = {"testfile1", "bin/testfile", "testdir1/testfile",
              "testdir1/testdir2/testfile"}
    if sys.platform != "darwin":
        answer.add("python.app")

    assert walk_prefix(tmpdir.strpath) == answer
Example #2
0
def test_walk_prefix(tmpdir):  # tmpdir is a py.test utility
    # Each directory is a dict whose keys are names. If the value is
    # None, then that key represents a file. If it's another dict, that key is
    # a file
    mock_directory = {
        "LICENSE.txt": None,
        "envs": {"ignore1": None,
                 "ignore2": None},
        "python.app": None,
        "bin": {"activate": None,
                "conda": None,
                "deactivate": None,
                "testfile": None},
        "testdir1": {"testfile": None,
                     "testdir2": {"testfile": None}},
        "testfile1": None,
    }

    make_mock_directory(tmpdir, mock_directory)

    # walk_prefix has windows_forward_slahes on by default, so we don't need
    # any special-casing there

    answer = {"testfile1", "bin/testfile", "testdir1/testfile",
              "testdir1/testdir2/testfile"}
    if sys.platform != "darwin":
        answer.add("python.app")

    assert walk_prefix(tmpdir.strpath) == answer
Example #3
0
def list_package_files(pkg_name=None):
    import os
    import re
    import conda.config as config
    from conda.misc import walk_prefix

    pkgs_dirs = config.pkgs_dirs[0]
    all_dir_names = []
    pattern = re.compile(pkg_name, re.I)

    print('\nINFO: The location for available packages: %s' % (pkgs_dirs))

    for dir in os.listdir(pkgs_dirs):
        ignore_dirs = ['_cache-0.0-x0', 'cache']

        if dir in ignore_dirs:
            continue

        if not os.path.isfile(pkgs_dirs + "/" + dir):
            match = pattern.match(dir)

            if match:
                all_dir_names.append(dir)

    num_of_all_dir_names = len(all_dir_names)
    dir_num_width = len(str(num_of_all_dir_names))

    if num_of_all_dir_names == 0:
        print("\n\tWARN: There is NO '%s' package.\n" % (pkg_name))
        return 1
    elif num_of_all_dir_names >= 2:
        print(
            "\n\tWARN: Ambiguous package name ('%s'), choose one name from below list:\n"
            % (pkg_name))

        num = 0
        for dir in all_dir_names:
            num += 1
            print("\t[ {num:>{width}} / {total} ]: {dir}".format(
                num=num,
                width=dir_num_width,
                total=num_of_all_dir_names,
                dir=dir))
        print("")
        return 1

    full_pkg_name = all_dir_names[0]

    print("INFO: All files belonging to '%s' package:\n" % (full_pkg_name))

    pkg_dir = pkgs_dirs + "/" + full_pkg_name

    ret = walk_prefix(pkg_dir, ignore_predefined_files=False)

    for item in ret:
        print(pkg_dir + "/" + item)
Example #4
0
def list_package_files(pkg_name=None):
    import os
    import re
    import conda.config as config
    from conda.misc import walk_prefix

    pkgs_dirs = config.pkgs_dirs[0]
    all_dir_names = []
    pattern = re.compile(pkg_name, re.I)

    print('\nINFO: The location for available packages: %s' % (pkgs_dirs))

    for dir in os.listdir(pkgs_dirs):
        ignore_dirs = [ '_cache-0.0-x0', 'cache' ]

        if dir in ignore_dirs:
            continue

        if not os.path.isfile(pkgs_dirs+"/"+dir):
            match = pattern.match(dir)

            if match:
                all_dir_names.append(dir)

    num_of_all_dir_names = len(all_dir_names)
    dir_num_width = len(str(num_of_all_dir_names))

    if num_of_all_dir_names == 0:
        print("\n\tWARN: There is NO '%s' package.\n" % (pkg_name))
        return 1
    elif num_of_all_dir_names >= 2:
        print("\n\tWARN: Ambiguous package name ('%s'), choose one name from below list:\n" % (pkg_name))

        num = 0
        for dir in all_dir_names:
            num += 1
            print("\t[ {num:>{width}} / {total} ]: {dir}".format(num=num, width=dir_num_width, total=num_of_all_dir_names, dir=dir))
        print("")
        return 1

    full_pkg_name = all_dir_names[0]

    print("INFO: All files belonging to '%s' package:\n" % (full_pkg_name))

    pkg_dir = pkgs_dirs+"/"+full_pkg_name

    ret = walk_prefix(pkg_dir, ignore_predefined_files=False)

    for item in ret:
        print(pkg_dir+"/"+item)
Example #5
0
def remove_easy_install_pth(files, preserve_egg_dir=False):
    """
    remove the need for easy-install.pth and finally remove easy-install.pth
    itself
    """
    absfiles = [join(config.build_prefix, f) for f in files]
    sp_dir = environ.get_sp_dir()
    for egg_path in glob(join(sp_dir, '*-py*.egg')):
        if isdir(egg_path):
            if preserve_egg_dir or not any(
                    join(egg_path, i) in absfiles
                    for i in walk_prefix(egg_path, False)):
                write_pth(egg_path)
                continue

            print('found egg dir:', egg_path)
            try:
                os.rename(join(egg_path, 'EGG-INFO/PKG-INFO'),
                          egg_path + '-info')
            except OSError:
                pass
            utils.rm_rf(join(egg_path, 'EGG-INFO'))
            for fn in os.listdir(egg_path):
                if fn == '__pycache__':
                    utils.rm_rf(join(egg_path, fn))
                else:
                    # this might be a name-space package
                    # so the package directory already exists
                    # from another installed dependency
                    if os.path.exists(join(sp_dir, fn)):
                        utils.copy_into(join(egg_path, fn), join(sp_dir, fn))
                        utils.rm_rf(join(egg_path, fn))
                    else:
                        os.rename(join(egg_path, fn), join(sp_dir, fn))

        elif isfile(egg_path):
            if not egg_path in absfiles:
                continue
            print('found egg:', egg_path)
            write_pth(egg_path)

    utils.rm_rf(join(sp_dir, 'easy-install.pth'))
Example #6
0
File: post.py Project: Vasyka/hat
def remove_easy_install_pth(files, preserve_egg_dir=False):
    """
    remove the need for easy-install.pth and finally remove easy-install.pth
    itself
    """
    absfiles = [join(config.build_prefix, f) for f in files]
    sp_dir = environ.get_sp_dir()
    for egg_path in glob(join(sp_dir, '*-py*.egg')):
        if isdir(egg_path):
            if preserve_egg_dir or not any(join(egg_path, i) in absfiles for i
                in walk_prefix(egg_path, False, windows_forward_slashes=False)):
                write_pth(egg_path)
                continue

            print('found egg dir:', egg_path)
            try:
                os.rename(join(egg_path, 'EGG-INFO'),
                          egg_path + '-info')
            except OSError:
                pass
            utils.rm_rf(join(egg_path, 'EGG-INFO'))
            for fn in os.listdir(egg_path):
                if fn == '__pycache__':
                    utils.rm_rf(join(egg_path, fn))
                else:
                    # this might be a name-space package
                    # so the package directory already exists
                    # from another installed dependency
                    if os.path.exists(join(sp_dir, fn)):
                        utils.copy_into(join(egg_path, fn), join(sp_dir, fn))
                        utils.rm_rf(join(egg_path, fn))
                    else:
                        os.rename(join(egg_path, fn), join(sp_dir, fn))

        elif isfile(egg_path):
            if not egg_path in absfiles:
                continue
            print('found egg:', egg_path)
            write_pth(egg_path)

    utils.rm_rf(join(sp_dir, 'easy-install.pth'))