Skip to content
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
8 changes: 4 additions & 4 deletions spec_cleaner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ def process_args(argv: List[str]) -> Dict[str, Any]:

# the spec must exist for us to do anything
if not os.path.exists(options.specfile):
raise RpmWrongArgsError('{0} does not exist.'.format(options.specfile))
raise RpmWrongArgsError(f'{options.specfile} does not exist.')

# the path for output must exist and the file must not be there unless
# force is specified
if options.output:
options.output = os.path.expanduser(options.output)
if not options.force and os.path.exists(options.output):
raise RpmWrongArgsError('{0} already exists.'.format(options.output))
raise RpmWrongArgsError(f'{options.output} already exists.')

# convert options to dict
options_dict = vars(options)
Expand All @@ -162,14 +162,14 @@ def main() -> int:
try:
options = process_args(sys.argv[1:])
except RpmWrongArgsError as exception:
sys.stderr.write('ERROR: {0}\n'.format(exception))
sys.stderr.write(f'ERROR: {exception}\n')
return 1

try:
cleaner = RpmSpecCleaner(options)
cleaner.run()
except RpmExceptionError as exception:
sys.stderr.write('ERROR: {0}\n'.format(exception))
sys.stderr.write(f'ERROR: {exception}\n')
return 1

return 0
4 changes: 2 additions & 2 deletions spec_cleaner/dependency_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def consume_chars(regex, string):
return string[0:end], string[end:]
else:
raise NoMatchExceptionError(
'Expected match failed (string: "%s", regex: "%s" )' % (string, regex.pattern)
f'Expected match failed (string: "{string}", regex: "{regex.pattern}" )'
)


Expand All @@ -79,7 +79,7 @@ def matching_bracket(bracket):
elif bracket == '(':
return ')'
raise Exception(
'Undefined bracket matching - add defintion of "%s" to ' 'matching_bracket()' % bracket
f'Undefined bracket matching - add defintion of "{bracket}" to matching_bracket()'
)


Expand Down
10 changes: 5 additions & 5 deletions spec_cleaner/fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def open_datafile(name: str) -> IO[str]:
homedir = os.getenv('HOME', '~') + '/.local/'

possible_paths = (
'{0}/../data/{1}'.format(os.path.dirname(os.path.realpath(__file__)), name),
'{0}/share/spec-cleaner/{1}'.format(homedir, name),
'{0}/share/spec-cleaner/{1}'.format(sysconfig.get_path('data'), name),
'{0}/share/spec-cleaner/{1}'.format(sys.prefix, name),
f'{os.path.dirname(os.path.realpath(__file__))}/../data/{name}',
f'{homedir}/share/spec-cleaner/{name}',
f"{sysconfig.get_path('data')}/share/spec-cleaner/{name}",
f'{sys.prefix}/share/spec-cleaner/{name}',
)

for path in possible_paths:
Expand All @@ -38,7 +38,7 @@ def open_datafile(name: str) -> IO[str]:
else:
return _file
# file not found
raise RpmExceptionError("File '{}' not found in datadirs".format(name))
raise RpmExceptionError(f"File '{name}' not found in datadirs")


def open_stringio_spec(name: str) -> IO[str]:
Expand Down
12 changes: 5 additions & 7 deletions spec_cleaner/rpmcopyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ def __init__(self, options):
self.year = options['copyright_year']
self.copyrights = []
self.buildrules = []
self.distro_copyright = '# Copyright (c) {0} SUSE LLC and contributors'.format(self.year)
self.distro_copyright = f'# Copyright (c) {self.year} SUSE LLC and contributors'
self.vimmodeline = ''

def _add_pkg_header(self):
"""Add specfile name to the Copyright section."""
specname = os.path.splitext(os.path.basename(self.spec))[0]
self.lines.append(
"""#
# spec file for package {0}
#""".format(
specname
)
f"""#
# spec file for package {specname}
#"""
)

def _add_copyright(self):
Expand Down Expand Up @@ -84,7 +82,7 @@ def add(self, line: str) -> None:
copyright_match = self.reg.re_copyright_string.match(line)
if copyright_match and not self.reg.re_suse_copyright.search(line):
# always replace whitespace garbage on copyright line
line = '# Copyright (c) {0}'.format(copyright_match.group(1))
line = f'# Copyright (c) {copyright_match.group(1)}'
self.copyrights.append(line)
elif self.reg.re_rootforbuild.match(line):
self.buildrules.append('# needsrootforbuild')
Expand Down
2 changes: 1 addition & 1 deletion spec_cleaner/rpmfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _move_license_from_doc(self, line: str) -> str:
licences += match.group()
line = self.reg.re_doclicense.sub('', line, 1)
match = self.reg.re_doclicense.search(line)
Section.add(self, '%license {}'.format(licences))
Section.add(self, f'%license {licences}')
return line

def _expand_python_sitelib(self, line: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion spec_cleaner/rpmhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def add_group(group):
items += add_group(subgroup)
return items
else:
raise RpmExceptionError('Unknown type of group in preamble: %s' % type(group))
raise RpmExceptionError(f'Unknown type of group in preamble: {type(group)}')


def find_pkgconfig_statement(elements):
Expand Down
14 changes: 7 additions & 7 deletions spec_cleaner/rpmpreamble.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def _fix_pypi_source(self, url):
(
'https',
'files.pythonhosted.org',
'/packages/{}/{}/{}/{}'.format(pkg_type, modname[0], modname, filename),
f'/packages/{pkg_type}/{modname[0]}/{modname}/{filename}',
'',
'',
'',
Expand Down Expand Up @@ -284,7 +284,7 @@ def _pkgname_to_brackety(token, brackety, conversions):
# then add each pkgconfig to the list
# print pkgconf_list
for j in convers_list:
name = '{0}({1})'.format(brackety, j)
name = f'{brackety}({j})'
converted.append(RpmRequiresToken(name, token.operator, token.version))
return converted

Expand Down Expand Up @@ -487,7 +487,7 @@ def add(self, line):
source = self._fix_pypi_source(source)
if secure_source_available:
source = self._make_secure_url(source, skip_availabilty_check=True)
self._add_line_value_to('source', source, key='Source%s' % match.group(1))
self._add_line_value_to('source', source, key=f'Source{match.group(1)}')
return

elif self.reg.re_patch.match(line):
Expand All @@ -498,15 +498,15 @@ def add(self, line):
else:
zero = ''
self._add_line_value_to(
'patch', match.group(3), key='%sPatch%s%s' % (match.group(1), zero, match.group(2)),
'patch', match.group(3), key=f'{match.group(1)}Patch{zero}{match.group(2)}',
)
return

elif self.reg.re_buildoption_phase.match(line):
match = self.reg.re_buildoption_phase.match(line)
value = match.group(2)
self._add_line_value_to(
'buildoption_phase', value, key='BuildOption{0}'.format(match.group(1))
'buildoption_phase', value, key=f'BuildOption{match.group(1)}'
)
return

Expand Down Expand Up @@ -624,7 +624,7 @@ def add(self, line):
else:
value = match.group(2)
self._add_line_value_to(
'requires_phase', value, key='Requires{0}'.format(match.group(1))
'requires_phase', value, key=f'Requires{match.group(1)}'
)
return

Expand Down Expand Up @@ -663,7 +663,7 @@ def add(self, line):
language = match.group(1)
# and what value is there
content = match.group(2)
self._add_line_value_to('summary_localized', content, key='Summary{0}'.format(language))
self._add_line_value_to('summary_localized', content, key=f'Summary{language}')
return

elif self.reg.re_group.match(line):
Expand Down
4 changes: 2 additions & 2 deletions spec_cleaner/rpmpreambleelements.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _sort_helper_key(self, a):
# if this is a list then all items except last are comment or whitespace
key = str(a[-1])
else:
raise RpmExceptionError('Unknown type during sort: %s' % a)
raise RpmExceptionError(f'Unknown type during sort: {a}')

# Special case is the category grouping where we have to get the number in
# after the value
Expand Down Expand Up @@ -321,7 +321,7 @@ def compile_category_prefix(self, category, key=None):
elif category in self.category_to_key:
key = self.category_to_key[category]
else:
raise RpmExceptionError('Unhandled category in preamble: %s' % category)
raise RpmExceptionError(f'Unhandled category in preamble: {category}')

# append : only if the thing is not known macro
if not key.startswith('%'):
Expand Down
2 changes: 1 addition & 1 deletion spec_cleaner/rpmprep.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _prepare_patch(self, line: str) -> str:
match = self.reg.re_patch_prep.match(line)
if match:
line = self.strip_useless_spaces(
'%%patch -P %s %s' % (match.group(1), match.group(2))
f'%patch -P {match.group(1)} {match.group(2)}'
)

return line
2 changes: 1 addition & 1 deletion spec_cleaner/rpmscriplets.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ def _collapse_multiline_ldconfig(self) -> None:
if self.lines[1] == '/sbin/ldconfig':
pkg = self.lines[0]
self.lines = []
self.lines.append('{0} -p /sbin/ldconfig'.format(pkg))
self.lines.append(f'{pkg} -p /sbin/ldconfig')
Loading