Fix importlib.metadata.files workaround

Some distributions, such as Fedora, do not install the RECORDS file as
part of a package's dist-info. As a result importlib.metadata.files will
return None.

Use the workaround for these cases as well.

Signed-off-by: Felix Kaechele <felix@kaechele.ca>
This commit is contained in:
Felix Kaechele 2023-05-23 17:18:46 -04:00
parent caf654366c
commit ce6daff12f
1 changed files with 12 additions and 12 deletions

View File

@ -16,19 +16,19 @@ def schema_filename():
''' '''
Path to the installed YAML configuration schema file, used to validate and parse the Path to the installed YAML configuration schema file, used to validate and parse the
configuration. configuration.
Raise FileNotFoundError when the schema path does not exist.
''' '''
try:
return next( files = importlib_metadata.files('borgmatic')
str(path.locate()) if files is not None:
for path in importlib_metadata.files('borgmatic') try:
if path.match('config/schema.yaml') return next(str(path.locate()) for path in files if path.match('config/schema.yaml'))
) except StopIteration:
except StopIteration: # schema not found in package, fall through to the approach below
# If the schema wasn't found in the package's files, this is probably a pip editable pass
# install, so try a different approach to get the schema.
return os.path.join(os.path.dirname(borgmatic.config.__file__), 'schema.yaml') # If the schema wasn't found in the package's files, this is probably a pip editable
# install, so try a different approach to get the schema.
return os.path.join(os.path.dirname(borgmatic.config.__file__), 'schema.yaml')
def format_json_error_path_element(path_element): def format_json_error_path_element(path_element):