Skip to content

Commit

Permalink
#91 Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
roskakori committed Dec 31, 2022
1 parent f678d34 commit ec93078
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pygount/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,11 @@ def execute(self):
source_paths_and_groups_to_analyze = list(source_scanner.source_paths())
duplicate_pool = pygount.analysis.DuplicatePool() if not self.has_duplicates else None
writer_class = _OUTPUT_FORMAT_TO_WRITER_CLASS_MAP[self.output_format]

if self.output == "STDOUT":
file_contextmanager = contextlib.nullcontext(sys.stdout)
else:
file_contextmanager = open(self.output, "w", encoding="utf-8", newline="")

with file_contextmanager as target_file, writer_class(target_file) as writer:
is_stdout = self.output == "STDOUT"
target_context_manager = (
contextlib.nullcontext(sys.stdout) if is_stdout else open(self.output, "w", encoding="utf-8", newline="")
)
with target_context_manager as target_file, writer_class(target_file) as writer:
with Progress(disable=not writer.has_to_track_progress, transient=True) as progress:
try:
for source_path, group in progress.track(source_paths_and_groups_to_analyze):
Expand Down

0 comments on commit ec93078

Please sign in to comment.