Remove support for override settings with `SCRAPY_` environment variables

This commit is contained in:
Laerte Pereira 2022-11-22 09:38:45 -03:00
parent aac6103179
commit 8e0025f53d
No known key found for this signature in database
GPG Key ID: BB69B5C731BB8A80
2 changed files with 12 additions and 23 deletions

View File

@ -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

View File

@ -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