mirror of
https://github.com/jazzband/django-configurations.git
synced 2026-03-16 22:20:27 +00:00
Merge pull request #383 from kloczek/master
really drop support for python<=3.7
This commit is contained in:
commit
e1091160b1
5 changed files with 30 additions and 30 deletions
|
|
@ -66,7 +66,7 @@ class ConfigurationBase(type):
|
|||
return super().__new__(cls, name, bases, attrs)
|
||||
|
||||
def __repr__(self):
|
||||
return "<Configuration '{0}.{1}'>".format(self.__module__,
|
||||
return "<Configuration '{}.{}'>".format(self.__module__,
|
||||
self.__name__)
|
||||
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ class Configuration(metaclass=ConfigurationBase):
|
|||
|
||||
# now check if we can access the file since we know we really want to
|
||||
try:
|
||||
with open(dotenv, 'r') as f:
|
||||
with open(dotenv) as f:
|
||||
content = f.read()
|
||||
except OSError as e:
|
||||
raise ImproperlyConfigured("Couldn't read .env file "
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class ConfigurationImporter:
|
|||
self.announce()
|
||||
|
||||
def __repr__(self):
|
||||
return "<ConfigurationImporter for '{0}.{1}'>".format(self.module,
|
||||
return "<ConfigurationImporter for '{}.{}'>".format(self.module,
|
||||
self.name)
|
||||
|
||||
@property
|
||||
|
|
@ -122,8 +122,8 @@ class ConfigurationImporter:
|
|||
if (self.argv[1] == 'runserver'
|
||||
and os.environ.get('RUN_MAIN') == 'true'):
|
||||
|
||||
message = ("django-configurations version {0}, using "
|
||||
"configuration {1}".format(__version__ or "",
|
||||
message = ("django-configurations version {}, using "
|
||||
"configuration {}".format(__version__ or "",
|
||||
self.name))
|
||||
self.logger.debug(stylize(message))
|
||||
|
||||
|
|
@ -151,13 +151,13 @@ class ConfigurationLoader:
|
|||
sys.modules[fullname] = mod
|
||||
self.spec.loader.exec_module(mod)
|
||||
|
||||
cls_path = '{0}.{1}'.format(mod.__name__, self.name)
|
||||
cls_path = f'{mod.__name__}.{self.name}'
|
||||
|
||||
try:
|
||||
cls = getattr(mod, self.name)
|
||||
except AttributeError as err: # pragma: no cover
|
||||
reraise(err, "Couldn't find configuration '{0}' "
|
||||
"in module '{1}'".format(self.name,
|
||||
reraise(err, "Couldn't find configuration '{}' "
|
||||
"in module '{}'".format(self.name,
|
||||
mod.__package__))
|
||||
try:
|
||||
cls.pre_setup()
|
||||
|
|
@ -174,11 +174,11 @@ class ConfigurationLoader:
|
|||
continue
|
||||
setattr(mod, name, value)
|
||||
|
||||
setattr(mod, 'CONFIGURATION', '{0}.{1}'.format(fullname,
|
||||
setattr(mod, 'CONFIGURATION', '{}.{}'.format(fullname,
|
||||
self.name))
|
||||
cls.post_setup()
|
||||
|
||||
except Exception as err:
|
||||
reraise(err, "Couldn't setup configuration '{0}'".format(cls_path))
|
||||
reraise(err, f"Couldn't setup configuration '{cls_path}'")
|
||||
|
||||
return mod
|
||||
|
|
|
|||
|
|
@ -29,21 +29,21 @@ def import_by_path(dotted_path, error_prefix=''):
|
|||
try:
|
||||
module_path, class_name = dotted_path.rsplit('.', 1)
|
||||
except ValueError:
|
||||
raise ImproperlyConfigured("{0}{1} doesn't look like "
|
||||
raise ImproperlyConfigured("{}{} doesn't look like "
|
||||
"a module path".format(error_prefix,
|
||||
dotted_path))
|
||||
try:
|
||||
module = import_module(module_path)
|
||||
except ImportError as err:
|
||||
msg = '{0}Error importing module {1}: "{2}"'.format(error_prefix,
|
||||
msg = '{}Error importing module {}: "{}"'.format(error_prefix,
|
||||
module_path,
|
||||
err)
|
||||
raise ImproperlyConfigured(msg).with_traceback(sys.exc_info()[2])
|
||||
try:
|
||||
attr = getattr(module, class_name)
|
||||
except AttributeError:
|
||||
raise ImproperlyConfigured('{0}Module "{1}" does not define a '
|
||||
'"{2}" attribute/class'.format(error_prefix,
|
||||
raise ImproperlyConfigured('{}Module "{}" does not define a '
|
||||
'"{}" attribute/class'.format(error_prefix,
|
||||
module_path,
|
||||
class_name))
|
||||
return attr
|
||||
|
|
@ -61,7 +61,7 @@ def reraise(exc, prefix=None, suffix=None):
|
|||
suffix = ''
|
||||
elif not (suffix.startswith('(') and suffix.endswith(')')):
|
||||
suffix = '(' + suffix + ')'
|
||||
exc.args = ('{0} {1} {2}'.format(prefix, args[0], suffix),) + args[1:]
|
||||
exc.args = (f'{prefix} {args[0]} {suffix}',) + args[1:]
|
||||
raise exc
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class Value:
|
|||
else:
|
||||
environ_name = name.upper()
|
||||
if self.environ_prefix:
|
||||
environ_name = '{0}_{1}'.format(self.environ_prefix, environ_name)
|
||||
environ_name = f'{self.environ_prefix}_{environ_name}'
|
||||
return environ_name
|
||||
|
||||
def setup(self, name):
|
||||
|
|
@ -102,8 +102,8 @@ class Value:
|
|||
if full_environ_name in os.environ:
|
||||
value = self.to_python(os.environ[full_environ_name])
|
||||
elif self.environ_required:
|
||||
raise ValueError('Value {0!r} is required to be set as the '
|
||||
'environment variable {1!r}'
|
||||
raise ValueError('Value {!r} is required to be set as the '
|
||||
'environment variable {!r}'
|
||||
.format(name, full_environ_name))
|
||||
self.value = value
|
||||
return value
|
||||
|
|
@ -128,7 +128,7 @@ class BooleanValue(Value):
|
|||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if self.default not in (True, False):
|
||||
raise ValueError('Default value {0!r} is not a '
|
||||
raise ValueError('Default value {!r} is not a '
|
||||
'boolean value'.format(self.default))
|
||||
|
||||
def to_python(self, value):
|
||||
|
|
@ -139,7 +139,7 @@ class BooleanValue(Value):
|
|||
return False
|
||||
else:
|
||||
raise ValueError('Cannot interpret '
|
||||
'boolean value {0!r}'.format(value))
|
||||
'boolean value {!r}'.format(value))
|
||||
|
||||
|
||||
class CastingMixin:
|
||||
|
|
@ -152,12 +152,12 @@ class CastingMixin:
|
|||
try:
|
||||
self._caster = import_string(self.caster)
|
||||
except ImportError as err:
|
||||
msg = "Could not import {!r}".format(self.caster)
|
||||
msg = f"Could not import {self.caster!r}"
|
||||
raise ImproperlyConfigured(msg) from err
|
||||
elif callable(self.caster):
|
||||
self._caster = self.caster
|
||||
else:
|
||||
error = 'Cannot use caster of {0} ({1!r})'.format(self,
|
||||
error = 'Cannot use caster of {} ({!r})'.format(self,
|
||||
self.caster)
|
||||
raise ValueError(error)
|
||||
try:
|
||||
|
|
@ -345,13 +345,13 @@ class ValidationMixin:
|
|||
try:
|
||||
self._validator = import_string(self.validator)
|
||||
except ImportError as err:
|
||||
msg = "Could not import {!r}".format(self.validator)
|
||||
msg = f"Could not import {self.validator!r}"
|
||||
raise ImproperlyConfigured(msg) from err
|
||||
elif callable(self.validator):
|
||||
self._validator = self.validator
|
||||
else:
|
||||
raise ValueError('Cannot use validator of '
|
||||
'{0} ({1!r})'.format(self, self.validator))
|
||||
'{} ({!r})'.format(self, self.validator))
|
||||
if self.default:
|
||||
self.to_python(self.default)
|
||||
|
||||
|
|
@ -397,7 +397,7 @@ class PathValue(Value):
|
|||
value = super().setup(name)
|
||||
value = os.path.expanduser(value)
|
||||
if self.check_exists and not os.path.exists(value):
|
||||
raise ValueError('Path {0!r} does not exist.'.format(value))
|
||||
raise ValueError(f'Path {value!r} does not exist.')
|
||||
return os.path.abspath(value)
|
||||
|
||||
|
||||
|
|
@ -414,7 +414,7 @@ class SecretValue(Value):
|
|||
def setup(self, name):
|
||||
value = super().setup(name)
|
||||
if not value:
|
||||
raise ValueError('Secret value {0!r} is not set'.format(name))
|
||||
raise ValueError(f'Secret value {name!r} is not set')
|
||||
return value
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class ValueTests(TestCase):
|
|||
|
||||
def test_value_with_default(self):
|
||||
value = Value('default', environ=False)
|
||||
self.assertEqual(type(value), type('default'))
|
||||
self.assertEqual(type(value), str)
|
||||
self.assertEqual(value, 'default')
|
||||
self.assertEqual(str(value), 'default')
|
||||
|
||||
|
|
@ -44,17 +44,17 @@ class ValueTests(TestCase):
|
|||
with env(DJANGO_TEST='override'):
|
||||
self.assertEqual(value.setup('TEST'), 'default')
|
||||
value = Value(environ_name='TEST')
|
||||
self.assertEqual(type(value), type('override'))
|
||||
self.assertEqual(type(value), str)
|
||||
self.assertEqual(value, 'override')
|
||||
self.assertEqual(str(value), 'override')
|
||||
self.assertEqual('{0}'.format(value), 'override')
|
||||
self.assertEqual(f'{value}', 'override')
|
||||
self.assertEqual('%s' % value, 'override')
|
||||
|
||||
value = Value(environ_name='TEST', late_binding=True)
|
||||
self.assertEqual(type(value), Value)
|
||||
self.assertEqual(value.value, 'override')
|
||||
self.assertEqual(str(value), 'override')
|
||||
self.assertEqual('{0}'.format(value), 'override')
|
||||
self.assertEqual(f'{value}', 'override')
|
||||
self.assertEqual('%s' % value, 'override')
|
||||
|
||||
self.assertEqual(repr(value), repr('override'))
|
||||
|
|
|
|||
Loading…
Reference in a new issue