From f39cea4abf10c4407b96fe4d48ba9eecaa5a147e Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 7 Nov 2023 10:17:16 -0800 Subject: [PATCH] Remove additional Python 3.7-isms (#784). --- borgmatic/actions/create.py | 8 ++------ borgmatic/commands/borgmatic.py | 8 ++------ test_requirements.txt | 11 ++++------- tests/unit/actions/test_create.py | 4 ++-- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/borgmatic/actions/create.py b/borgmatic/actions/create.py index 91961e3..8ca1e3b 100644 --- a/borgmatic/actions/create.py +++ b/borgmatic/actions/create.py @@ -1,12 +1,8 @@ +import importlib.metadata import json import logging import os -try: - import importlib_metadata -except ModuleNotFoundError: # pragma: nocover - import importlib.metadata as importlib_metadata - import borgmatic.borg.create import borgmatic.borg.state import borgmatic.config.validate @@ -39,7 +35,7 @@ def create_borgmatic_manifest(config, config_paths, dry_run): with open(borgmatic_manifest_path, 'w') as config_list_file: json.dump( { - 'borgmatic_version': importlib_metadata.version('borgmatic'), + 'borgmatic_version': importlib.metadata.version('borgmatic'), 'config_paths': config_paths, }, config_list_file, diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index ee03dde..ab32aa8 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -1,4 +1,5 @@ import collections +import importlib.metadata import json import logging import os @@ -9,11 +10,6 @@ from subprocess import CalledProcessError import colorama -try: - import importlib_metadata -except ModuleNotFoundError: # pragma: nocover - import importlib.metadata as importlib_metadata - import borgmatic.actions.borg import borgmatic.actions.break_lock import borgmatic.actions.check @@ -834,7 +830,7 @@ def main(extra_summary_logs=[]): # pragma: no cover global_arguments = arguments['global'] if global_arguments.version: - print(importlib_metadata.version('borgmatic')) + print(importlib.metadata.version('borgmatic')) sys.exit(0) if global_arguments.bash_completion: print(borgmatic.commands.completion.bash.bash_completion()) diff --git a/test_requirements.txt b/test_requirements.txt index 36a09cf..1451d08 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -14,13 +14,12 @@ flake8-use-fstring==1.4 flake8-variables-names==0.0.5 flexmock==0.11.3 idna==3.4 -importlib_metadata==6.3.0; python_version < '3.8' isort==5.12.0 jsonschema==4.17.3 Markdown==3.4.1 mccabe==0.7.0 packaging==23.1 -pathspec==0.11.1; python_version >= '3.8' +pathspec==0.11.1 pluggy==1.0.0 py==1.11.0 pycodestyle==2.10.0 @@ -28,10 +27,8 @@ pyflakes==3.0.1 pytest==7.3.0 pytest-cov==4.0.0 PyYAML>5.0.0 -regex; python_version >= '3.8' +regex requests==2.31.0 ruamel.yaml>0.15.0 -toml==0.10.2; python_version >= '3.8' -typed-ast; python_version >= '3.8' -typing-extensions==4.5.0; python_version < '3.8' -zipp==3.15.0; python_version < '3.8' +toml==0.10.2 +typed-ast diff --git a/tests/unit/actions/test_create.py b/tests/unit/actions/test_create.py index abbc853..28685e2 100644 --- a/tests/unit/actions/test_create.py +++ b/tests/unit/actions/test_create.py @@ -151,7 +151,7 @@ def test_create_borgmatic_manifest_creates_manifest_file(): flexmock(module.os.path).should_receive('exists').and_return(False) flexmock(module.os).should_receive('makedirs').and_return(True) - flexmock(module.importlib_metadata).should_receive('version').and_return('1.0.0') + flexmock(module.importlib.metadata).should_receive('version').and_return('1.0.0') flexmock(sys.modules['builtins']).should_receive('open').with_args( '/home/user/.borgmatic/bootstrap/manifest.json', 'w' ).and_return( @@ -172,7 +172,7 @@ def test_create_borgmatic_manifest_creates_manifest_file_with_custom_borgmatic_s flexmock(module.os.path).should_receive('exists').and_return(False) flexmock(module.os).should_receive('makedirs').and_return(True) - flexmock(module.importlib_metadata).should_receive('version').and_return('1.0.0') + flexmock(module.importlib.metadata).should_receive('version').and_return('1.0.0') flexmock(sys.modules['builtins']).should_receive('open').with_args( '/borgmatic/bootstrap/manifest.json', 'w' ).and_return(