<commit_before>from __future__ import with_statement

import os, sys, shutil, pkg_resources
from subprocess import Popen, PIPE
from tempfile import NamedTemporaryFile, mkdtemp

def get_spider_list_from_eggfile(eggfile, project, eggrunner='scrapyd.eggrunner'):
    # FIXME: we use a temporary directory here to avoid permissions problems
    # when running as system service, as "scrapy list" command tries to write
    # the scrapy.db sqlite database in current directory
    tmpdir = mkdtemp(prefix='eggs-%s-' % project)
    try:
        with NamedTemporaryFile(suffix='.egg', dir=tmpdir) as f:
            shutil.copyfileobj(eggfile, f)
            f.flush()
            eggfile.seek(0)
            pargs = [sys.executable, '-m', eggrunner, 'list']
            env = os.environ.copy()
            env['SCRAPY_PROJECT'] = project
            env['SCRAPY_EGGFILE'] = f.name
            proc = Popen(pargs, stdout=PIPE, stderr=PIPE, cwd=tmpdir, env=env)
            out, err = proc.communicate()
            if proc.returncode:
                msg = err or out or 'unknown error'
                raise RuntimeError(msg.splitlines()[-1])
            return out.splitlines()
    finally:
        shutil.rmtree(tmpdir)

def activate_egg(eggpath):
    """Activate a Scrapy egg file. This is meant to be used from egg runners
    to activate a Scrapy egg file. Don't use it from other code as it may
    leave unwanted side effects.
    """
    try:
        d = pkg_resources.find_distributions(eggpath).next()
    except StopIteration:<commit_msg>Simplified get_spider_list_from_eggfile() function now that it doesn't need to chdir to a custom directory (Scrapy now works when it's unable to create the SQLite database)<commit_after>from __future__ import with_statement

import os, sys, shutil, pkg_resources
from subprocess import Popen, PIPE
from tempfile import NamedTemporaryFile

def get_spider_list_from_eggfile(eggfile, project, eggrunner='scrapyd.eggrunner'):
    with NamedTemporaryFile(suffix='.egg') as f:
        shutil.copyfileobj(eggfile, f)
        f.flush()
        eggfile.seek(0)
        pargs = [sys.executable, '-m', eggrunner, 'list']
        env = os.environ.copy()
        env['SCRAPY_PROJECT'] = project
        env['SCRAPY_EGGFILE'] = f.name
        proc = Popen(pargs, stdout=PIPE, stderr=PIPE, env=env)
        out, err = proc.communicate()
        if proc.returncode:
            msg = err or out or 'unknown error'
            raise RuntimeError(msg.splitlines()[-1])
        return out.splitlines()

def activate_egg(eggpath):
    """Activate a Scrapy egg file. This is meant to be used from egg runners
    to activate a Scrapy egg file. Don't use it from other code as it may
    leave unwanted side effects.
    """
    try:
        d = pkg_resources.find_distributions(eggpath).next()
    except StopIteration:
{'fraction_non_alphanumeric': 0.09154929577464789, 'fraction_numerical': 0.0014084507042253522, 'mean_word_length': 2.929460580912863, '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': '7418995', 'n_tokens_mistral': 904, 'n_tokens_neox': 867, 'n_words': 266}