Skip to content

Commit

Permalink
Merge pull request #96 from roskakori/91-fix-missing-output-with-sloc…
Browse files Browse the repository at this point in the history
…count

#91 Fix missing output on Windows with --format=sloccount
  • Loading branch information
roskakori committed Dec 31, 2022
2 parents 4b4071a + 7bfac4d commit 090302e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
10 changes: 8 additions & 2 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ Changes

This chapter describes the changes coming with each new version of pygount.

Version 1.5.1, 2022-12-31

* Removed progress bar for ``--format=sloccount`` because it resulted into
blank lines when running on Windows and could cause interwoven output on
Unix (issue `#91 <https://github.com/roskakori/pygount/issues/91>`_).

Version 1.5.0, 2022-12-30

* Removed support for Python 3.6 and updated dependencies
* Removed support for Python 3.6 and updated dependencies (issue
`#93 <https://github.com/roskakori/pygount/issues/93>`_).

Version 1.4.0, 2022-04-09

* Added progress bar during scan phase and improved visual design of
``--format=summary`` (contributed by Stanislav Zmiev, issue.
``--format=summary`` (contributed by Stanislav Zmiev, issue
`#73 <https://github.com/roskakori/pygount/issues/73>`_).
* Added percentages to API. For example in addition to
``code_count`` now there also is ``code_percentage``.
Expand Down
15 changes: 7 additions & 8 deletions pygount/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright (c) 2016-2023, Thomas Aglassinger.
# All rights reserved. Distributed under the BSD License.
import argparse
import contextlib
import logging
import os
import sys
Expand Down Expand Up @@ -326,14 +327,12 @@ 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]

with Progress(transient=True) as progress:
if self.output == "STDOUT":
file_contextmanager = pygount.common.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):
writer.add(
Expand Down
5 changes: 0 additions & 5 deletions pygount/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
# Copyright (c) 2016-2023, Thomas Aglassinger.
# All rights reserved. Distributed under the BSD License.
import contextlib
import fnmatch
import functools
import inspect
Expand All @@ -12,7 +11,6 @@
from typing import Generator, List, Optional, Pattern, Sequence, Union

#: Pseudo pattern to indicate that the remaining pattern are an addition to the default patterns.

ADDITIONAL_PATTERN = "[...]"

#: Prefix to use for pattern strings to describe a regular expression instead of a shell pattern.
Expand Down Expand Up @@ -186,6 +184,3 @@ def new_func2(*args, **kwargs):
return new_func2
else:
raise TypeError(repr(type(reason)))


nullcontext = contextlib.nullcontext
11 changes: 6 additions & 5 deletions pygount/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, target_stream):
self.lines_per_second = 0
self.duration = None
self.duration_in_seconds = 0.0
self.has_to_track_progress = True

def __enter__(self):
return self
Expand All @@ -51,12 +52,11 @@ def close(self):
self.project_summary.update_file_percentages()
self.finished_at = datetime.datetime.utcnow()
self.duration = self.finished_at - self.started_at
self.duration_in_seconds = (
(1e-6 * self.duration.microseconds) + self.duration.seconds + self.duration.days * 3600 * 24
self.duration_in_seconds = max(
0.001, self.duration.microseconds * 1e-6 + self.duration.seconds + self.duration.days * 3600 * 24
)
if self.duration_in_seconds > 0:
self.lines_per_second = self.project_summary.total_line_count / self.duration_in_seconds
self.files_per_second = self.project_summary.total_file_count / self.duration_in_seconds
self.lines_per_second = self.project_summary.total_line_count / self.duration_in_seconds
self.files_per_second = self.project_summary.total_file_count / self.duration_in_seconds


class LineWriter(BaseWriter):
Expand All @@ -66,6 +66,7 @@ class LineWriter(BaseWriter):

def __init__(self, target_stream):
super().__init__(target_stream)
self.has_to_track_progress = False
self.template = "{0}\t{1}\t{2}\t{3}"

def add(self, source_analysis):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ testpaths = [

[tool.poetry]
name = "pygount"
version = "1.5.0"
version = "1.5.1"
description = "count source lines of code (SLOC) using pygments"
readme = "README.md"
authors = ["Thomas Aglassinger <roskakori@users.sourceforge.net>"]
Expand Down

0 comments on commit 090302e

Please sign in to comment.