Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to use f-strings instead of format #29

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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']
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/test_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions acstore/containers/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
16 changes: 7 additions & 9 deletions acstore/containers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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]

Expand Down Expand Up @@ -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', {})

Expand All @@ -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

Expand Down
15 changes: 8 additions & 7 deletions acstore/fake_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
license_file = LICENSE
license_files = LICENSE

[bdist_rpm]
release = 1
Expand Down
34 changes: 18 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:]
Expand All @@ -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']
Expand All @@ -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)

Expand Down Expand Up @@ -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__,
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions tests/containers/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
Loading