<commit_before>"""
Utility functions that map information from environments onto package cache
"""

from os.path import join

import utils
from .environment import Environment, environments
from .cache import PackageInfo


def hard_linked(env):
    """
    Return dictionary of all packages (as PackageInfo instances) that are hard-linked into *env*
    """
    return {p.name: p for p in env._link_type_packages(link_type='hard-link')}

def check_hardlinked_env(env):
    """
    Check all hardlinked packages in env
    """
    return {k: check_hardlinked_pkg(env, v) for k, v in hard_linked(env).items()}


def check_hardlinked_pkg(env, Pkg):
    """
    Check that pkg in cache is correctly (or completely) hardlinked into env.

    Returns a list of improperly hardlinked files.
    """

    bad_linked = []
    for f in Pkg.files:
        src = join(Pkg.path, f)
        tgt = join(env.path, f)
        if not utils.is_hardlinked(src, tgt):
            bad_linked.append(f)
    return bad_linked


def explicitly_installed(env):
    """
    Return list of explicitly installed packages.
    Note that this does not work with root environments
    """

    current_pkgs = set(environ.package_specs)
    
    hist = environ.history

    # Map date to explicitly installed package specs
    _ci = {'install', 'create'}
    installed_specs = {x['date']: set(t.split()[0] 
                        for t in x['specs']) 
                        for x in hist.get_user_requests <commit_msg>use relative import<commit_after>"""
Utility functions that map information from environments onto package cache
"""

from os.path import join

from .environment import Environment, environments
from .cache import PackageInfo
from .utils import is_hardlinked


def hard_linked(env):
    """
    Return dictionary of all packages (as PackageInfo instances) that are hard-linked into *env*
    """
    return {p.name: p for p in env._link_type_packages(link_type='hard-link')}

def check_hardlinked_env(env):
    """
    Check all hardlinked packages in env
    """
    return {k: check_hardlinked_pkg(env, v) for k, v in hard_linked(env).items()}


def check_hardlinked_pkg(env, Pkg):
    """
    Check that pkg in cache is correctly (or completely) hardlinked into env.

    Returns a list of improperly hardlinked files.
    """

    bad_linked = []
    for f in Pkg.files:
        src = join(Pkg.path, f)
        tgt = join(env.path, f)
        if not is_hardlinked(src, tgt):
            bad_linked.append(f)
    return bad_linked


def explicitly_installed(env):
    """
    Return list of explicitly installed packages.
    Note that this does not work with root environments
    """

    current_pkgs = set(environ.package_specs)
    
    hist = environ.history

    # Map date to explicitly installed package specs
    _ci = {'install', 'create'}
    installed_specs = {x['date']: set(t.split()[0] 
                        for t in x['specs']) 
                        for x in hist.get_user_requests 
{'fraction_non_alphanumeric': 0.09345794392523364, 'fraction_numerical': 0.0006675567423230974, 'mean_word_length': 2.8670967741935485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3375467', 'n_tokens_mistral': 882, 'n_tokens_neox': 859, 'n_words': 298}