Forráskód Böngészése

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

Dan Helfman 2 éve
szülő
commit
0b397a5bf9
3 módosított fájl, 8 hozzáadás és 4 törlés
  1. 2 0
      NEWS
  2. 4 1
      borgmatic/config/validate.py
  3. 2 3
      tests/unit/config/test_validate.py

+ 2 - 0
NEWS

@@ -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.
 

+ 4 - 1
borgmatic/config/validate.py

@@ -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):

+ 2 - 3
tests/unit/config/test_validate.py

@@ -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():