Skip to content

Commit

Permalink
Changes to use f-strings instead of format (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored Oct 16, 2022
1 parent 8569298 commit 3dffcb7
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 85 deletions.
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
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
28 changes: 19 additions & 9 deletions artifactsrc/resource_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,30 @@ def _GetVersionInformation(self):
return

file_version = version_information_resource.file_version
self._file_version = '{0:d}.{1:d}.{2:d}.{3:d}'.format(
(file_version >> 48) & 0xffff, (file_version >> 32) & 0xffff,
(file_version >> 16) & 0xffff, file_version & 0xffff)
major_version = (file_version >> 48) & 0xffff
minor_version = (file_version >> 32) & 0xffff
build_number = (file_version >> 16) & 0xffff
revision_number = file_version & 0xffff

self._file_version = (
f'{major_version:d}.{minor_version:d}.{build_number:d}.'
f'{revision_number:d}')

product_version = version_information_resource.product_version
self._product_version = '{0:d}.{1:d}.{2:d}.{3:d}'.format(
(product_version >> 48) & 0xffff, (product_version >> 32) & 0xffff,
(product_version >> 16) & 0xffff, product_version & 0xffff)
major_version = (product_version >> 48) & 0xffff
minor_version = (product_version >> 32) & 0xffff
build_number = (product_version >> 16) & 0xffff
revision_number = product_version & 0xffff

self._product_version = (
f'{major_version:d}.{minor_version:d}.{build_number:d}.'
f'{revision_number:d}')

if file_version != product_version:
logging.warning((
'Mismatch between file version: {0:s} and product version: '
'{1:s} in message file: {2:s}.').format(
self._file_version, self._product_version, self.windows_path))
f'Mismatch between file version: {self._file_version:s} and product '
f'version: {self._product_version:s} in message file: '
f'{self.windows_path:s}.'))

def _GetVersionInformationResource(self):
"""Retrieves the version information resource.
Expand Down
4 changes: 2 additions & 2 deletions artifactsrc/volume_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def _OpenMessageResourceFileByPathSpec(self, path_spec):
try:
file_object = dfvfs_resolver.Resolver.OpenFileObject(path_spec)
except IOError as exception:
logging.warning('Unable to open: {0:s} with error: {1!s}'.format(
path_spec.comparable, exception))
logging.warning(
f'Unable to open: {path_spec.comparable:s} with error: {exception!s}')
file_object = None

if file_object is None:
Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +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 run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


if __name__ == '__main__':
print('Using Python version {0!s}'.format(sys.version))
print(f'Using Python version {sys.version!s}')

fail_unless_has_test_file = '--fail-unless-has-test-file' in sys.argv
setattr(unittest, 'fail_unless_has_test_file', fail_unless_has_test_file)
Expand Down
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
43 changes: 22 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,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 artifactsrc so that we can get the version.
Expand Down Expand Up @@ -83,8 +82,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 Down Expand Up @@ -113,7 +112,7 @@ def _make_spec_file(self):
'%doc ACKNOWLEDGEMENTS AUTHORS README',
'%{_datadir}/%{name}/*',
'',
'%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 @@ -134,30 +133,27 @@ def _make_spec_file(self):

python_spec_file.extend([
'%package -n %{name}-data',
'Summary: Data files for {0:s}'.format(summary),
f'Summary: Data files for {summary:s}',
'',
'%description -n %{name}-data'])

python_spec_file.extend(description)

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}'

python_spec_file.extend([
'Requires: artifacts-kb-data >= %{{version}} {0:s}'.format(
requires),
'Summary: {0:s}'.format(python_summary),
f'Requires: artifacts-kb-data >= %{{version}} {requires:s}',
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)

python_spec_file.extend([
'%package -n %{name}-tools',
'Requires: {0:s}-artifacts-kb >= %{{version}}'.format(
python_package),
'Summary: Tools for {0:s}'.format(summary),
f'Requires: {python_package:s}-artifacts-kb >= %{{version}}',
f'Summary: Tools for {summary:s}',
'',
'%description -n %{name}-tools'])

Expand Down Expand Up @@ -212,18 +208,23 @@ def parse_requirements_from_file(path):
artifactsrc_long_description = (
'Documentation accompanying the Digital Forensics Artifact Repository.')

command_classes = {}
if BdistMSICommand:
command_classes['bdist_msi'] = BdistMSICommand
if BdistRPMCommand:
command_classes['bdist_rpm'] = BdistRPMCommand

setup(
name='artifactsrc',
version=artifactsrc.__version__,
description=artifactsrc_description,
long_description=artifactsrc_long_description,
long_description_content_type='text/plain',
license='Apache License, Version 2.0',
url='https://github.com/ForensicArtifacts/artifacts-kb',
maintainer='Joachim Metz',
maintainer_email='[email protected]',
cmdclass={
'bdist_msi': BdistMSICommand,
'bdist_rpm': BdistRPMCommand},
cmdclass=command_classes,
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
Expand Down
13 changes: 6 additions & 7 deletions tools/check_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def Main():
try:
if not scanner.ScanForOperatingSystemVolumes(
options.source, options=volume_scanner_options):
print('Unable to retrieve an operating system volume from: {0:s}.'.format(
options.source))
print((f'Unable to retrieve an operating system volume from: '
f'{options.source:s}.'))
print('')
return False

Expand All @@ -147,7 +147,7 @@ def Main():
definitions_with_check_results[artifact_definition.name] = check_result

except dfvfs_errors.ScannerError as exception:
print('[ERROR] {0!s}'.format(exception), file=sys.stderr)
print(f'[ERROR] {exception!s}', file=sys.stderr)
print('')
return False

Expand All @@ -158,11 +158,10 @@ def Main():

print('Aritfact definitions found:')
for name, check_result in sorted(definitions_with_check_results.items()):
text = '* {0:s} [results: {1:d}]'.format(
name, check_result.number_of_file_entries)
text = f'* {name:s} [results: {check_result.number_of_file_entries:d}]'
if check_result.data_formats:
text = '{0:s} [formats: {1:s}]'.format(
text, ', '.join(sorted(check_result.data_formats)))
formats_string = ', '.join(sorted(check_result.data_formats))
text = f'{text:s} [formats: {formats_string:s}]'

print(text)
print('')
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=artifactsrc --omit="*_test*,*__init__*,*test_lib*" run_tests.py

Expand Down
Loading

0 comments on commit 3dffcb7

Please sign in to comment.