Repository navigation
Fix good-first-issue batch (#5-#12) #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DatMoshu
wants to merge
3
commits into
main
Choose a base branch
from
worker/good-first-issues
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """Font loading that works without Arial (Linux, macOS, stripped Windows).""" | ||
| import os | ||
| from pathlib import Path | ||
| from PIL import ImageFont | ||
|
|
||
| def candidates(): | ||
| windir = os.environ.get('WINDIR') or os.environ.get('SystemRoot') or 'C:/Windows' | ||
| return [Path(windir, 'Fonts', 'arial.ttf'), Path('/Library/Fonts/Arial.ttf'), | ||
| Path('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf'), Path('/usr/share/fonts/TTF/DejaVuSans.ttf')] | ||
|
|
||
| def load_font(size, paths=None): | ||
| """Return a TrueType font of `size`, or PIL's built-in default when none is installed.""" | ||
| for path in (candidates() if paths is None else paths): | ||
| try: | ||
| return ImageFont.truetype(str(path), size) | ||
| except OSError: | ||
| continue | ||
| try: | ||
| return ImageFont.load_default(size) | ||
| except TypeError: # Pillow < 10.1 has no sized default | ||
| return ImageFont.load_default() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| """Crash-safe JSON writes: unique temp files, and the target is never missing.""" | ||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
| from spritemotion import jsonio | ||
|
|
||
|
|
||
| def test_write_leaves_no_temp_files_and_round_trips(tmp_path): | ||
| target = tmp_path / "data.json" | ||
| jsonio.write_json(target, {"a": 1}) | ||
| assert jsonio.read_json(target) == {"a": 1} | ||
| assert [p.name for p in tmp_path.iterdir()] == ["data.json"] | ||
|
|
||
|
|
||
| def test_a_stale_fixed_name_tmp_file_is_not_touched(tmp_path): | ||
| target = tmp_path / "data.json" | ||
| stale = tmp_path / "data.json.tmp" | ||
| stale.write_text("another writer", encoding="utf-8") | ||
| jsonio.write_json(target, {"a": 1}) | ||
| assert stale.read_text(encoding="utf-8") == "another writer" | ||
|
|
||
|
|
||
| def test_target_exists_at_every_replace_with_backup(tmp_path, monkeypatch): | ||
| target = tmp_path / "data.json" | ||
| jsonio.write_json(target, {"v": 1}) | ||
| seen = [] | ||
| real = os.replace | ||
|
|
||
| def spy(src, dst): | ||
| seen.append(target.exists()) | ||
| return real(src, dst) | ||
|
|
||
| monkeypatch.setattr(jsonio.os, "replace", spy) | ||
| jsonio.write_json(target, {"v": 2}, backup=True) | ||
| assert seen and all(seen) | ||
| assert jsonio.read_json(target) == {"v": 2} | ||
| assert jsonio.read_json(tmp_path / "data.json.bak") == {"v": 1} | ||
|
|
||
|
|
||
| def test_a_failed_write_keeps_the_old_file_and_cleans_up(tmp_path): | ||
| target = tmp_path / "data.json" | ||
| jsonio.write_json(target, {"v": 1}) | ||
| with pytest.raises(ValueError): | ||
| jsonio.write_json(target, {"v": float("nan")}, backup=True) | ||
| assert jsonio.read_json(target) == {"v": 1} | ||
| assert [p.name for p in tmp_path.iterdir()] == ["data.json"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import importlib.util | ||
| from pathlib import Path | ||
|
|
||
| ROOT = Path(__file__).resolve().parents[2] | ||
|
|
||
|
|
||
| def load(rel, name): | ||
| spec = importlib.util.spec_from_file_location(name, ROOT / rel) | ||
| mod = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(mod) | ||
| return mod | ||
|
|
||
|
|
||
| def test_load_font_falls_back_when_arial_missing(tmp_path): | ||
| fonts = load('games/ultima-online/region-masks/region_fonts.py', 'region_fonts') | ||
| font = fonts.load_font(14, paths=[tmp_path / 'missing.ttf']) | ||
| assert font is not None and hasattr(font, 'getmask') | ||
|
|
||
|
|
||
| def test_pose_editor_blender_env(monkeypatch, tmp_path): | ||
| server = load('games/ultima-online/region-masks/pose_editor_server.py', 'pose_editor_server_t') | ||
| exe = tmp_path / 'blender.exe' | ||
| monkeypatch.setenv('SPRITEMOTION_BLENDER', str(exe)) | ||
| assert server.find_blender() == str(exe) | ||
|
|
||
|
|
||
| def test_uo_content_blender_env(monkeypatch, tmp_path): | ||
| pipeline = load('tools/uo-content/pipeline.py', 'uo_pipeline_t') | ||
| monkeypatch.setenv('SPRITEMOTION_BLENDER', str(tmp_path / 'b.exe')) | ||
| assert pipeline.blender_path() == str(tmp_path / 'b.exe') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """Bad annotation and status files are reported, not silently dropped or fatal.""" | ||
| import logging | ||
|
|
||
| import pytest | ||
| from conftest import REPO, load_module | ||
|
|
||
|
|
||
| def test_corrupt_job_status_is_skipped_and_reported(tmp_path, monkeypatch): | ||
| monkeypatch.syspath_prepend(str(REPO / "tools" / "uo-content")) | ||
| studio = load_module(REPO / "tools" / "uo-content" / "studio.py", "uo_content_studio_test") | ||
| jobs = tmp_path / "jobs" | ||
| for name, text in (("aaaaaaaaaaaa", '{"state": "building"}'), ("bbbbbbbbbbbb", "{not json"), | ||
| ("cccccccccccc", '{"nostate": 1}'), ("dddddddddddd", '{"state": "done"}')): | ||
| (jobs / name).mkdir(parents=True) | ||
| (jobs / name / "status.json").write_text(text, encoding="utf-8") | ||
| skipped = studio.recover_interrupted_jobs(jobs) | ||
| assert sorted(f.parent.name for f, _ in skipped) == ["bbbbbbbbbbbb", "cccccccccccc"] | ||
| assert '"failed"' in (jobs / "aaaaaaaaaaaa" / "status.json").read_text(encoding="utf-8") | ||
| assert (jobs / "bbbbbbbbbbbb" / "status.json").read_text(encoding="utf-8") == "{not json" | ||
| assert '"done"' in (jobs / "dddddddddddd" / "status.json").read_text(encoding="utf-8") | ||
|
|
||
|
|
||
| def test_bad_annotations_log_a_warning_and_other_errors_propagate(monkeypatch, caplog): | ||
| pytest.importorskip("scipy") # silhouette-fit needs it; the CI image doesn't install it | ||
| run = load_module(REPO / "tools" / "silhouette-fit" / "run.py", "silhouette_fit_run_test") | ||
|
|
||
| def bad(*args, **kwargs): | ||
| raise KeyError("source_fingerprint") | ||
|
|
||
| monkeypatch.setattr(run, "select_targets", bad) | ||
| with caplog.at_level(logging.WARNING, logger="silhouette-fit"): | ||
| targets, selection = run.annotation_targets(object(), "walk", ["head"]) | ||
| assert targets == {} and selection["used"] == [] | ||
| assert "source_fingerprint" in caplog.text | ||
|
|
||
| def broken(*args, **kwargs): | ||
| raise RuntimeError("programming error") | ||
|
|
||
| monkeypatch.setattr(run, "select_targets", broken) | ||
| with pytest.raises(RuntimeError): | ||
| run.annotation_targets(object(), "walk", ["head"]) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On POSIX systems,
NamedTemporaryFilecreates the temporary file with mode0600, andos.replacetransfers that mode to the destination. Consequently, every call now changes an existing group/world-readable JSON file (typically0644under the prior implementation) to owner-only, which can prevent another account or service from reading shared manifests and annotations. Apply the existing file's mode, or a mode derived from the process umask, to the temporary file before replacing the destination.Useful? React with 👍 / 👎.