From 1134a9cab055969b3232a16037d16e5ab93759f0 Mon Sep 17 00:00:00 2001 From: nyov Date: Tue, 24 Mar 2015 03:12:58 +0000 Subject: [PATCH] config: look in ~/.config/scrapy.cfg as well --- docs/topics/commands.rst | 21 +++++++++++++++++++++ docs/topics/settings.rst | 2 ++ scrapy/utils/conf.py | 3 +++ 3 files changed, 26 insertions(+) diff --git a/docs/topics/commands.rst b/docs/topics/commands.rst index 5c0de0d6d..27d0655ef 100644 --- a/docs/topics/commands.rst +++ b/docs/topics/commands.rst @@ -13,6 +13,27 @@ just call "commands" or "Scrapy commands". The Scrapy tool provides several commands, for multiple purposes, and each one accepts a different set of arguments and options. +Configuration settings +====================== + +Scrapy will look for configuration parameters in ini-style ``scrapy.cfg`` files +in standard locations: + +1. ``/etc/scrapy.cfg`` or ``c:\scrapy\scrapy.cfg`` (system-wide), +2. ``~/.config/scrapy.cfg`` (``$XDG_CONFIG_HOME``) and ``~/.scrapy.cfg`` (``$HOME``) + for global (user-wide) settings, and +3. ``scrapy.cfg`` inside a scrapy project's root (see next section). + +Settings from these files are merged in the listed order of preference: +user-defined values have higher priority than system-wide defaults +and project-wide settings will override all others, when defined. + +Scrapy also understands, and can be configured through, a number of environment +variables. Currently these are: + +* ``SCRAPY_SETTINGS_MODULE`` (See :ref:`topics-settings-module-envvar`) +* ``SCRAPY_PROJECT`` + .. _topics-project-structure: Default structure of Scrapy projects diff --git a/docs/topics/settings.rst b/docs/topics/settings.rst index 5e11e473f..0f41c427b 100644 --- a/docs/topics/settings.rst +++ b/docs/topics/settings.rst @@ -16,6 +16,8 @@ project (in case you have many). For a list of available built-in settings see: :ref:`topics-settings-ref`. +.. _topics-settings-module-envvar: + Designating the settings ======================== diff --git a/scrapy/utils/conf.py b/scrapy/utils/conf.py index caa80a5a1..b883923b9 100644 --- a/scrapy/utils/conf.py +++ b/scrapy/utils/conf.py @@ -63,7 +63,10 @@ def get_config(use_closest=True): def get_sources(use_closest=True): + xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or \ + os.path.expanduser('~/.config') sources = ['/etc/scrapy.cfg', r'c:\scrapy\scrapy.cfg', + xdg_config_home + '/scrapy.cfg', os.path.expanduser('~/.scrapy.cfg')] if use_closest: sources.append(closest_scrapy_cfg())