Fix borgmatic error when not finding the configuration schema for certain "pip install --editable" development installs (#687).

This commit is contained in:
Dan Helfman 2023-04-30 16:24:10 -07:00
parent a60d7fd173
commit 0b397a5bf9
3 changed files with 8 additions and 4 deletions

2
NEWS
View file

@ -10,6 +10,8 @@
* #682: Fix "source_directories_must_exist" option to expand globs and tildes in source directories.
* #684: Rename "master" development branch to "main" to use more inclusive language. You'll need to
update your development checkouts accordingly.
* #687: Fix borgmatic error when not finding the configuration schema for certain "pip install
--editable" development installs.
* Run "borgmatic borg" action without capturing output so interactive prompts and flags like
"--progress" still work.

View file

@ -8,6 +8,7 @@ try:
except ModuleNotFoundError: # pragma: nocover
import importlib.metadata as importlib_metadata
import borgmatic.config
from borgmatic.config import environment, load, normalize, override
@ -25,7 +26,9 @@ def schema_filename():
if path.match('config/schema.yaml')
)
except StopIteration:
raise FileNotFoundError('Configuration file schema could not be found')
# 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):

View file

@ -16,14 +16,13 @@ def test_schema_filename_finds_schema_path():
assert module.schema_filename() == schema_path
def test_schema_filename_with_missing_schema_path_raises():
def test_schema_filename_with_missing_schema_path_in_package_still_finds_it_in_config_directory():
flexmock(module.importlib_metadata).should_receive('files').and_return(
flexmock(match=lambda path: False, locate=lambda: None),
flexmock(match=lambda path: False, locate=lambda: None),
)
with pytest.raises(FileNotFoundError):
assert module.schema_filename()
assert module.schema_filename().endswith('/borgmatic/config/schema.yaml')
def test_format_json_error_path_element_formats_array_index():