Skip to content

Commit

Permalink
Merge pull request #383 from kloczek/master
Browse files Browse the repository at this point in the history
really drop support for python<=3.7
  • Loading branch information
uhurusurfa authored Sep 27, 2024
2 parents 880484d + 6dc2340 commit e109116
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions configurations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __new__(cls, name, bases, attrs):
return super().__new__(cls, name, bases, attrs)

def __repr__(self):
return "<Configuration '{0}.{1}'>".format(self.__module__,
return "<Configuration '{}.{}'>".format(self.__module__,
self.__name__)


Expand Down Expand Up @@ -115,7 +115,7 @@ def load_dotenv(cls):

# 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 "
Expand Down
16 changes: 8 additions & 8 deletions configurations/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, check_options=False):
self.announce()

def __repr__(self):
return "<ConfigurationImporter for '{0}.{1}'>".format(self.module,
return "<ConfigurationImporter for '{}.{}'>".format(self.module,
self.name)

@property
Expand Down Expand Up @@ -122,8 +122,8 @@ def stylize(text):
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))

Expand Down Expand Up @@ -151,13 +151,13 @@ def load_module(self, fullname):
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()
Expand All @@ -174,11 +174,11 @@ def load_module(self, fullname):
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
10 changes: 5 additions & 5 deletions configurations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
22 changes: 11 additions & 11 deletions configurations/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def full_environ_name(self, name):
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):
Expand All @@ -102,8 +102,8 @@ def setup(self, name):
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
Expand All @@ -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):
Expand All @@ -139,7 +139,7 @@ def to_python(self, value):
return False
else:
raise ValueError('Cannot interpret '
'boolean value {0!r}'.format(value))
'boolean value {!r}'.format(value))


class CastingMixin:
Expand All @@ -152,12 +152,12 @@ def __init__(self, *args, **kwargs):
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:
Expand Down Expand Up @@ -345,13 +345,13 @@ def __init__(self, *args, **kwargs):
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)

Expand Down Expand Up @@ -397,7 +397,7 @@ def setup(self, name):
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)


Expand All @@ -414,7 +414,7 @@ def __init__(self, *args, **kwargs):
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


Expand Down
8 changes: 4 additions & 4 deletions tests/test_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -44,17 +44,17 @@ def test_value_with_default_and_late_binding(self):
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'))
Expand Down

0 comments on commit e109116

Please sign in to comment.