Skip to content

Commit

Permalink
platonify fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhayes777 committed Jan 30, 2024
1 parent 833821c commit 1f4de58
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 44 deletions.
29 changes: 6 additions & 23 deletions autoconf/directory_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import os
from abc import abstractmethod, ABC
from pathlib import Path

import yaml

from autoconf import exc


Expand Down Expand Up @@ -65,12 +63,12 @@ def _getitem(self, item):

def items(self):
for key in self.d:
yield key, self[key]
yield (key, self[key])


class YAMLConfig(AbstractConfig):
def __init__(self, path):
with open(path) as f:
with open(path, encoding="utf-8") as f:
self._dict = yaml.safe_load(f)

def _getitem(self, item):
Expand All @@ -90,9 +88,8 @@ def __init__(self, path, parser, section):
self.parser = parser

def keys(self):
with open(self.path) as f:
with open(self.path, encoding="utf-8") as f:
string = f.read()

lines = string.split("\n")
is_section = False
for line in lines:
Expand Down Expand Up @@ -142,11 +139,7 @@ def keys(self):
return self.parser.sections()

def _getitem(self, item):
return SectionConfig(
self.path,
self.parser,
item,
)
return SectionConfig(self.path, self.parser, item)


class RecursiveConfig(AbstractConfig):
Expand Down Expand Up @@ -207,20 +200,10 @@ def for_class_and_suffix_path(self, cls, path):
return config.for_class_and_suffix_path(cls, path)
except KeyError:
pass
directories = " ".join(str(config.directory) for config in self.prior_configs)

directories = " ".join((str(config.directory) for config in self.prior_configs))
print()

raise exc.ConfigException(
f"No prior config found for class: \n\n"
f"{cls.__name__} \n\n"
f"For parameter name and path: \n\n "
f"{'.'.join(path)} \n\n "
f"In any of the following directories:\n\n"
f"{directories}\n\n"
f"Either add configuration for the parameter or a type annotation for a class with valid configuration.\n\n"
f"The following readthedocs page explains prior configuration files in PyAutoFit and will help you fix "
f"the error https://pyautofit.readthedocs.io/en/latest/general/adding_a_model_component.html"
f"No prior config found for class: \n\n{cls.__name__} \n\nFor parameter name and path: \n\n {'.'.join(path)} \n\n In any of the following directories:\n\n{directories}\n\nEither add configuration for the parameter or a type annotation for a class with valid configuration.\n\nThe following readthedocs page explains prior configuration files in PyAutoFit and will help you fix the error https://pyautofit.readthedocs.io/en/latest/general/adding_a_model_component.html"
)


Expand Down
42 changes: 21 additions & 21 deletions autoconf/tools/decorators.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
class CachedProperty(object):
"""
A property that is only computed once per instance and then replaces
itself with an ordinary attribute. Deleting the attribute resets the
property.
Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76
"""

def __init__(self, func):
self.func = func

def __get__(self, obj, cls):
if obj is None:
return self
if self.func.__name__ not in obj.__dict__:
obj.__dict__[self.func.__name__] = self.func(obj)
return obj.__dict__[self.func.__name__]


cached_property = CachedProperty
class CachedProperty:
"""
A property that is only computed once per instance and then replaces
itself with an ordinary attribute. Deleting the attribute resets the
property.
Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76
"""

def __init__(self, func):
self.func = func

def __get__(self, obj, cls):
if obj is None:
return self
if self.func.__name__ not in obj.__dict__:
obj.__dict__[self.func.__name__] = self.func(obj)
return obj.__dict__[self.func.__name__]


cached_property = CachedProperty

0 comments on commit 1f4de58

Please sign in to comment.