Fix module_exists on Python 3.12#179
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates destral.utils to be compatible with Python 3.12 by removing the hard dependency on the removed stdlib module imp, while keeping a Python 2.7 fallback, and adds regression tests around the updated behavior.
Changes:
- Update
module_exists()to useimportlib.util.find_spec()when available (and keep animp.find_module()fallback for Python 2.7). - Guard
netsvc.SERVICEScleanup so unit tests can run without a loaded ERP environment. - Add unit tests for
module_exists()and fix a Python 3.12SyntaxWarninginfind_files()’ regex literal.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
destral/utils.py |
Switch module_exists() to importlib.util.find_spec(), add guarded netsvc cleanup, and adjust find_files() regex literal. |
tests/test_utils.py |
Add unit tests covering module_exists() for existing modules/submodules and missing modules. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use importlib.util.find_spec on Python 3 to avoid the removed imp module, keeping the imp fallback for Python 2.7. Add regression coverage for existing and missing modules. Co-authored-by: Eduard Carreras <ecarreras@gisce.net>
f03d109 to
ac7eb34
Compare
|
He aplicat els dos comentaris de Copilot i he fet force-push del commit actualitzat
Validació local repetida:
CI GitHub del commit nou també OK: |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Objectiu
Corregir la compatibilitat amb Python 3.12, on el mòdul estàndard
impja no existeix.Refs #175
Canvis
module_exists()usaimportlib.util.find_spec()quan està disponible.imp.find_module()per Python 2.7.netsvc.SERVICESqueda protegida perquè els tests unitaris puguin executar-se sense entorn ERP carregat.SyntaxWarningde Python 3.12 en el patró regex defind_files().Validació
Executat correctament:
No he executat
mamba specperquèmambano està instal·lat en aquest entorn local.