Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-24.04
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13", "3.14"]
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]

steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-24.04
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13", "3.14"]
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]

steps:
- name: Checkout repository
Expand Down
15 changes: 7 additions & 8 deletions github_backup/github_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import argparse
import base64
import calendar
import codecs
import json
import logging
import os
Expand Down Expand Up @@ -2304,7 +2303,7 @@ def gist_backup_is_current(repository, repo_cwd, repo_dir):
if not updated_at:
return False
try:
with codecs.open(os.path.join(repo_cwd, "gist.json"), encoding="utf-8") as f:
with open(os.path.join(repo_cwd, "gist.json"), encoding="utf-8", newline="") as f:
stored = json.load(f)
except (OSError, ValueError):
return False
Expand Down Expand Up @@ -2377,7 +2376,7 @@ def backup_repositories(args, output_directory, repositories):
# DMCA-blocked or empty gist), so make sure the directory exists
mkdir_p(repo_cwd)
output_file = "{0}/gist.json".format(repo_cwd)
with codecs.open(output_file, "w", encoding="utf-8") as f:
with open(output_file, "w", encoding="utf-8", newline="") as f:
json_dump(repository, f)

continue # don't try to back anything else for a gist; it doesn't exist
Expand Down Expand Up @@ -3021,7 +3020,7 @@ def backup_issues(args, repo_cwd, repository, repos_template):
args, issue_cwd, issues[number], number, repository, item_type="issue"
)

with codecs.open(issue_file + ".temp", "w", encoding="utf-8") as f:
with open(issue_file + ".temp", "w", encoding="utf-8", newline="") as f:
json_dump(issue, f)
os.replace(issue_file + ".temp", issue_file) # Atomic write

Expand All @@ -3040,7 +3039,7 @@ def read_json_file_if_exists(path):
return None

try:
with codecs.open(path, "r", encoding="utf-8") as f:
with open(path, "r", encoding="utf-8", newline="") as f:
return json.load(f)
except (OSError, UnicodeDecodeError, json.decoder.JSONDecodeError) as e:
logger.debug("Error reading existing JSON file {0}: {1}".format(path, e))
Expand Down Expand Up @@ -3230,7 +3229,7 @@ def pull_is_due_for_repository_checkpoint(pull):

restore_existing_pull_optional_data(pull, existing_pull)

with codecs.open(pull_file + ".temp", "w", encoding="utf-8") as f:
with open(pull_file + ".temp", "w", encoding="utf-8", newline="") as f:
json_dump(pull, f)
os.replace(pull_file + ".temp", pull_file) # Atomic write

Expand Down Expand Up @@ -3646,7 +3645,7 @@ def json_dump_if_changed(data, output_file_path):
# Check if file exists and compare content
if os.path.exists(output_file_path):
try:
with codecs.open(output_file_path, "r", encoding="utf-8") as f:
with open(output_file_path, "r", encoding="utf-8", newline="") as f:
existing_content = f.read()
if existing_content == new_content:
logger.debug(
Expand All @@ -3663,7 +3662,7 @@ def json_dump_if_changed(data, output_file_path):

# Write the file atomically using temp file + rename
temp_file = output_file_path + ".temp"
with codecs.open(temp_file, "w", encoding="utf-8") as f:
with open(temp_file, "w", encoding="utf-8", newline="") as f:
f.write(new_content)
os.replace(temp_file, output_file_path) # Atomic write
return True
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def open_file(fname):
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3.15",
],
description="backup a github user or organization",
long_description=open_file("README.rst").read(),
Expand Down
15 changes: 7 additions & 8 deletions tests/test_json_dump_if_changed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Tests for json_dump_if_changed functionality."""

import codecs
import json
import os
import tempfile
Expand All @@ -25,7 +24,7 @@ def test_writes_new_file(self):
assert os.path.exists(output_file)

# Verify content matches expected format
with codecs.open(output_file, "r", encoding="utf-8") as f:
with open(output_file, "r", encoding="utf-8", newline="") as f:
content = f.read()
loaded = json.loads(content)
assert loaded == test_data
Expand Down Expand Up @@ -67,7 +66,7 @@ def test_writes_when_content_changed(self):
assert result2 is True

# Verify new content
with codecs.open(output_file, "r", encoding="utf-8") as f:
with open(output_file, "r", encoding="utf-8", newline="") as f:
loaded = json.load(f)
assert loaded == test_data2

Expand All @@ -79,7 +78,7 @@ def test_uses_consistent_formatting(self):

github_backup.json_dump_if_changed(test_data, output_file)

with codecs.open(output_file, "r", encoding="utf-8") as f:
with open(output_file, "r", encoding="utf-8", newline="") as f:
content = f.read()

# Check for consistent formatting:
Expand Down Expand Up @@ -111,7 +110,7 @@ def test_atomic_write_always_used(self):
assert not os.path.exists(temp_file)

# Verify content
with codecs.open(output_file, "r", encoding="utf-8") as f:
with open(output_file, "r", encoding="utf-8", newline="") as f:
loaded = json.load(f)
assert loaded == test_data

Expand All @@ -130,7 +129,7 @@ def test_handles_unicode_content(self):
assert result is True

# Verify Unicode is preserved
with codecs.open(output_file, "r", encoding="utf-8") as f:
with open(output_file, "r", encoding="utf-8", newline="") as f:
loaded = json.load(f)
assert loaded == test_data

Expand All @@ -154,7 +153,7 @@ def test_handles_complex_nested_data(self):
assert result is True

# Verify structure is preserved
with codecs.open(output_file, "r", encoding="utf-8") as f:
with open(output_file, "r", encoding="utf-8", newline="") as f:
loaded = json.load(f)
assert loaded == test_data

Expand All @@ -173,7 +172,7 @@ def test_overwrites_on_unicode_decode_error(self):
assert result is True

# Verify new content was written
with codecs.open(output_file, "r", encoding="utf-8") as f:
with open(output_file, "r", encoding="utf-8", newline="") as f:
loaded = json.load(f)
assert loaded == test_data

Expand Down