Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Feb 18, 2022
1 parent f377e45 commit 5d99392
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
18 changes: 9 additions & 9 deletions calcipy/code_tag_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def _search_lines(

comments = []
for lineno, line in enumerate(lines):
match = regex_compiled.search(line)
if match:
if match := regex_compiled.search(line):
group = match.groupdict()
comments.append(_CodeTag(lineno + 1, tag=group['tag'], text=group['text']))
return comments
Expand Down Expand Up @@ -187,7 +186,7 @@ def _format_record(base_dir: Path, file_path: Path, comment: _CodeTag) -> Dict[s
@beartype
def _format_report(
base_dir: Path, code_tags: List[_Tags], tag_order: List[str],
) -> str: # noqa: CCR001
) -> str: # noqa: CCR001
"""Pretty-format the code tags by file and line number.
Args:
Expand All @@ -214,8 +213,9 @@ def _format_report(

sorted_counter = {tag: counter[tag] for tag in tag_order if tag in counter}
logger.debug('sorted_counter={sorted_counter}', sorted_counter=sorted_counter)
formatted_summary = ', '.join(f'{tag} ({count})' for tag, count in sorted_counter.items())
if formatted_summary:
if formatted_summary := ', '.join(
f'{tag} ({count})' for tag, count in sorted_counter.items()
):
output += f'\n\nFound code tags for {formatted_summary}\n'
return output

Expand All @@ -226,7 +226,7 @@ def write_code_tag_file(
path_tag_summary: Path, paths_source: List[Path], base_dir: Path,
regex_compiled: Optional[Pattern[str]] = None, tag_order: Optional[List[str]] = None,
header: str = '# Task Summary',
) -> None: # noqa: CCR001
) -> None: # noqa: CCR001
"""Create the code tag summary file.
Args:
Expand All @@ -243,9 +243,9 @@ def write_code_tag_file(
regex_compiled = regex_compiled or re.compile(CODE_TAG_RE.format(tag='|'.join(tag_order)))

matches = _search_files(paths_source, regex_compiled)
report = _format_report(base_dir, matches, tag_order=tag_order).strip()

if report:
if report := _format_report(
base_dir, matches, tag_order=tag_order
).strip():
path_tag_summary.write_text(f'{header}\n\n{report}\n\n<!-- {SKIP_PHRASE} -->\n')
else:
path_tag_summary.unlink(missing_ok=True)
3 changes: 1 addition & 2 deletions calcipy/doit_tasks/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ def _parse_var_comment(line: str, matcher: Pattern = _RE_VAR_COMMENT_HTML) -> Di
Dict[str, str]: single key and value pair based on the parsed comment
"""
match = matcher.match(line.strip())
if match:
if match := matcher.match(line.strip()):
matches = match.groupdict()
return {matches['key']: matches['value']}
return {}
Expand Down
13 changes: 9 additions & 4 deletions calcipy/doit_tasks/doit_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ def _verify_initialized_paths(self) -> None:
RuntimeError: if any paths are None
"""
missing = [name for name, _m in self._get_members(instance_type=type(None), prefix='path_')]
if missing:
if missing := [
name
for name, _m in self._get_members(
instance_type=type(None), prefix='path_'
)
]:
kwargs = ', '.join(missing)
raise RuntimeError(f'Missing keyword arguments for: {kwargs}')

Expand Down Expand Up @@ -430,8 +434,9 @@ def _set_submodules(self, calcipy_config: Dict[str, Any]) -> None:
# Configure global options
section_keys = ['lint', 'test', 'code_tag', 'doc']
supported_keys = section_keys + ['ignore_patterns']
unexpected_keys = [key for key in calcipy_config if key not in supported_keys]
if unexpected_keys:
if unexpected_keys := [
key for key in calcipy_config if key not in supported_keys
]:
raise RuntimeError(f'Found unexpected key(s) {unexpected_keys} (i.e. not in {supported_keys})')

# Parse the Copier file for configuration information
Expand Down
5 changes: 3 additions & 2 deletions calcipy/doit_tasks/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ def _lint_non_python(strict: bool = False) -> List[DoitAction]:

actions = []

paths_yaml = DG.meta.paths_by_suffix.get('yml', []) + DG.meta.paths_by_suffix.get('yaml', [])
if paths_yaml:
if paths_yaml := DG.meta.paths_by_suffix.get(
'yml', []
) + DG.meta.paths_by_suffix.get('yaml', []):
paths = ' '.join(f'"{pth}"' for pth in paths_yaml)
actions.append(Interactive(f'poetry run yamllint {strict_flag} {paths}'))

Expand Down
2 changes: 1 addition & 1 deletion calcipy/doit_tasks/summary_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _format_task_summary(task_summary: _TaskSummary) -> str:
_TaskExitCode.SKIP_UP_TO_DATE: (fg.yellow, 'was skipped'),
}
foreground, exit_summary = lookup.get(task_summary.exit_code, ('', 'is UNKNOWN'))
return f'{foreground}{task_summary.name} {exit_summary}' + fg.rs
return f'{foreground}{task_summary.name} {exit_summary}{fg.rs}'


class SummaryReporter(ConsoleReporter): # pragma: no cover # noqa: H601
Expand Down
4 changes: 1 addition & 3 deletions calcipy/file_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def read_lines(path_file: Path) -> List[str]:
List[str]: lines of text as list
"""
if path_file.is_file():
return path_file.read_text().split('\n')
return []
return path_file.read_text().split('\n') if path_file.is_file() else []


@beartype
Expand Down

0 comments on commit 5d99392

Please sign in to comment.