Sourcery refactored master branch - #5
Conversation
| if not which('ebook-convert'): | ||
| return False | ||
| return True | ||
| return bool(which('ebook-convert')) |
There was a problem hiding this comment.
Function _check_calibre refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| shutil.copy(html_filename, html_filename + '.html') | ||
| shutil.copy(html_filename, f'{html_filename}.html') |
There was a problem hiding this comment.
Function html2calibre refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace list() with [] (
list-literal) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| converter = registry.converter_registry.get(format) | ||
| if converter is None: | ||
| raise ValueError('Unsupported format: %s' % format) | ||
| raise ValueError(f'Unsupported format: {format}') |
There was a problem hiding this comment.
Function Converter.convert refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| if self.cleanup: | ||
| if self.fo_filename: | ||
| os.unlink(self.fo_filename) | ||
| if self.cleanup and self.fo_filename: | ||
| os.unlink(self.fo_filename) |
There was a problem hiding this comment.
Function BaseConverter.__del__ refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| if output_filename: | ||
| fo_filename = output_filename | ||
| else: | ||
| fo_filename = newTempfile(suffix='.fo') | ||
|
|
||
| fo_filename = output_filename or newTempfile(suffix='.fo') | ||
| csstoxslfo = os.path.abspath(os.path.join(dirname, 'lib', 'csstoxslfo', 'css2xslfo.jar')) | ||
| if not os.path.exists(csstoxslfo): | ||
| raise IOError('%s does not exist' % csstoxslfo) | ||
| raise IOError(f'{csstoxslfo} does not exist') | ||
|
|
There was a problem hiding this comment.
Function HTML2FO.convert refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity) - Replace if statement with if expression (
assign-if-exp) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Replace list() with [] (
list-literal)
| if not v.startswith('#'): | ||
| codepoint = name2codepoint.get(v) | ||
| return codepoint and '&#%d;' % codepoint or '' | ||
| else: | ||
| if v.startswith('#'): | ||
| return e | ||
| codepoint = name2codepoint.get(v) | ||
| return codepoint and '&#%d;' % codepoint or '' |
There was a problem hiding this comment.
Function tidyhtml.handler refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| dirname = os.environ.get(envname, None) | ||
| if dirname is None: | ||
| LOG.debug('Environment variable $%s is unset' % envname) | ||
| LOG.debug(f'Environment variable ${envname} is unset') |
There was a problem hiding this comment.
Function checkEnvironment refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| full_exe_name = os.path.join(xfc_dir, 'fo2rtf') | ||
| if not os.path.exists(full_exe_name): | ||
| LOG.debug('%s does not exist' % full_exe_name) | ||
| LOG.debug(f'{full_exe_name} does not exist') |
There was a problem hiding this comment.
Function _check_xfc refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| if not format in ('rtf', 'docx', 'wml', 'odt'): | ||
| raise ValueError('Unsupported format: %s' % format) | ||
| if format not in ('rtf', 'docx', 'wml', 'odt'): | ||
| raise ValueError(f'Unsupported format: {format}') | ||
|
|
||
| if not output_filename: | ||
| output_filename = newTempfile(suffix='.%s' % format) | ||
| output_filename = newTempfile(suffix=f'.{format}') |
There was a problem hiding this comment.
Function fo2xfc refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| exe_name = win32 and '\\bin\\windows\\xinc.exe' or 'bin/unix/xinc' | ||
| exe_name = '\\bin\\windows\\xinc.exe' if win32 else 'bin/unix/xinc' | ||
| full_exe_name = os.path.join(xinc_home, exe_name) | ||
| if not os.path.exists(full_exe_name): | ||
| LOG.debug('%s does not exist' % full_exe_name) | ||
| LOG.debug(f'{full_exe_name} does not exist') |
There was a problem hiding this comment.
Function _check_xinc refactored with the following changes:
- Replace boolean ternary with inline if expression (
ternary-to-if-expression) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!