kasparovabi opened a new pull request, #2053:
URL: https://github.com/apache/cloudberry/pull/2053

   ### What does this PR do?
   
   Eleven modules under `gpMgmt/bin/gppylib/test/unit/` do `import imp` so they 
can call `imp.load_source()` on utilities that have no `.py` extension 
(`gpstop`, `gpstart`, `gpconfig`, `gpcheckcat` and so on). Python 3.12 removed 
`imp` ([What's New in 3.12](https://docs.python.org/3/whatsnew/3.12.html#imp)), 
and that is the Python on Rocky Linux 10 and Ubuntu 24.04, both of which the 
workflows build for. On those systems every one of these modules fails at 
import with `ModuleNotFoundError: No module named 'imp'` before a single test 
runs.
   
   This adds a small `load_source(name, path)` to `gp_unittest.py` built on 
`importlib.machinery.SourceFileLoader`, and the eleven modules call it instead. 
The helper keeps the one `imp.load_source()` behaviour the tests could notice: 
if a module with that name is already in `sys.modules`, it runs the code again 
in that same module object. `test_unit_foreign_key_check.py` imported `imp` 
without using it, so that line just goes.
   
   ### Type of Change
   - [x] Bug fix (non-breaking change)
   - [ ] New feature (non-breaking change)
   - [ ] Breaking change (fix or feature with breaking changes)
   - [ ] Documentation update
   
   ### Test Plan
   - [ ] Unit tests added/updated
   - [ ] Integration tests added/updated
   - [ ] Passed `make installcheck`
   - [ ] Passed `make -C src/test installcheck-cbdb-parallel`
   
   I did not build Cloudberry, so none of the boxes above are ticked. Here is 
what I did run. I took the `gpMgmt` tree and ran each of the eleven modules 
with `python -m unittest gppylib.test.unit.<module>`, in Docker with no 
network, with `mock`, `psutil`, `pyyaml` and `pygresql` installed. I ran the 
unpatched tree on Python 3.11 and 3.12 and the patched tree on 3.11 and 3.12.
   
   | module | 3.11 before | 3.11 after | 3.12 before | 3.12 after |
   |---|---|---|---|---|
   | test_unit_gpstop | 34 run, OK | 34 run, OK | import error (`imp`) | 34 
run, 1 error (see below) |
   | test_unit_gpconfig | 46 run, OK | 46 run, OK | import error (`imp`) | 46 
run, OK |
   | test_unit_gpdeletesystem | 6 run, OK | 6 run, OK | import error (`imp`) | 
6 run, OK |
   | test_unit_gpssh | 2 run, OK | 2 run, OK | import error (`imp`) | 2 run, OK 
|
   | test_unit_foreign_key_check | 4 run, OK | 4 run, OK | import error (`imp`) 
| 4 run, OK |
   | the other six | environment errors | same errors | import error (`imp`) | 
same errors as 3.11 |
   
   The "other six" (`gpexpand`, `gpcheckcat`, `test_cluster_gpcheckcat`, 
`gpcheckperf`, `gpstart`, `gpcheckresgroupimpl`) fail in my container for 
reasons that have nothing to do with this change: no built `gparray` on the 
path, no `$USER`, no `postgres` binary under `$GPHOME`. They fail the same way 
before and after on 3.11, and after the patch on 3.12 they reach that same 
point instead of stopping at the import.
   
   The one new error on 3.12 in `test_unit_gpstop` is `assertNotRegexpMatches`, 
a `unittest` alias that 3.12 also removed. It is a separate problem and I left 
it out to keep this PR to one change. I can send it separately if you want it.
   
   ### Impact
   **User-facing changes:** none, this only touches unit tests.
   
   **Dependencies:** none.
   
   ### Checklist
   - [ ] Followed [contribution 
guide](https://cloudberry.apache.org/contribute/code)
   - [ ] Added/updated documentation
   - [ ] Reviewed code for security implications
   - [x] This PR contains AI-assisted code generation
   - [ ] Requested review from [cloudberry 
committers](https://github.com/orgs/apache/teams/cloudberry-committers)
   
   ### Additional Context
   
   I read this diff line by line before opening it, and I am happy to adjust or 
drop any part of it. What brought me here was a checker I maintain that looks 
for imports of modules Python has removed, and I wrote the change with an AI 
assistant, so I have ticked that box. If you would rather not get this kind of 
contribution, tell me and I will not send another.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to