Remove dependency on os.environ from default settings

Avoid loading settings from environment in scrapy core.
Instead it's better to populate them from the starting
shell or an embedding script.
This commit is contained in:
nyov 2016-03-01 07:12:19 +00:00
parent cc06b6b1f6
commit 2240f00a13
5 changed files with 20 additions and 17 deletions

View File

@ -291,12 +291,12 @@ edit
* Syntax: ``scrapy edit <spider>``
* Requires project: *yes*
Edit the given spider using the editor defined in the :setting:`EDITOR`
setting.
Edit the given spider using the editor defined in the ``EDITOR`` environment
variable or (if unset) the :setting:`EDITOR` setting.
This command is provided only as a convenience shortcut for the most common
case, the developer is of course free to choose any tool or IDE to write and
debug his spiders.
debug spiders.
Usage example::

View File

@ -635,11 +635,11 @@ Setting :setting:`DUPEFILTER_DEBUG` to ``True`` will make it log all duplicate r
EDITOR
------
Default: `depends on the environment`
Default: ``vi`` (on Unix systems) or the IDLE editor (on Windows)
The editor to use for editing spiders with the :command:`edit` command. It
defaults to the ``EDITOR`` environment variable, if set. Otherwise, it defaults
to ``vi`` (on Unix systems) or the IDLE editor (on Windows).
The editor to use for editing spiders with the :command:`edit` command.
Additionally, if the ``EDITOR`` environment variable is set, the :command:`edit`
command will prefer it over the default setting.
.. setting:: EXTENSIONS

View File

@ -1,5 +1,5 @@
from __future__ import print_function
import sys
import sys, os
import optparse
import cProfile
import inspect
@ -106,6 +106,12 @@ def execute(argv=None, settings=None):
if settings is None:
settings = get_project_settings()
# set EDITOR from environment if available
try:
editor = os.environ['EDITOR']
except KeyError: pass
else:
settings['EDITOR'] = editor
check_deprecated_settings(settings)
# --- backwards compatibility for scrapy.conf.settings singleton ---

View File

@ -3,6 +3,7 @@ import sys, os
from scrapy.commands import ScrapyCommand
from scrapy.exceptions import UsageError
class Command(ScrapyCommand):
requires_project = True
@ -15,7 +16,8 @@ class Command(ScrapyCommand):
return "Edit spider"
def long_desc(self):
return "Edit a spider using the editor defined in EDITOR setting"
return ("Edit a spider using the editor defined in the EDITOR environment"
" variable or else the EDITOR setting")
def _err(self, msg):
sys.stderr.write(msg + os.linesep)

View File

@ -13,7 +13,6 @@ Scrapy developers, if you add a setting here remember to:
"""
import os
import sys
from importlib import import_module
from os.path import join, abspath, dirname
@ -111,13 +110,9 @@ DOWNLOADER_STATS = True
DUPEFILTER_CLASS = 'scrapy.dupefilters.RFPDupeFilter'
try:
EDITOR = os.environ['EDITOR']
except KeyError:
if sys.platform == 'win32':
EDITOR = '%s -m idlelib.idle'
else:
EDITOR = 'vi'
EDITOR = 'vi'
if sys.platform == 'win32':
EDITOR = '%s -m idlelib.idle'
EXTENSIONS = {}