Skip to content

Commit

Permalink
Changes to use f-strings instead of format (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Oct 2, 2022
1 parent 311c7fa commit 96a17df
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 61 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
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 dfkinds 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 @@ -124,17 +123,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 @@ -184,6 +182,12 @@ def parse_requirements_from_file(path):
'definitions to provide consistent definitions of entities (or description'
' of things) across different tools.')

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

setup(
name='dfkinds',
version=dfkinds.__version__,
Expand All @@ -194,9 +198,7 @@ def parse_requirements_from_file(path):
url='https://github.com/log2timeline/dfkinds',
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 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=dfkinds --omit="*_test*,*__init__*,*test_lib*" run_tests.py

Expand Down
52 changes: 23 additions & 29 deletions utils/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 96a17df

Please sign in to comment.