From 05108af5219406fbb793f6741218fd5ce2f49e38 Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Sun, 2 Oct 2022 11:53:16 +0200 Subject: [PATCH] Changes to use f-strings instead of format --- .github/workflows/test_docker.yml | 4 +-- .github/workflows/test_docs.yml | 4 +-- .github/workflows/test_tox.yml | 6 ++-- .pylintrc | 1 + acstore/containers/interface.py | 6 ++-- acstore/containers/manager.py | 16 +++++----- acstore/fake_store.py | 15 ++++----- appveyor.yml | 4 --- docs/requirements.txt | 2 +- setup.cfg | 2 +- setup.py | 34 ++++++++++---------- tests/containers/interface.py | 4 +-- tox.ini | 4 +-- utils/dependencies.py | 52 ++++++++++++++----------------- 14 files changed, 71 insertions(+), 83 deletions(-) diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index 9db669c..789393b 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -3,7 +3,7 @@ name: test_docker on: [push] jobs: test_fedora: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: version: ['36'] @@ -37,7 +37,7 @@ jobs: python3 ./setup.py build python3 ./setup.py install test_ubuntu: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: version: ['22.04'] diff --git a/.github/workflows/test_docs.yml b/.github/workflows/test_docs.yml index 13e0c94..b623bdf 100644 --- a/.github/workflows/test_docs.yml +++ b/.github/workflows/test_docs.yml @@ -9,14 +9,14 @@ on: - main jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: include: - python-version: '3.8' toxenv: 'docs' container: - image: ubuntu:20.04 + image: ubuntu:22.04 steps: - uses: actions/checkout@v2 - name: Set up container diff --git a/.github/workflows/test_tox.yml b/.github/workflows/test_tox.yml index ec8b92b..1a05955 100644 --- a/.github/workflows/test_tox.yml +++ b/.github/workflows/test_tox.yml @@ -9,12 +9,10 @@ on: - main jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: include: - - python-version: '3.6' - toxenv: 'py36' - python-version: '3.7' toxenv: 'py37' - python-version: '3.8' @@ -26,7 +24,7 @@ jobs: - python-version: '3.8' toxenv: 'lint' container: - image: ubuntu:20.04 + image: ubuntu:22.04 steps: - uses: actions/checkout@v2 - name: Set up container diff --git a/.pylintrc b/.pylintrc index f25f26b..2cd75dd 100644 --- a/.pylintrc +++ b/.pylintrc @@ -98,6 +98,7 @@ disable=assignment-from-none, locally-disabled, locally-enabled, logging-format-interpolation, + logging-fstring-interpolation, metaclass-assignment, missing-param-doc, no-absolute-import, diff --git a/acstore/containers/interface.py b/acstore/containers/interface.py index f6dc69c..8b26289 100644 --- a/acstore/containers/interface.py +++ b/acstore/containers/interface.py @@ -20,7 +20,7 @@ def CopyToString(self): Returns: str: unique identifier or None. """ - return '{0:d}'.format(self._identifier) + return f'{self._identifier:d}' class AttributeContainer(object): @@ -123,9 +123,7 @@ def GetAttributeValuesString(self): elif isinstance(attribute_value, bytes): attribute_value = repr(attribute_value) - attribute_string = '{0:s}: {1!s}'.format( - attribute_name, attribute_value) - attributes.append(attribute_string) + attributes.append(f'{attribute_name:s}: {attribute_value!s}') return ', '.join(attributes) diff --git a/acstore/containers/manager.py b/acstore/containers/manager.py index dc183e1..754d0b3 100644 --- a/acstore/containers/manager.py +++ b/acstore/containers/manager.py @@ -23,8 +23,7 @@ def CreateAttributeContainer(cls, container_type): container_class = cls._attribute_container_classes.get( container_type, None) if not container_class: - raise ValueError('Unsupported container type: {0:s}'.format( - container_type)) + raise ValueError(f'Unsupported container type: {container_type:s}') return container_class() @@ -44,9 +43,9 @@ def DeregisterAttributeContainer(cls, attribute_container_class): """ container_type = attribute_container_class.CONTAINER_TYPE.lower() if container_type not in cls._attribute_container_classes: - raise KeyError( - 'Attribute container class not set for container type: ' - '{0:s}.'.format(attribute_container_class.CONTAINER_TYPE)) + raise KeyError(( + f'Attribute container class not set for container type: ' + f'{attribute_container_class.CONTAINER_TYPE:s}.')) del cls._attribute_container_classes[container_type] @@ -76,8 +75,7 @@ def GetSchema(cls, container_type): container_class = cls._attribute_container_classes.get( container_type, None) if not container_class: - raise ValueError('Unsupported container type: {0:s}'.format( - container_type)) + raise ValueError(f'Unsupported container type: {container_type:s}') return getattr(container_class, 'SCHEMA', {}) @@ -98,8 +96,8 @@ def RegisterAttributeContainer(cls, attribute_container_class): container_type = attribute_container_class.CONTAINER_TYPE.lower() if container_type in cls._attribute_container_classes: raise KeyError(( - 'Attribute container class already set for container type: ' - '{0:s}.').format(attribute_container_class.CONTAINER_TYPE)) + f'Attribute container class already set for container type: ' + f'{attribute_container_class.CONTAINER_TYPE:s}.')) cls._attribute_container_classes[container_type] = attribute_container_class diff --git a/acstore/fake_store.py b/acstore/fake_store.py index 905257d..5d77d61 100644 --- a/acstore/fake_store.py +++ b/acstore/fake_store.py @@ -36,7 +36,7 @@ def CopyToString(self): if self.sequence_number is None: return None - return '{0:d}'.format(self.sequence_number) + return f'{self.sequence_number:d}' class FakeAttributeContainerStore(interface.AttributeContainerStore): @@ -82,17 +82,18 @@ def _WriteExistingAttributeContainer(self, container): """ identifier = container.GetIdentifier() if not isinstance(identifier, FakeAttributeContainerIdentifier): - raise IOError( - 'Unsupported attribute container identifier type: {0!s}'.format( - type(identifier))) + identifier_type = type(identifier) + raise IOError(( + f'Unsupported attribute container identifier type: ' + f'{identifier_type!s}')) lookup_key = identifier.CopyToString() containers = self._attribute_containers.get(container.CONTAINER_TYPE, None) if containers is None or lookup_key not in containers: - raise IOError( - 'Missing attribute container: {0:s} with identifier: {1:s}'.format( - container.CONTAINER_TYPE, lookup_key)) + raise IOError(( + f'Missing attribute container: {container.CONTAINER_TYPE:s} with ' + f'identifier: {lookup_key:s}')) containers[lookup_key] = container diff --git a/appveyor.yml b/appveyor.yml index 13cda06..dc1cd8e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,10 +24,6 @@ install: - sh: config/appveyor/install.sh build_script: -# Note that bdist_msi will change the version number to work-around limitations -# of the MSI version version numbering. Hence a MSI build is done separately -# from building the wheel to not influence its version number. -- cmd: "%PYTHON%\\python.exe setup.py bdist_msi" - cmd: "%PYTHON%\\python.exe setup.py bdist_wheel" test_script: diff --git a/docs/requirements.txt b/docs/requirements.txt index 81e7973..e872a91 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,6 +1,6 @@ docutils Markdown recommonmark -sphinx >= 4.1.0 +sphinx >= 4.1.0, < 5.2.0 sphinx-markdown-tables sphinx-rtd-theme >= 0.5.1 diff --git a/setup.cfg b/setup.cfg index 7daff51..36d6b39 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -license_file = LICENSE +license_files = LICENSE [bdist_rpm] release = 1 diff --git a/setup.py b/setup.py index 5d8b539..93cc016 100755 --- a/setup.py +++ b/setup.py @@ -22,10 +22,9 @@ bdist_rpm = None version_tuple = (sys.version_info[0], sys.version_info[1]) -if version_tuple < (3, 6): - print(( - 'Unsupported Python version: {0:s}, version 3.6 or higher ' - 'required.').format(sys.version)) +if version_tuple < (3, 7): + print(f'Unsupported Python version: {sys.version:s}, version 3.7 or higher ' + f'required.') sys.exit(1) # Change PYTHONPATH to include acstore so that we can get the version. @@ -82,8 +81,8 @@ def _make_spec_file(self): summary = line[9:] elif line.startswith('BuildRequires: '): - line = 'BuildRequires: {0:s}-setuptools, {0:s}-devel'.format( - python_package) + line = (f'BuildRequires: {python_package:s}-setuptools, ' + f'{python_package:s}-devel') elif line.startswith('Requires: '): requires = line[10:] @@ -106,7 +105,7 @@ def _make_spec_file(self): elif line.startswith('%files'): lines = [ - '%files -n {0:s}-%{{name}}'.format(python_package), + f'%files -n {python_package:s}-%{{name}}', '%defattr(644,root,root,755)', '%license LICENSE', '%doc ACKNOWLEDGEMENTS AUTHORS README'] @@ -126,17 +125,16 @@ def _make_spec_file(self): elif line.startswith('%prep'): in_description = False - python_spec_file.append( - '%package -n {0:s}-%{{name}}'.format(python_package)) - python_summary = 'Python 3 module of {0:s}'.format(summary) + python_spec_file.append(f'%package -n {python_package:s}-%{{name}}') + python_summary = f'Python 3 module of {summary:s}' if requires: - python_spec_file.append('Requires: {0:s}'.format(requires)) + python_spec_file.append(f'Requires: {requires:s}') python_spec_file.extend([ - 'Summary: {0:s}'.format(python_summary), + f'Summary: {python_summary:s}', '', - '%description -n {0:s}-%{{name}}'.format(python_package)]) + f'%description -n {python_package:s}-%{{name}}']) python_spec_file.extend(description) @@ -185,6 +183,12 @@ def parse_requirements_from_file(path): 'ACStore, or Attribute Container Storage, provides a stand-alone ' 'implementation to read and write attribute container storage files.') +command_classes = {} +if BdistMSICommand: + command_classes['bdist_msi'] = BdistMSICommand +if BdistRPMCommand: + command_classes['bdist_rpm'] = BdistRPMCommand + setup( name='acstore', version=acstore.__version__, @@ -195,9 +199,7 @@ def parse_requirements_from_file(path): url='https://github.com/log2timeline/acstore', maintainer='Log2Timeline maintainers', maintainer_email='log2timeline-maintainers@googlegroups.com', - cmdclass={ - 'bdist_msi': BdistMSICommand, - 'bdist_rpm': BdistRPMCommand}, + cmdclass=command_classes, classifiers=[ '', 'Environment :: Console', diff --git a/tests/containers/interface.py b/tests/containers/interface.py index 727b84f..20ecc28 100644 --- a/tests/containers/interface.py +++ b/tests/containers/interface.py @@ -16,9 +16,9 @@ def testCopyToString(self): """Tests the CopyToString function.""" identifier = interface.AttributeContainerIdentifier() - expected_identifier_string = '{0:d}'.format(id(identifier)) + expected_identifier = id(identifier) identifier_string = identifier.CopyToString() - self.assertEqual(identifier_string, expected_identifier_string) + self.assertEqual(identifier_string, f'{expected_identifier:d}') class AttributeContainerTest(test_lib.BaseTestCase): diff --git a/tox.ini b/tox.ini index 9901f1f..f6c2751 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py3{6,7,8,9,10},coverage,docs,lint +envlist = py3{7,8,9,10},coverage,docs,lint [testenv] pip_pre = True @@ -10,7 +10,7 @@ deps = -rtest_requirements.txt coverage: coverage commands = - py3{6,7,8,9,10}: ./run_tests.py + py3{7,8,9,10}: ./run_tests.py coverage: coverage erase coverage: coverage run --source=acstore --omit="*_test*,*__init__*,*test_lib*" run_tests.py diff --git a/utils/dependencies.py b/utils/dependencies.py index 6034a99..a2c4040 100644 --- a/utils/dependencies.py +++ b/utils/dependencies.py @@ -157,8 +157,7 @@ def _CheckPythonModule(self, dependency): """ module_object = self._ImportPythonModule(dependency.name) if not module_object: - status_message = 'missing: {0:s}'.format(dependency.name) - return False, status_message + return False, f'missing: {dependency.name:s}' if not dependency.version_property: return True, dependency.name @@ -196,13 +195,11 @@ def _CheckPythonModuleVersion( module_version = version_method() if not module_version: - status_message = ( - 'unable to determine version information for: {0:s}').format( - module_name) - return False, status_message + return False, ( + f'unable to determine version information for: {module_name:s}') # Make sure the module version is a string. - module_version = '{0!s}'.format(module_version) + module_version = f'{module_version!s}' # Split the version string and convert every digit into an integer. # A string compare of both version strings will yield an incorrect result. @@ -217,42 +214,38 @@ def _CheckPythonModuleVersion( module_version_map = list( map(int, self._VERSION_SPLIT_REGEX.split(module_version))) except ValueError: - status_message = 'unable to parse module version: {0:s} {1:s}'.format( - module_name, module_version) - return False, status_message + return False, ( + f'unable to parse module version: {module_name:s} {module_version:s}') if minimum_version: try: minimum_version_map = list( map(int, self._VERSION_SPLIT_REGEX.split(minimum_version))) except ValueError: - status_message = 'unable to parse minimum version: {0:s} {1:s}'.format( - module_name, minimum_version) - return False, status_message + return False, ( + f'unable to parse minimum version: {module_name:s} ' + f'{minimum_version:s}') if module_version_map < minimum_version_map: - status_message = ( - '{0:s} version: {1!s} is too old, {2!s} or later required').format( - module_name, module_version, minimum_version) - return False, status_message + return False, ( + f'{module_name:s} version: {module_version!s} is too old, ' + f'{minimum_version!s} or later required') if maximum_version: try: maximum_version_map = list( map(int, self._VERSION_SPLIT_REGEX.split(maximum_version))) except ValueError: - status_message = 'unable to parse maximum version: {0:s} {1:s}'.format( - module_name, maximum_version) - return False, status_message + return False, ( + f'unable to parse maximum version: {module_name:s} ' + f'{maximum_version:s}') if module_version_map > maximum_version_map: - status_message = ( - '{0:s} version: {1!s} is too recent, {2!s} or earlier ' - 'required').format(module_name, module_version, maximum_version) - return False, status_message + return False, ( + f'{module_name:s} version: {module_version!s} is too recent, ' + f'{maximum_version!s} or earlier required') - status_message = '{0:s} version: {1!s}'.format(module_name, module_version) - return True, status_message + return True, f'{module_name:s} version: {module_version!s}' def _ImportPythonModule(self, module_name): """Imports a Python module. @@ -292,10 +285,10 @@ def _PrintCheckDependencyStatus( else: status_indicator = '[FAILURE]' - print('{0:s}\t{1:s}'.format(status_indicator, status_message)) + print(f'{status_indicator:s}\t{status_message:s}') elif verbose_output: - print('[OK]\t\t{0:s}'.format(status_message)) + print(f'[OK]\t\t{status_message:s}') def CheckDependencies(self, verbose_output=True): """Checks the availability of the dependencies. @@ -349,7 +342,8 @@ def CheckTestDependencies(self, verbose_output=True): continue result, status_message = self._CheckPythonModule(dependency) - if not result: + + if not result and not dependency.is_optional: check_result = False self._PrintCheckDependencyStatus(