ソースを参照

Drop importlib_metadata entirely

The fallback option using the dirname of the config module location
seems to be more robust in a number of cases.

Signed-off-by: Felix Kaechele <felix@kaechele.ca>
Felix Kaechele 2 年 前
コミット
15cabb93ca
2 ファイル変更1 行追加34 行削除
  1. 0 16
      borgmatic/config/validate.py
  2. 1 18
      tests/unit/config/test_validate.py

+ 0 - 16
borgmatic/config/validate.py

@@ -3,11 +3,6 @@ import os
 import jsonschema
 import ruamel.yaml
 
-try:
-    import importlib_metadata
-except ModuleNotFoundError:  # pragma: nocover
-    import importlib.metadata as importlib_metadata
-
 import borgmatic.config
 from borgmatic.config import environment, load, normalize, override
 
@@ -17,17 +12,6 @@ def schema_filename():
     Path to the installed YAML configuration schema file, used to validate and parse the
     configuration.
     '''
-
-    files = importlib_metadata.files('borgmatic')
-    if files is not None:
-        try:
-            return next(str(path.locate()) for path in files if path.match('config/schema.yaml'))
-        except StopIteration:
-            # schema not found in package, fall through to the approach below
-            pass
-
-    # 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')
 
 

+ 1 - 18
tests/unit/config/test_validate.py

@@ -5,24 +5,7 @@ from borgmatic.config import validate as module
 
 
 def test_schema_filename_finds_schema_path():
-    schema_path = '/var/borgmatic/config/schema.yaml'
-
-    flexmock(module.importlib_metadata).should_receive('files').and_return(
-        flexmock(match=lambda path: False, locate=lambda: None),
-        flexmock(match=lambda path: True, locate=lambda: schema_path),
-        flexmock(match=lambda path: False, locate=lambda: None),
-    )
-
-    assert module.schema_filename() == schema_path
-
-
-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),
-    )
-
-    assert module.schema_filename().endswith('/borgmatic/config/schema.yaml')
+    module.schema_filename().endswith('/borgmatic/config/schema.yaml')
 
 
 def test_format_json_error_path_element_formats_array_index():