Skip to content

Commit

Permalink
Merge pull request #148 from roskakori/105-add-option-to-merge-embedd…
Browse files Browse the repository at this point in the history
…ed-languages

#105 Clean up deprecation warnings
  • Loading branch information
roskakori committed May 12, 2024
2 parents 8127879 + cdb0651 commit 9d645b6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pygount/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, target_stream):
except AttributeError:
self.target_name = "<io>"
self.project_summary = ProjectSummary()
self.started_at = datetime.datetime.utcnow()
self.started_at = self._utc_now()
self.finished_at = None
self.files_per_second = 0
self.lines_per_second = 0
Expand All @@ -52,14 +52,19 @@ def add(self, source_analysis):

def close(self):
self.project_summary.update_file_percentages()
self.finished_at = datetime.datetime.utcnow()
self.finished_at = self._utc_now()
self.duration = self.finished_at - self.started_at
self.duration_in_seconds = max(
0.001, self.duration.microseconds * 1e-6 + self.duration.seconds + self.duration.days * 3600 * 24
)
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

@staticmethod
def _utc_now() -> datetime.datetime:
# After switching to Python 3.11+, we can change this to `now(datetime.UTC)`.
return datetime.datetime.now(datetime.timezone.utc)


class LineWriter(BaseWriter):
"""
Expand Down

0 comments on commit 9d645b6

Please sign in to comment.