mirror of https://github.com/scrapy/scrapy.git
Merge pull request #5724 from Laerte/remove-scrapy_-env-variables-override
Remove support for override settings with `SCRAPY_` environment variables
This commit is contained in:
commit
b9c8db13c2
|
|
@ -6,7 +6,7 @@ from os.path import join, dirname, abspath, isabs, exists
|
|||
|
||||
from scrapy.utils.conf import closest_scrapy_cfg, get_config, init_env
|
||||
from scrapy.settings import Settings
|
||||
from scrapy.exceptions import NotConfigured, ScrapyDeprecationWarning
|
||||
from scrapy.exceptions import NotConfigured
|
||||
|
||||
|
||||
ENVVAR = 'SCRAPY_SETTINGS_MODULE'
|
||||
|
|
@ -67,23 +67,16 @@ def get_project_settings():
|
|||
if settings_module_path:
|
||||
settings.setmodule(settings_module_path, priority='project')
|
||||
|
||||
scrapy_envvars = {k[7:]: v for k, v in os.environ.items() if
|
||||
k.startswith('SCRAPY_')}
|
||||
valid_envvars = {
|
||||
'CHECK',
|
||||
'PROJECT',
|
||||
'PYTHON_SHELL',
|
||||
'SETTINGS_MODULE',
|
||||
}
|
||||
setting_envvars = {k for k in scrapy_envvars if k not in valid_envvars}
|
||||
if setting_envvars:
|
||||
setting_envvar_list = ', '.join(sorted(setting_envvars))
|
||||
warnings.warn(
|
||||
'Use of environment variables prefixed with SCRAPY_ to override '
|
||||
'settings is deprecated. The following environment variables are '
|
||||
f'currently defined: {setting_envvar_list}',
|
||||
ScrapyDeprecationWarning
|
||||
)
|
||||
|
||||
scrapy_envvars = {k[7:]: v for k, v in os.environ.items() if
|
||||
k.startswith('SCRAPY_') and k.replace('SCRAPY_', '') in valid_envvars}
|
||||
|
||||
settings.setdict(scrapy_envvars, priority='project')
|
||||
|
||||
return settings
|
||||
|
|
|
|||
|
|
@ -31,10 +31,6 @@ class CmdlineTest(unittest.TestCase):
|
|||
self.assertEqual(self._execute('settings', '--get', 'TEST1', '-s',
|
||||
'TEST1=override'), 'override')
|
||||
|
||||
def test_override_settings_using_envvar(self):
|
||||
self.env['SCRAPY_TEST1'] = 'override'
|
||||
self.assertEqual(self._execute('settings', '--get', 'TEST1'), 'override')
|
||||
|
||||
def test_profiling(self):
|
||||
path = tempfile.mkdtemp()
|
||||
filename = os.path.join(path, 'res.prof')
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@ import shutil
|
|||
import contextlib
|
||||
import warnings
|
||||
|
||||
from pytest import warns
|
||||
|
||||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
from scrapy.utils.project import data_path, get_project_settings
|
||||
|
||||
|
||||
|
|
@ -80,10 +77,10 @@ class GetProjectSettingsTestCase(unittest.TestCase):
|
|||
envvars = {
|
||||
'SCRAPY_FOO': 'bar',
|
||||
}
|
||||
with warns(ScrapyDeprecationWarning, match=': FOO') as record:
|
||||
with set_env(**envvars):
|
||||
get_project_settings()
|
||||
assert len(record) == 1
|
||||
with set_env(**envvars):
|
||||
settings = get_project_settings()
|
||||
|
||||
assert settings.get("SCRAPY_FOO") is None
|
||||
|
||||
def test_valid_and_invalid_envvars(self):
|
||||
value = 'tests.test_cmdline.settings'
|
||||
|
|
@ -91,8 +88,7 @@ class GetProjectSettingsTestCase(unittest.TestCase):
|
|||
'SCRAPY_FOO': 'bar',
|
||||
'SCRAPY_SETTINGS_MODULE': value,
|
||||
}
|
||||
with warns(ScrapyDeprecationWarning, match=': FOO') as record:
|
||||
with set_env(**envvars):
|
||||
settings = get_project_settings()
|
||||
assert len(record) == 1
|
||||
with set_env(**envvars):
|
||||
settings = get_project_settings()
|
||||
assert settings.get('SETTINGS_MODULE') == value
|
||||
assert settings.get('SCRAPY_FOO') is None
|
||||
|
|
|
|||
Loading…
Reference in New Issue