scrapy.utils.conf.closest_scrapy_cfg

Here are the examples of the python api scrapy.utils.conf.closest_scrapy_cfg taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

3 Source : project.py
with MIT License
from autofelix

def inside_project():
    scrapy_module = os.environ.get('SCRAPY_SETTINGS_MODULE')
    if scrapy_module is not None:
        try:
            import_module(scrapy_module)
        except ImportError as exc:
            warnings.warn("Cannot import scrapy settings module %s: %s" % (scrapy_module, exc))
        else:
            return True
    return bool(closest_scrapy_cfg())


def project_data_dir(project='default'):

3 Source : project.py
with MIT License
from autofelix

def project_data_dir(project='default'):
    """Return the current project data dir, creating it if it doesn't exist"""
    if not inside_project():
        raise NotConfigured("Not inside a project")
    cfg = get_config()
    if cfg.has_option(DATADIR_CFG_SECTION, project):
        d = cfg.get(DATADIR_CFG_SECTION, project)
    else:
        scrapy_cfg = closest_scrapy_cfg()
        if not scrapy_cfg:
            raise NotConfigured("Unable to find scrapy.cfg file to infer project data dir")
        d = abspath(join(dirname(scrapy_cfg), '.scrapy'))
    if not exists(d):
        os.makedirs(d)
    return d


def data_path(path, createdir=False):

3 Source : utils.py
with BSD 3-Clause "New" or "Revised" License
from scrapinghub

def get_project_dir():
    closest_cfg = closest_scrapy_cfg()
    if closest_cfg:
        return os.path.dirname(closest_cfg)

    init_env()
    scrapy_module = os.environ.get('SCRAPY_SETTINGS_MODULE')
    if scrapy_module is None:
        return None

    try:
        module = import_module(scrapy_module)
        return os.path.dirname(os.path.dirname(module.__file__))
    except ImportError:
        return None


def get_spider_class(spider_name, project_settings):