test(tools): create hard links with os.link for Python 3.9 #4545

Merged
thuanquang merged 1 commit from upstream-pr/4545 into main 2026-10-13 14:30:44 +00:00
thuanquang commented 2026-10-12 15:19:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-12T15:19:46Z.


What

import_audit and stubgen error on Python 3.9 before reaching their assertions:

AttributeError: 'PosixPath' object has no attribute 'hardlink_to'

Path.hardlink_to was added in Python 3.10. Python 3.9.6 is the python3 that the Xcode command-line tools install on macOS, which is the toolchain BUILD.md names for the relinker-only build there, and tools/progress.py targets Python 3.9+ (#11). The two tests now create the hard link with os.link(target, link), which does the same on every Python 3 version and on Windows. Only the two test files change.

pr_overlap_encoding also fails on Python 3.9 (subprocess._text_encoding). That is a different cause, and #4361 changes that file, so it is left out here.

Overlap: #4425 also adds import os at the same place in tools/tests/test_import_audit.py. As agreed on #4425, it goes first; I will then rebase this one, keeping a single import os.

Tested

macOS 27 (Apple Silicon), AppleClang 21, relinker-only build of main (d592d54e) with -DBUILD_TESTING=ON:

  • Python 3.9.6 (Xcode command-line tools), before: import_audit and stubgen fail with the error above; 121/124 pass.
  • Python 3.9.6, after: import_audit and stubgen pass; 123/124 pass, with pr_overlap_encoding the only failure.
  • Python 3.11.4: test_import_audit.py (37 tests) and test_stubgen.py (11 tests) pass.
  • python3 tools/check_conventions.py --base origin/main passes.

Not tested on Linux or Windows.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #4425
  • Unblocks: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4831438405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4545). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-12T15:19:46Z. --- ### What `import_audit` and `stubgen` error on Python 3.9 before reaching their assertions: ``` AttributeError: 'PosixPath' object has no attribute 'hardlink_to' ``` `Path.hardlink_to` was added in Python 3.10. Python 3.9.6 is the `python3` that the Xcode command-line tools install on macOS, which is the toolchain [BUILD.md](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/BUILD.md#relinker-only) names for the relinker-only build there, and `tools/progress.py` targets Python 3.9+ (#11). The two tests now create the hard link with `os.link(target, link)`, which does the same on every Python 3 version and on Windows. Only the two test files change. `pr_overlap_encoding` also fails on Python 3.9 (`subprocess._text_encoding`). That is a different cause, and #4361 changes that file, so it is left out here. Overlap: #4425 also adds `import os` at the same place in `tools/tests/test_import_audit.py`. As agreed on #4425, it goes first; I will then rebase this one, keeping a single `import os`. ### Tested macOS 27 (Apple Silicon), AppleClang 21, relinker-only build of `main` (d592d54e) with `-DBUILD_TESTING=ON`: - Python 3.9.6 (Xcode command-line tools), before: `import_audit` and `stubgen` fail with the error above; 121/124 pass. - Python 3.9.6, after: `import_audit` and `stubgen` pass; 123/124 pass, with `pr_overlap_encoding` the only failure. - Python 3.11.4: `test_import_audit.py` (37 tests) and `test_stubgen.py` (11 tests) pass. - `python3 tools/check_conventions.py --base origin/main` passes. Not tested on Linux or Windows. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #4425 - [x] Unblocks: none - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
coltken95 commented 2026-10-13 12:05:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T12:05:05Z.


Tested with Python 3.9.25, with 4feeef698 applied onto main 5d50886ee:

  • On main: test_import_audit and test_stubgen error with
    AttributeError: 'PosixPath' object has no attribute 'hardlink_to'
  • With the PR: all 48 tests in those two files pass.

For reference, tools/tests as a whole (252 tests) still has one failure on 3.9 that this PR doesn't touch:
test_pr_overlap_encoding.EncodingTests.test_default_encoding_uses_simulated_cp1252.
It passes on 3.11 and 3.13.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6145135412 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4545#issuecomment-6145135412). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-13T12:05:05Z. --- Tested with Python 3.9.25, with 4feeef698 applied onto main 5d50886ee: - On main: `test_import_audit` and `test_stubgen` error with `AttributeError: 'PosixPath' object has no attribute 'hardlink_to'` - With the PR: all 48 tests in those two files pass. For reference, `tools/tests` as a whole (252 tests) still has one failure on 3.9 that this PR doesn't touch: `test_pr_overlap_encoding.EncodingTests.test_default_encoding_uses_simulated_cp1252`. It passes on 3.11 and 3.13.
xXPBSXx commented 2026-10-13 13:17:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T13:17:19Z.


Windows test: head 4feeef698 merged onto current main 0f2683cb7, together with 5 other open pull requests in one build (the merges were conflict-free); a failure would have been bisected per PR. Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest for the tests this change adds or touches: import_audit passed, stubgen passed; python tools/check_conventions.py --base upstream/main passed for the combined tree. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146434916 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4545#issuecomment-6146434916). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T13:17:19Z. --- Windows test: head `4feeef698` merged onto current `main` `0f2683cb7`, together with 5 other open pull requests in one build (the merges were conflict-free); a failure would have been bisected per PR. Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j2`: full build 0 errors; ctest for the tests this change adds or touches: import_audit passed, stubgen passed; `python tools/check_conventions.py --base upstream/main` passed for the combined tree. I did not run the new tests against `main` without the change. AI-assisted (Claude Code).
adriadam10 commented 2026-10-13 14:15:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:15:40Z.


Checked: os.link(target, link) is equivalent to hardlink_to on every Python 3 version; test_stubgen.py already imports os. Merged on current main, scoped build and ctest pass (29/29). Python 3.9 results confirmed by @coltken95 (Linux 3.9.25) and Windows by @xXPBSXx; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147588956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4545#issuecomment-6147588956). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:15:40Z. --- Checked: `os.link(target, link)` is equivalent to `hardlink_to` on every Python 3 version; `test_stubgen.py` already imports `os`. Merged on current main, scoped build and ctest pass (29/29). Python 3.9 results confirmed by @coltken95 (Linux 3.9.25) and Windows by @xXPBSXx; merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4545
No description provided.